diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-19 01:24:30 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-19 01:24:30 +0300 |
commit | e61d23b0305f5a878b07d5bc100af1ec2e4e98e7 (patch) | |
tree | c92e9976dc49c8546739b9ad620739be401f7bc6 | |
parent | a5e4614aed3dcd4c3adf74d25ff349b96d56a998 (diff) | |
download | luarocks-e61d23b0305f5a878b07d5bc100af1ec2e4e98e7.tar.gz luarocks-e61d23b0305f5a878b07d5bc100af1ec2e4e98e7.tar.bz2 luarocks-e61d23b0305f5a878b07d5bc100af1ec2e4e98e7.zip |
admin
-rw-r--r-- | src/luarocks/admin/cache-original.lua | 88 | ||||
-rw-r--r-- | src/luarocks/admin/cache.lua | 29 | ||||
-rw-r--r-- | src/luarocks/admin/cmd/make_manifest-original.lua | 50 | ||||
-rw-r--r-- | src/luarocks/admin/cmd/make_manifest.lua | 31 |
4 files changed, 172 insertions, 26 deletions
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 @@ | |||
1 | |||
2 | --- Module handling the LuaRocks local cache. | ||
3 | -- Adds a rock or rockspec to a rocks server. | ||
4 | local cache = {} | ||
5 | |||
6 | local fs = require("luarocks.fs") | ||
7 | local cfg = require("luarocks.core.cfg") | ||
8 | local dir = require("luarocks.dir") | ||
9 | local util = require("luarocks.util") | ||
10 | |||
11 | function cache.get_upload_server(server) | ||
12 | if not server then server = cfg.upload_server end | ||
13 | if not server then | ||
14 | return nil, "No server specified and no default configured with upload_server." | ||
15 | end | ||
16 | return server, cfg.upload_servers and cfg.upload_servers[server] | ||
17 | end | ||
18 | |||
19 | function cache.get_server_urls(server, upload_server) | ||
20 | local download_url = server | ||
21 | local login_url = nil | ||
22 | if upload_server then | ||
23 | if upload_server.rsync then download_url = "rsync://"..upload_server.rsync | ||
24 | elseif upload_server.http then download_url = "http://"..upload_server.http | ||
25 | elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp | ||
26 | end | ||
27 | |||
28 | if upload_server.ftp then login_url = "ftp://"..upload_server.ftp | ||
29 | elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp | ||
30 | end | ||
31 | end | ||
32 | return download_url, login_url | ||
33 | end | ||
34 | |||
35 | function cache.split_server_url(url, user, password) | ||
36 | local protocol, server_path = dir.split_url(url) | ||
37 | if protocol == "file" then | ||
38 | server_path = fs.absolute_name(server_path) | ||
39 | elseif server_path:match("@") then | ||
40 | local credentials | ||
41 | credentials, server_path = server_path:match("([^@]*)@(.*)") | ||
42 | if credentials:match(":") then | ||
43 | user, password = credentials:match("([^:]*):(.*)") | ||
44 | else | ||
45 | user = credentials | ||
46 | end | ||
47 | end | ||
48 | local local_cache = dir.path(cfg.local_cache, (server_path:gsub("[\\/]", "_"))) | ||
49 | return local_cache, protocol, server_path, user, password | ||
50 | end | ||
51 | |||
52 | local function download_cache(protocol, server_path, user, password) | ||
53 | os.remove("index.html") | ||
54 | -- TODO abstract away explicit 'wget' call | ||
55 | if protocol == "rsync" then | ||
56 | local srv, path = server_path:match("([^/]+)(/.+)") | ||
57 | return fs.execute(cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..user.."@"..srv..":"..path.."/ ./") | ||
58 | elseif protocol == "file" then | ||
59 | return fs.copy_contents(server_path, ".") | ||
60 | else | ||
61 | local login_info = "" | ||
62 | if user then login_info = " --user="..user end | ||
63 | if password then login_info = login_info .. " --password="..password end | ||
64 | return fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) | ||
65 | end | ||
66 | end | ||
67 | |||
68 | function cache.refresh_local_cache(url, given_user, given_password) | ||
69 | local local_cache, protocol, server_path, user, password = cache.split_server_url(url, given_user, given_password) | ||
70 | |||
71 | local ok, err = fs.make_dir(local_cache) | ||
72 | if not ok then | ||
73 | return nil, "Failed creating local cache dir: "..err | ||
74 | end | ||
75 | |||
76 | fs.change_dir(local_cache) | ||
77 | |||
78 | util.printout("Refreshing cache "..local_cache.."...") | ||
79 | |||
80 | ok = download_cache(protocol, server_path, user, password) | ||
81 | if not ok then | ||
82 | return nil, "Failed downloading cache." | ||
83 | end | ||
84 | |||
85 | return local_cache, protocol, server_path, user, password | ||
86 | end | ||
87 | |||
88 | 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 @@ | |||
1 | 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 | ||
2 | |||
1 | 3 | ||
2 | --- Module handling the LuaRocks local cache. | ||
3 | -- Adds a rock or rockspec to a rocks server. | ||
4 | local cache = {} | 4 | local cache = {} |
5 | 5 | ||
6 | |||
6 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
7 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
8 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
@@ -20,13 +21,13 @@ function cache.get_server_urls(server, upload_server) | |||
20 | local download_url = server | 21 | local download_url = server |
21 | local login_url = nil | 22 | local login_url = nil |
22 | if upload_server then | 23 | if upload_server then |
23 | if upload_server.rsync then download_url = "rsync://"..upload_server.rsync | 24 | if upload_server.rsync then download_url = "rsync://" .. upload_server.rsync |
24 | elseif upload_server.http then download_url = "http://"..upload_server.http | 25 | elseif upload_server.http then download_url = "http://" .. upload_server.http |
25 | elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp | 26 | elseif upload_server.ftp then download_url = "ftp://" .. upload_server.ftp |
26 | end | 27 | end |
27 | 28 | ||
28 | if upload_server.ftp then login_url = "ftp://"..upload_server.ftp | 29 | if upload_server.ftp then login_url = "ftp://" .. upload_server.ftp |
29 | elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp | 30 | elseif upload_server.sftp then login_url = "sftp://" .. upload_server.sftp |
30 | end | 31 | end |
31 | end | 32 | end |
32 | return download_url, login_url | 33 | return download_url, login_url |
@@ -51,17 +52,17 @@ end | |||
51 | 52 | ||
52 | local function download_cache(protocol, server_path, user, password) | 53 | local function download_cache(protocol, server_path, user, password) |
53 | os.remove("index.html") | 54 | os.remove("index.html") |
54 | -- TODO abstract away explicit 'wget' call | 55 | |
55 | if protocol == "rsync" then | 56 | if protocol == "rsync" then |
56 | local srv, path = server_path:match("([^/]+)(/.+)") | 57 | local srv, path = server_path:match("([^/]+)(/.+)") |
57 | return fs.execute(cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..user.."@"..srv..":"..path.."/ ./") | 58 | return fs.execute(cfg.variables.RSYNC .. " " .. cfg.variables.RSYNCFLAGS .. " -e ssh " .. user .. "@" .. srv .. ":" .. path .. "/ ./") |
58 | elseif protocol == "file" then | 59 | elseif protocol == "file" then |
59 | return fs.copy_contents(server_path, ".") | 60 | return fs.copy_contents(server_path, ".") |
60 | else | 61 | else |
61 | local login_info = "" | 62 | local login_info = "" |
62 | if user then login_info = " --user="..user end | 63 | if user then login_info = " --user=" .. user end |
63 | if password then login_info = login_info .. " --password="..password end | 64 | if password then login_info = login_info .. " --password=" .. password end |
64 | return fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) | 65 | return fs.execute(cfg.variables.WGET .. " --no-cache -q -m -np -nd " .. protocol .. "://" .. server_path .. login_info) |
65 | end | 66 | end |
66 | end | 67 | end |
67 | 68 | ||
@@ -70,12 +71,12 @@ function cache.refresh_local_cache(url, given_user, given_password) | |||
70 | 71 | ||
71 | local ok, err = fs.make_dir(local_cache) | 72 | local ok, err = fs.make_dir(local_cache) |
72 | if not ok then | 73 | if not ok then |
73 | return nil, "Failed creating local cache dir: "..err | 74 | return nil, "Failed creating local cache dir: " .. err |
74 | end | 75 | end |
75 | 76 | ||
76 | fs.change_dir(local_cache) | 77 | fs.change_dir(local_cache) |
77 | 78 | ||
78 | util.printout("Refreshing cache "..local_cache.."...") | 79 | util.printout("Refreshing cache " .. local_cache .. "...") |
79 | 80 | ||
80 | ok = download_cache(protocol, server_path, user, password) | 81 | ok = download_cache(protocol, server_path, user, password) |
81 | if not ok then | 82 | 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 @@ | |||
1 | |||
2 | --- Module implementing the luarocks-admin "make_manifest" command. | ||
3 | -- Compile a manifest file for a repository. | ||
4 | local make_manifest = {} | ||
5 | |||
6 | local writer = require("luarocks.manif.writer") | ||
7 | local index = require("luarocks.admin.index") | ||
8 | local cfg = require("luarocks.core.cfg") | ||
9 | local util = require("luarocks.util") | ||
10 | local deps = require("luarocks.deps") | ||
11 | local fs = require("luarocks.fs") | ||
12 | local dir = require("luarocks.dir") | ||
13 | |||
14 | function make_manifest.add_to_parser(parser) | ||
15 | local cmd = parser:command("make_manifest", "Compile a manifest file for a repository.", util.see_also()) | ||
16 | |||
17 | cmd:argument("repository", "Local repository pathname.") | ||
18 | :args("?") | ||
19 | |||
20 | cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n".. | ||
21 | "Use this when rebuilding the manifest of a local rocks tree.") | ||
22 | util.deps_mode_option(cmd) | ||
23 | end | ||
24 | |||
25 | --- Driver function for "make_manifest" command. | ||
26 | -- @return boolean or (nil, string): True if manifest was generated, | ||
27 | -- or nil and an error message. | ||
28 | function make_manifest.command(args) | ||
29 | local repo = args.repository or cfg.rocks_dir | ||
30 | |||
31 | util.printout("Making manifest for "..repo) | ||
32 | |||
33 | if repo:match("/lib/luarocks") and not args.local_tree then | ||
34 | util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") | ||
35 | end | ||
36 | |||
37 | local ok, err = writer.make_manifest(repo, deps.get_deps_mode(args), not args.local_tree) | ||
38 | if ok and not args.local_tree then | ||
39 | util.printout("Generating index.html for "..repo) | ||
40 | index.make_index(repo) | ||
41 | end | ||
42 | if args.local_tree then | ||
43 | for luaver in util.lua_versions() do | ||
44 | fs.delete(dir.path(repo, "manifest-"..luaver)) | ||
45 | end | ||
46 | end | ||
47 | return ok, err | ||
48 | end | ||
49 | |||
50 | 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 @@ | |||
1 | 1 | ||
2 | --- Module implementing the luarocks-admin "make_manifest" command. | 2 | |
3 | -- Compile a manifest file for a repository. | 3 | |
4 | local make_manifest = {} | 4 | local make_manifest = {} |
5 | 5 | ||
6 | |||
6 | local writer = require("luarocks.manif.writer") | 7 | local writer = require("luarocks.manif.writer") |
7 | local index = require("luarocks.admin.index") | 8 | local index = require("luarocks.admin.index") |
8 | local cfg = require("luarocks.core.cfg") | 9 | local cfg = require("luarocks.core.cfg") |
@@ -11,24 +12,30 @@ local deps = require("luarocks.deps") | |||
11 | local fs = require("luarocks.fs") | 12 | local fs = require("luarocks.fs") |
12 | local dir = require("luarocks.dir") | 13 | local dir = require("luarocks.dir") |
13 | 14 | ||
15 | local argparse = require("luarocks.vendor.argparse") | ||
16 | |||
17 | |||
18 | |||
19 | |||
20 | |||
14 | function make_manifest.add_to_parser(parser) | 21 | function make_manifest.add_to_parser(parser) |
15 | local cmd = parser:command("make_manifest", "Compile a manifest file for a repository.", util.see_also()) | 22 | local cmd = parser:command("make_manifest", "Compile a manifest file for a repository.", util.see_also()) |
16 | 23 | ||
17 | cmd:argument("repository", "Local repository pathname.") | 24 | cmd:argument("repository", "Local repository pathname."): |
18 | :args("?") | 25 | args("?") |
19 | 26 | ||
20 | cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n".. | 27 | cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n" .. |
21 | "Use this when rebuilding the manifest of a local rocks tree.") | 28 | "Use this when rebuilding the manifest of a local rocks tree.") |
22 | util.deps_mode_option(cmd) | 29 | util.deps_mode_option(cmd) |
23 | end | 30 | end |
24 | 31 | ||
25 | --- Driver function for "make_manifest" command. | 32 | |
26 | -- @return boolean or (nil, string): True if manifest was generated, | 33 | |
27 | -- or nil and an error message. | 34 | |
28 | function make_manifest.command(args) | 35 | function make_manifest.command(args) |
29 | local repo = args.repository or cfg.rocks_dir | 36 | local repo = args.repository or cfg.rocks_dir |
30 | 37 | ||
31 | util.printout("Making manifest for "..repo) | 38 | util.printout("Making manifest for " .. repo) |
32 | 39 | ||
33 | if repo:match("/lib/luarocks") and not args.local_tree then | 40 | if repo:match("/lib/luarocks") and not args.local_tree then |
34 | util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") | 41 | 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) | |||
36 | 43 | ||
37 | local ok, err = writer.make_manifest(repo, deps.get_deps_mode(args), not args.local_tree) | 44 | local ok, err = writer.make_manifest(repo, deps.get_deps_mode(args), not args.local_tree) |
38 | if ok and not args.local_tree then | 45 | if ok and not args.local_tree then |
39 | util.printout("Generating index.html for "..repo) | 46 | util.printout("Generating index.html for " .. repo) |
40 | index.make_index(repo) | 47 | index.make_index(repo) |
41 | end | 48 | end |
42 | if args.local_tree then | 49 | if args.local_tree then |
43 | for luaver in util.lua_versions() do | 50 | for luaver in util.lua_versions() do |
44 | fs.delete(dir.path(repo, "manifest-"..luaver)) | 51 | fs.delete(dir.path(repo, "manifest-" .. luaver)) |
45 | end | 52 | end |
46 | end | 53 | end |
47 | return ok, err | 54 | return ok, err |