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