Browse Source

Formatting changes and cleanup

environments/development/deployments/40
Drew Short 7 years ago
parent
commit
3ab98df845
  1. 21
      src/spm/spm.moon

21
src/spm/spm.moon

@ -17,7 +17,8 @@ if not component.isAvailable("internet")
internet = require("internet") internet = require("internet")
githubContentRoot = "https://raw.githubusercontent.com/" githubContentRoot = "https://raw.githubusercontent.com/"
repoLocationConfig = "{URL_BASE}/repos.cfg"
defaultRepoLocationConfig = "{URL_BASE}/repos.cfg"
localInstalledPackagesFile = "/etc/spdata.svd" localInstalledPackagesFile = "/etc/spdata.svd"
localConfigFile = "/etc/spm.cfg" localConfigFile = "/etc/spm.cfg"
@ -52,7 +53,7 @@ getContent = (url) ->
-- Request repository information -- Request repository information
getRepositories = -> getRepositories = ->
success, raw_repositories = pcall(getContent, repoLocationConfig)
success, raw_repositories = pcall(getContent, defaultRepoLocationConfig)
if not success if not success
io.stderr\write("Could not connect to the Internet. Please ensure you have an Internet connection.") io.stderr\write("Could not connect to the Internet. Please ensure you have an Internet connection.")
@ -62,12 +63,12 @@ getRepositories = ->
-- Get Packages for src -- Get Packages for src
getPackages = (src) -> getPackages = (src) ->
success, sPackages = pcall(getContent, src .. "/programs.cfg")
success, packages = pcall(getContent, src .. "/programs.cfg")
if not success or not sPackages
if not success or not packages
return -1 return -1
return serial.unserialize(sPackages)
return serial.unserialize(packages)
getGithubPackages = (repo) -> getGithubPackages = (repo) ->
return getPackages(githubContentRoot .. repo .. "/master") return getPackages(githubContentRoot .. repo .. "/master")
@ -80,6 +81,7 @@ compare = (a, b) ->
return #a < #b return #a < #b
-- Download a file from a remote location
downloadFile = (url, path, force) -> downloadFile = (url, path, force) ->
if options.f or force if options.f or force
wget("-fq", url, path) wget("-fq", url, path)
@ -89,6 +91,7 @@ downloadFile = (url, path, force) ->
return true return true
return false return false
-- Read serialized table data from a file
readFromFile = (path) -> readFromFile = (path) ->
if not fs.exists(fs.path(path)) if not fs.exists(fs.path(path))
fs.makeDirectory(fs.path(path)) fs.makeDirectory(fs.path(path))
@ -105,9 +108,11 @@ readFromFile = (path) ->
file\close() file\close()
return serial.unserialize(serializedTableData) or { -1 } return serial.unserialize(serializedTableData) or { -1 }
-- Read the locally installed package list
readFromLocalInstallFile = -> readFromLocalInstallFile = ->
return readFromFile(localInstalledPackagesFile) return readFromFile(localInstalledPackagesFile)
-- Read the local configuration file
readLocalConfigFile = -> readLocalConfigFile = ->
path = localConfigFile path = localConfigFile
if not fs.exists(path) if not fs.exists(path)
@ -115,6 +120,7 @@ readLocalConfigFile = ->
else else
return readFromFile(path) return readFromFile(path)
-- Save the installed packages table to a local file
saveToInstalledPackagesFile = (installedPackages) -> saveToInstalledPackagesFile = (installedPackages) ->
file, msg = io.open(localInstalledPackagesFile, "wb") file, msg = io.open(localInstalledPackagesFile, "wb")
@ -127,6 +133,7 @@ saveToInstalledPackagesFile = (installedPackages) ->
file\write(sPacks) file\write(sPacks)
file\close() file\close()
-- List all packages
listPackages = (filter) -> listPackages = (filter) ->
filter = filter or false filter = filter or false
@ -183,8 +190,8 @@ listPackages = (filter) ->
table.sort(packageTable, compare) table.sort(packageTable, compare)
return packageTable return packageTable
-- Pretty print a package table
printPackages = (packages) -> printPackages = (packages) ->
if packages == nil or not packages[1] if packages == nil or not packages[1]
print("No package matching specified filter found.") print("No package matching specified filter found.")
return return
@ -204,6 +211,7 @@ printPackages = (packages) ->
print("--SPM {ENV} Package list--") print("--SPM {ENV} Package list--")
xCur, yCur = term.getCursor() xCur, yCur = term.getCursor()
-- Retrieve package information
getInformation = (requestedPackage) -> getInformation = (requestedPackage) ->
success, repositories = pcall(getRepositories) success, repositories = pcall(getRepositories)
@ -231,6 +239,7 @@ getInformation = (requestedPackage) ->
return nil return nil
-- uhhhhhh
provideInfo = (pack) -> provideInfo = (pack) ->
if not pack if not pack
printUsage() printUsage()

Loading…
Cancel
Save