From b7176e55adf369f62b02e73e303b53e401399eca Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sat, 20 Oct 2018 20:35:48 -0400 Subject: [PATCH] package manager wip --- sys/apis/packages.lua | 32 +++++++++++++++++++++++++++++ sys/apps/Packages.lua | 13 ++++++++++++ sys/extensions/6.packages.lua | 38 +++++++++++++++++++++++++++++++++++ sys/packageList.lua | 4 ++++ 4 files changed, 87 insertions(+) create mode 100644 sys/apis/packages.lua create mode 100644 sys/apps/Packages.lua create mode 100644 sys/extensions/6.packages.lua create mode 100644 sys/packageList.lua diff --git a/sys/apis/packages.lua b/sys/apis/packages.lua new file mode 100644 index 0000000..c3b4473 --- /dev/null +++ b/sys/apis/packages.lua @@ -0,0 +1,32 @@ +_G.requireInjector(_ENV) + +local Util = require('util') + +local fs = _G.fs + +local PACKAGE_DIR = 'packages' + +local Packages = { } + +function Packages:installed() + self.cache = { } + + if fs.exists(PACKAGE_DIR) then + for _, dir in pairs(fs.list(PACKAGE_DIR)) do + local path = fs.combine(fs.combine(PACKAGE_DIR, dir), '.package') + self.cache[dir] = Util.readTable(path) + end + end + + return self.cache +end + +function Packages:list() + return Util.readTable('sys/packageList.lua') or { } +end + +function Packages:isInstalled(package) + return self:installed()[package] +end + +return Packages diff --git a/sys/apps/Packages.lua b/sys/apps/Packages.lua new file mode 100644 index 0000000..14e5c5b --- /dev/null +++ b/sys/apps/Packages.lua @@ -0,0 +1,13 @@ +_G.requireInjector(_ENV) + +local Packages = require('packages') +local Util = require('util') + +local args = { ... } + +if args[1] == 'list' then + for k,v in pairs(Packages:list()) do + Util.print('[%s] %s', Packages:isInstalled(k) and 'x' or ' ', k) + end +end + diff --git a/sys/extensions/6.packages.lua b/sys/extensions/6.packages.lua new file mode 100644 index 0000000..09fcaff --- /dev/null +++ b/sys/extensions/6.packages.lua @@ -0,0 +1,38 @@ +_G.requireInjector(_ENV) + +local Packages = require('packages') +local Util = require('util') + +local shell = _ENV.shell +local fs = _G.fs + +local appPaths = Util.split(shell.path(), '(.-):') +local luaPaths = Util.split(_G.LUA_PATH, '(.-):') + +local function addPath(t, e) + local function hasEntry() + for _,v in ipairs(t) do + if v == e then + return true + end + end + end + if not hasEntry() then + table.insert(t, 1, e) + end +end + +-- dependency graph +-- https://github.com/mpeterv/depgraph/blob/master/src/depgraph/init.lua + +for name, package in pairs(Packages:installed()) do + if package.mount then + fs.mount(table.unpack(Util.matches(package.mount))) + end + + addPath(appPaths, fs.combine(fs.combine('packages', name), 'apps')) + addPath(luaPaths, fs.combine(fs.combine('packages', name), 'apis')) +end + +shell.setPath(table.concat(appPaths, ':')) +_G.LUA_PATH = table.concat(luaPaths, ':') diff --git a/sys/packageList.lua b/sys/packageList.lua new file mode 100644 index 0000000..622f2c1 --- /dev/null +++ b/sys/packageList.lua @@ -0,0 +1,4 @@ +{ + [ 'opus-neural' ] = 'file://packages/opus-neural/.package', + [ 'opus-miners' ] = 'file://packages/opus-miners/.package', +} \ No newline at end of file