From e61d23b0305f5a878b07d5bc100af1ec2e4e98e7 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Mon, 19 Aug 2024 01:24:30 +0300 Subject: admin --- src/luarocks/admin/cache-original.lua | 88 +++++++++++++++++++++++ src/luarocks/admin/cache.lua | 29 ++++---- src/luarocks/admin/cmd/make_manifest-original.lua | 50 +++++++++++++ src/luarocks/admin/cmd/make_manifest.lua | 31 ++++---- 4 files changed, 172 insertions(+), 26 deletions(-) create mode 100644 src/luarocks/admin/cache-original.lua create mode 100644 src/luarocks/admin/cmd/make_manifest-original.lua (limited to 'src') diff --git a/src/luarocks/admin/cache-original.lua b/src/luarocks/admin/cache-original.lua new file mode 100644 index 00000000..7a4e4af8 --- /dev/null +++ b/src/luarocks/admin/cache-original.lua @@ -0,0 +1,88 @@ + +--- Module handling the LuaRocks local cache. +-- Adds a rock or rockspec to a rocks server. +local cache = {} + +local fs = require("luarocks.fs") +local cfg = require("luarocks.core.cfg") +local dir = require("luarocks.dir") +local util = require("luarocks.util") + +function cache.get_upload_server(server) + if not server then server = cfg.upload_server end + if not server then + return nil, "No server specified and no default configured with upload_server." + end + return server, cfg.upload_servers and cfg.upload_servers[server] +end + +function cache.get_server_urls(server, upload_server) + local download_url = server + local login_url = nil + if upload_server then + if upload_server.rsync then download_url = "rsync://"..upload_server.rsync + elseif upload_server.http then download_url = "http://"..upload_server.http + elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp + end + + if upload_server.ftp then login_url = "ftp://"..upload_server.ftp + elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp + end + end + return download_url, login_url +end + +function cache.split_server_url(url, user, password) + local protocol, server_path = dir.split_url(url) + if protocol == "file" then + server_path = fs.absolute_name(server_path) + elseif server_path:match("@") then + local credentials + credentials, server_path = server_path:match("([^@]*)@(.*)") + if credentials:match(":") then + user, password = credentials:match("([^:]*):(.*)") + else + user = credentials + end + end + local local_cache = dir.path(cfg.local_cache, (server_path:gsub("[\\/]", "_"))) + return local_cache, protocol, server_path, user, password +end + +local function download_cache(protocol, server_path, user, password) + os.remove("index.html") + -- TODO abstract away explicit 'wget' call + if protocol == "rsync" then + local srv, path = server_path:match("([^/]+)(/.+)") + return fs.execute(cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..user.."@"..srv..":"..path.."/ ./") + elseif protocol == "file" then + return fs.copy_contents(server_path, ".") + else + local login_info = "" + if user then login_info = " --user="..user end + if password then login_info = login_info .. " --password="..password end + return fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) + end +end + +function cache.refresh_local_cache(url, given_user, given_password) + local local_cache, protocol, server_path, user, password = cache.split_server_url(url, given_user, given_password) + + local ok, err = fs.make_dir(local_cache) + if not ok then + return nil, "Failed creating local cache dir: "..err + end + + fs.change_dir(local_cache) + + util.printout("Refreshing cache "..local_cache.."...") + + ok = download_cache(protocol, server_path, user, password) + if not ok then + return nil, "Failed downloading cache." + end + + return local_cache, protocol, server_path, user, password +end + +return cache diff --git a/src/luarocks/admin/cache.lua b/src/luarocks/admin/cache.lua index 7a4e4af8..48551f7a 100644 --- a/src/luarocks/admin/cache.lua +++ b/src/luarocks/admin/cache.lua @@ -1,8 +1,9 @@ +local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local os = _tl_compat and _tl_compat.os or os; local string = _tl_compat and _tl_compat.string or string + ---- Module handling the LuaRocks local cache. --- Adds a rock or rockspec to a rocks server. local cache = {} + local fs = require("luarocks.fs") local cfg = require("luarocks.core.cfg") local dir = require("luarocks.dir") @@ -20,13 +21,13 @@ function cache.get_server_urls(server, upload_server) local download_url = server local login_url = nil if upload_server then - if upload_server.rsync then download_url = "rsync://"..upload_server.rsync - elseif upload_server.http then download_url = "http://"..upload_server.http - elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp + if upload_server.rsync then download_url = "rsync://" .. upload_server.rsync + elseif upload_server.http then download_url = "http://" .. upload_server.http + elseif upload_server.ftp then download_url = "ftp://" .. upload_server.ftp end - if upload_server.ftp then login_url = "ftp://"..upload_server.ftp - elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp + if upload_server.ftp then login_url = "ftp://" .. upload_server.ftp + elseif upload_server.sftp then login_url = "sftp://" .. upload_server.sftp end end return download_url, login_url @@ -51,17 +52,17 @@ end local function download_cache(protocol, server_path, user, password) os.remove("index.html") - -- TODO abstract away explicit 'wget' call + if protocol == "rsync" then local srv, path = server_path:match("([^/]+)(/.+)") - return fs.execute(cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..user.."@"..srv..":"..path.."/ ./") + return fs.execute(cfg.variables.RSYNC .. " " .. cfg.variables.RSYNCFLAGS .. " -e ssh " .. user .. "@" .. srv .. ":" .. path .. "/ ./") elseif protocol == "file" then return fs.copy_contents(server_path, ".") else local login_info = "" - if user then login_info = " --user="..user end - if password then login_info = login_info .. " --password="..password end - return fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) + if user then login_info = " --user=" .. user end + if password then login_info = login_info .. " --password=" .. password end + return fs.execute(cfg.variables.WGET .. " --no-cache -q -m -np -nd " .. protocol .. "://" .. server_path .. login_info) end end @@ -70,12 +71,12 @@ function cache.refresh_local_cache(url, given_user, given_password) local ok, err = fs.make_dir(local_cache) if not ok then - return nil, "Failed creating local cache dir: "..err + return nil, "Failed creating local cache dir: " .. err end fs.change_dir(local_cache) - util.printout("Refreshing cache "..local_cache.."...") + util.printout("Refreshing cache " .. local_cache .. "...") ok = download_cache(protocol, server_path, user, password) if not ok then diff --git a/src/luarocks/admin/cmd/make_manifest-original.lua b/src/luarocks/admin/cmd/make_manifest-original.lua new file mode 100644 index 00000000..18f74b5d --- /dev/null +++ b/src/luarocks/admin/cmd/make_manifest-original.lua @@ -0,0 +1,50 @@ + +--- Module implementing the luarocks-admin "make_manifest" command. +-- Compile a manifest file for a repository. +local make_manifest = {} + +local writer = require("luarocks.manif.writer") +local index = require("luarocks.admin.index") +local cfg = require("luarocks.core.cfg") +local util = require("luarocks.util") +local deps = require("luarocks.deps") +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") + +function make_manifest.add_to_parser(parser) + local cmd = parser:command("make_manifest", "Compile a manifest file for a repository.", util.see_also()) + + cmd:argument("repository", "Local repository pathname.") + :args("?") + + cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n".. + "Use this when rebuilding the manifest of a local rocks tree.") + util.deps_mode_option(cmd) +end + +--- Driver function for "make_manifest" command. +-- @return boolean or (nil, string): True if manifest was generated, +-- or nil and an error message. +function make_manifest.command(args) + local repo = args.repository or cfg.rocks_dir + + util.printout("Making manifest for "..repo) + + if repo:match("/lib/luarocks") and not args.local_tree then + util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") + end + + local ok, err = writer.make_manifest(repo, deps.get_deps_mode(args), not args.local_tree) + if ok and not args.local_tree then + util.printout("Generating index.html for "..repo) + index.make_index(repo) + end + if args.local_tree then + for luaver in util.lua_versions() do + fs.delete(dir.path(repo, "manifest-"..luaver)) + end + end + return ok, err +end + +return make_manifest diff --git a/src/luarocks/admin/cmd/make_manifest.lua b/src/luarocks/admin/cmd/make_manifest.lua index 18f74b5d..d2be94bb 100644 --- a/src/luarocks/admin/cmd/make_manifest.lua +++ b/src/luarocks/admin/cmd/make_manifest.lua @@ -1,8 +1,9 @@ ---- Module implementing the luarocks-admin "make_manifest" command. --- Compile a manifest file for a repository. + + local make_manifest = {} + local writer = require("luarocks.manif.writer") local index = require("luarocks.admin.index") local cfg = require("luarocks.core.cfg") @@ -11,24 +12,30 @@ local deps = require("luarocks.deps") local fs = require("luarocks.fs") local dir = require("luarocks.dir") +local argparse = require("luarocks.vendor.argparse") + + + + + function make_manifest.add_to_parser(parser) local cmd = parser:command("make_manifest", "Compile a manifest file for a repository.", util.see_also()) - cmd:argument("repository", "Local repository pathname.") - :args("?") + cmd:argument("repository", "Local repository pathname."): + args("?") - cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n".. - "Use this when rebuilding the manifest of a local rocks tree.") + cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n" .. + "Use this when rebuilding the manifest of a local rocks tree.") util.deps_mode_option(cmd) end ---- Driver function for "make_manifest" command. --- @return boolean or (nil, string): True if manifest was generated, --- or nil and an error message. + + + function make_manifest.command(args) local repo = args.repository or cfg.rocks_dir - util.printout("Making manifest for "..repo) + util.printout("Making manifest for " .. repo) if repo:match("/lib/luarocks") and not args.local_tree then util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") @@ -36,12 +43,12 @@ function make_manifest.command(args) local ok, err = writer.make_manifest(repo, deps.get_deps_mode(args), not args.local_tree) if ok and not args.local_tree then - util.printout("Generating index.html for "..repo) + util.printout("Generating index.html for " .. repo) index.make_index(repo) end if args.local_tree then for luaver in util.lua_versions() do - fs.delete(dir.path(repo, "manifest-"..luaver)) + fs.delete(dir.path(repo, "manifest-" .. luaver)) end end return ok, err -- cgit v1.2.3-55-g6feb