diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-19 01:23:16 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-19 01:23:16 +0300 |
commit | a5e4614aed3dcd4c3adf74d25ff349b96d56a998 (patch) | |
tree | 14603190cea6e5c618c953deea4b08e6c4be9224 | |
parent | 8ce0f1ea847910518a46d24f771aab8814399009 (diff) | |
download | luarocks-a5e4614aed3dcd4c3adf74d25ff349b96d56a998.tar.gz luarocks-a5e4614aed3dcd4c3adf74d25ff349b96d56a998.tar.bz2 luarocks-a5e4614aed3dcd4c3adf74d25ff349b96d56a998.zip |
admin
-rw-r--r-- | src/luarocks/admin/cache.tl | 89 | ||||
-rw-r--r-- | src/luarocks/admin/cmd/add.tl | 137 | ||||
-rw-r--r-- | src/luarocks/admin/cmd/make_manifest.tl | 57 | ||||
-rw-r--r-- | src/luarocks/admin/cmd/refresh_cache.tl | 38 | ||||
-rw-r--r-- | src/luarocks/admin/cmd/remove.tl | 124 | ||||
-rw-r--r-- | src/luarocks/admin/index.tl | 192 | ||||
-rw-r--r-- | src/luarocks/core/cfg.d.tl | 6 | ||||
-rw-r--r-- | src/luarocks/core/types/args.d.tl | 203 |
8 files changed, 747 insertions, 99 deletions
diff --git a/src/luarocks/admin/cache.tl b/src/luarocks/admin/cache.tl new file mode 100644 index 00000000..85e3df36 --- /dev/null +++ b/src/luarocks/admin/cache.tl | |||
@@ -0,0 +1,89 @@ | |||
1 | |||
2 | --- Module handling the LuaRocks local cache. | ||
3 | -- Adds a rock or rockspec to a rocks server. | ||
4 | local record cache | ||
5 | end | ||
6 | |||
7 | local fs = require("luarocks.fs") | ||
8 | local cfg = require("luarocks.core.cfg") | ||
9 | local dir = require("luarocks.dir") | ||
10 | local util = require("luarocks.util") | ||
11 | |||
12 | function cache.get_upload_server(server: string): string, string | ||
13 | if not server then server = cfg.upload_server end | ||
14 | if not server then | ||
15 | return nil, "No server specified and no default configured with upload_server." | ||
16 | end | ||
17 | return server, cfg.upload_servers and cfg.upload_servers[server] | ||
18 | end | ||
19 | |||
20 | function cache.get_server_urls(server: string, upload_server: {string: string}): string, string | ||
21 | local download_url: string = server | ||
22 | local login_url: string = nil | ||
23 | if upload_server then | ||
24 | if upload_server.rsync then download_url = "rsync://"..upload_server.rsync | ||
25 | elseif upload_server.http then download_url = "http://"..upload_server.http | ||
26 | elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp | ||
27 | end | ||
28 | |||
29 | if upload_server.ftp then login_url = "ftp://"..upload_server.ftp | ||
30 | elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp | ||
31 | end | ||
32 | end | ||
33 | return download_url, login_url | ||
34 | end | ||
35 | |||
36 | function cache.split_server_url(url: string, user: string, password: string): string, string, string, string, string | ||
37 | local protocol, server_path = dir.split_url(url) | ||
38 | if protocol == "file" then | ||
39 | server_path = fs.absolute_name(server_path) | ||
40 | elseif server_path:match("@") then | ||
41 | local credentials: string | ||
42 | credentials, server_path = server_path:match("([^@]*)@(.*)") | ||
43 | if credentials:match(":") then | ||
44 | user, password = credentials:match("([^:]*):(.*)") | ||
45 | else | ||
46 | user = credentials | ||
47 | end | ||
48 | end | ||
49 | local local_cache = dir.path(cfg.local_cache, (server_path:gsub("[\\/]", "_"))) | ||
50 | return local_cache, protocol, server_path, user, password | ||
51 | end | ||
52 | |||
53 | local function download_cache(protocol: string, server_path: string, user: string, password: string): boolean, string, string | ||
54 | os.remove("index.html") | ||
55 | -- TODO abstract away explicit 'wget' call | ||
56 | if protocol == "rsync" then | ||
57 | local srv, path = server_path:match("([^/]+)(/.+)") | ||
58 | return fs.execute(cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..user.."@"..srv..":"..path.."/ ./") | ||
59 | elseif protocol == "file" then | ||
60 | return fs.copy_contents(server_path, ".") | ||
61 | else | ||
62 | local login_info = "" | ||
63 | if user then login_info = " --user="..user end | ||
64 | if password then login_info = login_info .. " --password="..password end | ||
65 | return fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) | ||
66 | end | ||
67 | end | ||
68 | |||
69 | function cache.refresh_local_cache(url: string, given_user: string, given_password: string): string, string, string, string, string | ||
70 | local local_cache, protocol, server_path, user, password = cache.split_server_url(url, given_user, given_password) | ||
71 | |||
72 | local ok, err = fs.make_dir(local_cache) | ||
73 | if not ok then | ||
74 | return nil, "Failed creating local cache dir: "..err | ||
75 | end | ||
76 | |||
77 | fs.change_dir(local_cache) | ||
78 | |||
79 | util.printout("Refreshing cache "..local_cache.."...") | ||
80 | |||
81 | ok = download_cache(protocol, server_path, user, password) | ||
82 | if not ok then | ||
83 | return nil, "Failed downloading cache." | ||
84 | end | ||
85 | |||
86 | return local_cache, protocol, server_path, user, password | ||
87 | end | ||
88 | |||
89 | return cache | ||
diff --git a/src/luarocks/admin/cmd/add.tl b/src/luarocks/admin/cmd/add.tl new file mode 100644 index 00000000..f90eabc0 --- /dev/null +++ b/src/luarocks/admin/cmd/add.tl | |||
@@ -0,0 +1,137 @@ | |||
1 | |||
2 | --- Module implementing the luarocks-admin "add" command. | ||
3 | -- Adds a rock or rockspec to a rocks server. | ||
4 | local record add | ||
5 | end | ||
6 | |||
7 | local cfg = require("luarocks.core.cfg") | ||
8 | local util = require("luarocks.util") | ||
9 | local dir = require("luarocks.dir") | ||
10 | local writer = require("luarocks.manif.writer") | ||
11 | local fs = require("luarocks.fs") | ||
12 | local cache = require("luarocks.admin.cache") | ||
13 | local index = require("luarocks.admin.index") | ||
14 | |||
15 | local argparse = require("luarocks.vendor.argparse") | ||
16 | local type Parser = argparse.Parser | ||
17 | |||
18 | local type a = require("luarocks.core.types.args") | ||
19 | local type Args = a.Args | ||
20 | |||
21 | function add.add_to_parser(parser: Parser) | ||
22 | local cmd = parser:command("add", "Add a rock or rockspec to a rocks server.", util.see_also()) | ||
23 | |||
24 | cmd:argument("rock", "A local rockspec or rock file.") | ||
25 | :args("+") | ||
26 | |||
27 | cmd:option("--server", "The server to use. If not given, the default server ".. | ||
28 | "set in the upload_server variable from the configuration file is used instead.") | ||
29 | :target("add_server") | ||
30 | cmd:flag("--no-refresh", "Do not refresh the local cache prior to ".. | ||
31 | "generation of the updated manifest.") | ||
32 | cmd:flag("--index", "Produce an index.html file for the manifest. This ".. | ||
33 | "flag is automatically set if an index.html file already exists.") | ||
34 | end | ||
35 | |||
36 | local function zip_manifests() | ||
37 | for ver in util.lua_versions() do | ||
38 | local file = "manifest-"..ver | ||
39 | local zip = file..".zip" | ||
40 | fs.delete(dir.path(fs.current_dir(), zip)) | ||
41 | fs.zip(zip, file) | ||
42 | end | ||
43 | end | ||
44 | |||
45 | local function add_files_to_server(refresh: boolean, rockfiles: {string}, server: string, upload_server: {string: string}, do_index: boolean): boolean, string, string | ||
46 | |||
47 | local download_url, login_url = cache.get_server_urls(server, upload_server) | ||
48 | local at = fs.current_dir() | ||
49 | local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url | ||
50 | |||
51 | local local_cache, protocol, server_path, user, password = refresh_fn(download_url, cfg.upload_user, cfg.upload_password) | ||
52 | if not local_cache then | ||
53 | return nil, protocol | ||
54 | end | ||
55 | |||
56 | if not login_url then | ||
57 | login_url = protocol.."://"..server_path | ||
58 | end | ||
59 | |||
60 | local ok, err = fs.change_dir(at) | ||
61 | if not ok then return nil, err end | ||
62 | |||
63 | local files = {} | ||
64 | for _, rockfile in ipairs(rockfiles) do | ||
65 | if fs.exists(rockfile) then | ||
66 | util.printout("Copying file "..rockfile.." to "..local_cache.."...") | ||
67 | local absolute = fs.absolute_name(rockfile) | ||
68 | fs.copy(absolute, local_cache, "read") | ||
69 | table.insert(files, dir.base_name(absolute)) | ||
70 | else | ||
71 | util.printerr("File "..rockfile.." not found") | ||
72 | end | ||
73 | end | ||
74 | if #files == 0 then | ||
75 | return nil, "No files found" | ||
76 | end | ||
77 | |||
78 | local ok, err = fs.change_dir(local_cache) | ||
79 | if not ok then return nil, err end | ||
80 | |||
81 | util.printout("Updating manifest...") | ||
82 | writer.make_manifest(local_cache, "one", true) | ||
83 | |||
84 | zip_manifests() | ||
85 | |||
86 | if fs.exists("index.html") then | ||
87 | do_index = true | ||
88 | end | ||
89 | |||
90 | if do_index then | ||
91 | util.printout("Updating index.html...") | ||
92 | index.make_index(local_cache) | ||
93 | end | ||
94 | |||
95 | local login_info = "" | ||
96 | if user then login_info = " -u "..user end | ||
97 | if password then login_info = login_info..":"..password end | ||
98 | if not login_url:match("/$") then | ||
99 | login_url = login_url .. "/" | ||
100 | end | ||
101 | |||
102 | if do_index then | ||
103 | table.insert(files, "index.html") | ||
104 | end | ||
105 | table.insert(files, "manifest") | ||
106 | for ver in util.lua_versions() do | ||
107 | table.insert(files, "manifest-"..ver) | ||
108 | table.insert(files, "manifest-"..ver..".zip") | ||
109 | end | ||
110 | |||
111 | -- TODO abstract away explicit 'curl' call | ||
112 | |||
113 | local cmd: string | ||
114 | if protocol == "rsync" then | ||
115 | local srv, path = server_path:match("([^/]+)(/.+)") | ||
116 | cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" | ||
117 | elseif protocol == "file" then | ||
118 | return fs.copy_contents(local_cache, server_path) | ||
119 | elseif upload_server and upload_server.sftp then | ||
120 | local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") | ||
121 | cmd = cfg.variables.SCP.." "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 | ||
122 | else | ||
123 | cmd = cfg.variables.CURL.." "..login_info.." -T '{"..table.concat(files, ",").."}' "..login_url | ||
124 | end | ||
125 | |||
126 | util.printout(cmd) | ||
127 | return fs.execute(cmd) | ||
128 | end | ||
129 | |||
130 | function add.command(args: Args): boolean, string, string --! | ||
131 | local server, server_table = cache.get_upload_server(args.add_server or args.server) | ||
132 | if not server then return nil, server_table end | ||
133 | return add_files_to_server(not args.no_refresh, args.rock, server, server_table, args.index) | ||
134 | end | ||
135 | |||
136 | |||
137 | return add | ||
diff --git a/src/luarocks/admin/cmd/make_manifest.tl b/src/luarocks/admin/cmd/make_manifest.tl new file mode 100644 index 00000000..c8e46f89 --- /dev/null +++ b/src/luarocks/admin/cmd/make_manifest.tl | |||
@@ -0,0 +1,57 @@ | |||
1 | |||
2 | --- Module implementing the luarocks-admin "make_manifest" command. | ||
3 | -- Compile a manifest file for a repository. | ||
4 | local record make_manifest | ||
5 | end | ||
6 | |||
7 | local writer = require("luarocks.manif.writer") | ||
8 | local index = require("luarocks.admin.index") | ||
9 | local cfg = require("luarocks.core.cfg") | ||
10 | local util = require("luarocks.util") | ||
11 | local deps = require("luarocks.deps") | ||
12 | local fs = require("luarocks.fs") | ||
13 | local dir = require("luarocks.dir") | ||
14 | |||
15 | local argparse = require("luarocks.vendor.argparse") | ||
16 | local type Parser = argparse.Parser | ||
17 | |||
18 | local type a = require("luarocks.core.types.args") | ||
19 | local type Args = a.Args | ||
20 | |||
21 | function make_manifest.add_to_parser(parser: Parser) | ||
22 | local cmd = parser:command("make_manifest", "Compile a manifest file for a repository.", util.see_also()) | ||
23 | |||
24 | cmd:argument("repository", "Local repository pathname.") | ||
25 | :args("?") | ||
26 | |||
27 | cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n".. | ||
28 | "Use this when rebuilding the manifest of a local rocks tree.") | ||
29 | util.deps_mode_option(cmd as Parser) | ||
30 | end | ||
31 | |||
32 | --- Driver function for "make_manifest" command. | ||
33 | -- @return boolean or (nil, string): True if manifest was generated, | ||
34 | -- or nil and an error message. | ||
35 | function make_manifest.command(args: Args): boolean, string | ||
36 | local repo = args.repository or cfg.rocks_dir | ||
37 | |||
38 | util.printout("Making manifest for "..repo) | ||
39 | |||
40 | if repo:match("/lib/luarocks") and not args.local_tree then | ||
41 | util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") | ||
42 | end | ||
43 | |||
44 | local ok, err = writer.make_manifest(repo, deps.get_deps_mode(args), not args.local_tree) | ||
45 | if ok and not args.local_tree then | ||
46 | util.printout("Generating index.html for "..repo) | ||
47 | index.make_index(repo) | ||
48 | end | ||
49 | if args.local_tree then | ||
50 | for luaver in util.lua_versions() do | ||
51 | fs.delete(dir.path(repo, "manifest-"..luaver)) | ||
52 | end | ||
53 | end | ||
54 | return ok, err | ||
55 | end | ||
56 | |||
57 | return make_manifest | ||
diff --git a/src/luarocks/admin/cmd/refresh_cache.tl b/src/luarocks/admin/cmd/refresh_cache.tl new file mode 100644 index 00000000..1e2b84d2 --- /dev/null +++ b/src/luarocks/admin/cmd/refresh_cache.tl | |||
@@ -0,0 +1,38 @@ | |||
1 | |||
2 | --- Module implementing the luarocks-admin "refresh_cache" command. | ||
3 | local record refresh_cache | ||
4 | end | ||
5 | |||
6 | local cfg = require("luarocks.core.cfg") | ||
7 | local util = require("luarocks.util") | ||
8 | local cache = require("luarocks.admin.cache") | ||
9 | |||
10 | local argparse = require("luarocks.vendor.argparse") | ||
11 | local type Parser = argparse.Parser | ||
12 | |||
13 | local type a = require("luarocks.core.types.args") | ||
14 | local type Args = a.Args | ||
15 | |||
16 | function refresh_cache.add_to_parser(parser: Parser) | ||
17 | local cmd = parser:command("refresh_cache", "Refresh local cache of a remote rocks server.", util.see_also()) | ||
18 | |||
19 | cmd:option("--from", "The server to use. If not given, the default server ".. | ||
20 | "set in the upload_server variable from the configuration file is used instead.") | ||
21 | :argname("<server>") | ||
22 | end | ||
23 | |||
24 | function refresh_cache.command(args: Args): boolean, string | ||
25 | local server, upload_server = cache.get_upload_server(args.server) | ||
26 | if not server then return nil, upload_server end | ||
27 | local download_url = cache.get_server_urls(server, upload_server) | ||
28 | |||
29 | local ok, err = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) | ||
30 | if not ok then | ||
31 | return nil, err | ||
32 | else | ||
33 | return true | ||
34 | end | ||
35 | end | ||
36 | |||
37 | |||
38 | return refresh_cache | ||
diff --git a/src/luarocks/admin/cmd/remove.tl b/src/luarocks/admin/cmd/remove.tl new file mode 100644 index 00000000..33b83db0 --- /dev/null +++ b/src/luarocks/admin/cmd/remove.tl | |||
@@ -0,0 +1,124 @@ | |||
1 | |||
2 | --- Module implementing the luarocks-admin "remove" command. | ||
3 | -- Removes a rock or rockspec from a rocks server. | ||
4 | local record admin_remove | ||
5 | end | ||
6 | |||
7 | local cfg = require("luarocks.core.cfg") | ||
8 | local util = require("luarocks.util") | ||
9 | local dir = require("luarocks.dir") | ||
10 | local writer = require("luarocks.manif.writer") | ||
11 | local fs = require("luarocks.fs") | ||
12 | local cache = require("luarocks.admin.cache") | ||
13 | local index = require("luarocks.admin.index") | ||
14 | |||
15 | local argparse = require("luarocks.vendor.argparse") | ||
16 | local type Parser = argparse.Parser | ||
17 | local type Option = argparse.Option | ||
18 | |||
19 | local type a = require("luarocks.core.types.args") | ||
20 | local type Args = a.Args | ||
21 | |||
22 | local type bo = require("luarocks.core.types.bopts") | ||
23 | local type BOpts = bo.BOpts | ||
24 | |||
25 | local type i = require("luarocks.core.types.installs") | ||
26 | local type IOpts = i.IOpts | ||
27 | |||
28 | local type p = require("luarocks.core.types.persist") | ||
29 | local type PersistableTable = p.PersistableTable | ||
30 | |||
31 | local type res = require("luarocks.core.types.result") | ||
32 | local type Result = res.Result | ||
33 | |||
34 | local type t = require("luarocks.core.types.tree") | ||
35 | local type Tree = t.Tree | ||
36 | |||
37 | local type q = require("luarocks.core.types.query") | ||
38 | local type Query = q.Query | ||
39 | |||
40 | local type r = require("luarocks.core.types.rockspec") | ||
41 | local type Rockspec = r.Rockspec | ||
42 | local type Dependencies = r.Dependencies | ||
43 | |||
44 | local type m = require("luarocks.core.types.manifest") | ||
45 | local type Entry = m.Manifest.Entry | ||
46 | |||
47 | function admin_remove.add_to_parser(parser: Parser) | ||
48 | local cmd = parser:command("remove", "Remove a rock or rockspec from a rocks server.", util.see_also()) | ||
49 | |||
50 | cmd:argument("rock", "A local rockspec or rock file.") | ||
51 | :args("+") | ||
52 | |||
53 | cmd:option("--server", "The server to use. If not given, the default server ".. | ||
54 | "set in the upload_server variable from the configuration file is used instead.") | ||
55 | cmd:flag("--no-refresh", "Do not refresh the local cache prior to ".. | ||
56 | "generation of the updated manifest.") | ||
57 | end | ||
58 | |||
59 | local function remove_files_from_server(refresh: boolean, rockfiles: {string}, server: string, upload_server: {string: string}): boolean, string | ||
60 | |||
61 | local download_url, login_url = cache.get_server_urls(server, upload_server) | ||
62 | local at = fs.current_dir() | ||
63 | local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url | ||
64 | |||
65 | local local_cache, protocol, server_path, user, password = refresh_fn(download_url, cfg.upload_user, cfg.upload_password) | ||
66 | if not local_cache then | ||
67 | return nil, protocol | ||
68 | end | ||
69 | |||
70 | local ok, err = fs.change_dir(at) | ||
71 | if not ok then return nil, err end | ||
72 | |||
73 | local nr_files = 0 | ||
74 | for _, rockfile in ipairs(rockfiles) do | ||
75 | local basename = dir.base_name(rockfile) | ||
76 | local file = dir.path(local_cache, basename) | ||
77 | util.printout("Removing file "..file.."...") | ||
78 | fs.delete(file) | ||
79 | if not fs.exists(file) then | ||
80 | nr_files = nr_files + 1 | ||
81 | else | ||
82 | util.printerr("Failed removing "..file) | ||
83 | end | ||
84 | end | ||
85 | if nr_files == 0 then | ||
86 | return nil, "No files removed." | ||
87 | end | ||
88 | |||
89 | local ok, err = fs.change_dir(local_cache) | ||
90 | if not ok then return nil, err end | ||
91 | |||
92 | util.printout("Updating manifest...") | ||
93 | writer.make_manifest(local_cache, "one", true) | ||
94 | util.printout("Updating index.html...") | ||
95 | index.make_index(local_cache) | ||
96 | |||
97 | if protocol == "file" then | ||
98 | local cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." --delete "..local_cache.."/ ".. server_path.."/" | ||
99 | util.printout(cmd) | ||
100 | fs.execute(cmd) | ||
101 | return true | ||
102 | end | ||
103 | |||
104 | if protocol ~= "rsync" then | ||
105 | return nil, "This command requires 'rsync', check your configuration." | ||
106 | end | ||
107 | |||
108 | local srv, path = server_path:match("([^/]+)(/.+)") | ||
109 | local cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." --delete -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" | ||
110 | |||
111 | util.printout(cmd) | ||
112 | fs.execute(cmd) | ||
113 | |||
114 | return true | ||
115 | end | ||
116 | |||
117 | function admin_remove.command(args: Args): boolean, string | ||
118 | local server, server_table = cache.get_upload_server(args.server) | ||
119 | if not server then return nil, server_table end | ||
120 | return remove_files_from_server(not args.no_refresh, args.rock, server, server_table) --! | ||
121 | end | ||
122 | |||
123 | |||
124 | return admin_remove | ||
diff --git a/src/luarocks/admin/index.tl b/src/luarocks/admin/index.tl new file mode 100644 index 00000000..06968828 --- /dev/null +++ b/src/luarocks/admin/index.tl | |||
@@ -0,0 +1,192 @@ | |||
1 | |||
2 | --- Module which builds the index.html page to be used in rocks servers. | ||
3 | local record index | ||
4 | end | ||
5 | |||
6 | local util = require("luarocks.util") | ||
7 | local fs = require("luarocks.fs") | ||
8 | local vers = require("luarocks.core.vers") | ||
9 | local persist = require("luarocks.persist") | ||
10 | local dir = require("luarocks.dir") | ||
11 | local manif = require("luarocks.manif") | ||
12 | |||
13 | local type r = require("luarocks.core.types.rockspec") | ||
14 | local type Rockspec = r.Rockspec | ||
15 | |||
16 | local type m = require("luarocks.core.types.manifest") | ||
17 | local type Entry = m.Manifest.Entry | ||
18 | |||
19 | local ext_url_target = ' target="_blank"' | ||
20 | |||
21 | local index_header = [[ | ||
22 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | ||
23 | <html> | ||
24 | <head> | ||
25 | <title>Available rocks</title> | ||
26 | <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> | ||
27 | <style> | ||
28 | body { | ||
29 | background-color: white; | ||
30 | font-family: "bitstream vera sans", "verdana", "sans"; | ||
31 | font-size: 14px; | ||
32 | } | ||
33 | a { | ||
34 | color: #0000c0; | ||
35 | text-decoration: none; | ||
36 | } | ||
37 | a.pkg { | ||
38 | color: black; | ||
39 | } | ||
40 | a:hover { | ||
41 | text-decoration: underline; | ||
42 | } | ||
43 | td.main { | ||
44 | border-style: none; | ||
45 | } | ||
46 | blockquote { | ||
47 | font-size: 12px; | ||
48 | } | ||
49 | td.package { | ||
50 | background-color: #f0f0f0; | ||
51 | vertical-align: top; | ||
52 | } | ||
53 | td.spacer { | ||
54 | height: 5px; | ||
55 | } | ||
56 | td.version { | ||
57 | background-color: #d0d0d0; | ||
58 | vertical-align: top; | ||
59 | text-align: left; | ||
60 | padding: 5px; | ||
61 | width: 100px; | ||
62 | } | ||
63 | p.manifest { | ||
64 | font-size: 8px; | ||
65 | } | ||
66 | </style> | ||
67 | </head> | ||
68 | <body> | ||
69 | <h1>Available rocks</h1> | ||
70 | <p> | ||
71 | Lua modules available from this location for use with <a href="http://www.luarocks.org">LuaRocks</a>: | ||
72 | </p> | ||
73 | <table class="main"> | ||
74 | ]] | ||
75 | |||
76 | local index_package_begin = [[ | ||
77 | <td class="package"> | ||
78 | <p><a name="$anchor"></a><a href="#$anchor" class="pkg"><b>$package</b></a> - $summary<br/> | ||
79 | </p><blockquote><p>$detailed<br/> | ||
80 | $externaldependencies | ||
81 | <font size="-1"><a href="$original">latest sources</a> $homepage | License: $license</font></p> | ||
82 | </blockquote></a></td> | ||
83 | <td class="version"> | ||
84 | ]] | ||
85 | |||
86 | local index_package_end = [[ | ||
87 | </td></tr> | ||
88 | <tr><td colspan="2" class="spacer"></td></tr> | ||
89 | ]] | ||
90 | |||
91 | local index_footer_begin = [[ | ||
92 | </table> | ||
93 | <p class="manifest"> | ||
94 | <a href="manifest">manifest file</a> | ||
95 | ]] | ||
96 | local index_manifest_ver = [[ | ||
97 | • <a href="manifest-$VER">Lua $VER manifest file</a> (<a href="manifest-$VER.zip">zip</a>) | ||
98 | ]] | ||
99 | local index_footer_end = [[ | ||
100 | </p> | ||
101 | </body> | ||
102 | </html> | ||
103 | ]] | ||
104 | |||
105 | function index.format_external_dependencies(rockspec: Rockspec): string | ||
106 | if rockspec.external_dependencies then | ||
107 | local deplist = {} | ||
108 | local listed_set: {string: boolean} = {} | ||
109 | local plats: {string : string} = nil | ||
110 | for name, desc in util.sortedpairs(rockspec.external_dependencies) do | ||
111 | if name ~= "platforms" then | ||
112 | table.insert(deplist, name:lower()) | ||
113 | listed_set[name] = true | ||
114 | else | ||
115 | plats = desc | ||
116 | end | ||
117 | end | ||
118 | if plats then | ||
119 | for plat, entries in util.sortedpairs(plats) do | ||
120 | for name, desc in util.sortedpairs(entries) do | ||
121 | if not listed_set[name] then | ||
122 | table.insert(deplist, name:lower() .. " (on "..plat..")") | ||
123 | end | ||
124 | end | ||
125 | end | ||
126 | end | ||
127 | return '<p><b>External dependencies:</b> ' .. table.concat(deplist, ', ').. '</p>' | ||
128 | else | ||
129 | return "" | ||
130 | end | ||
131 | end | ||
132 | |||
133 | function index.make_index(repo: string): boolean, string | ||
134 | if not fs.is_dir(repo) then | ||
135 | return nil, "Cannot access repository at "..repo | ||
136 | end | ||
137 | local manifest = manif.load_manifest(repo) | ||
138 | local out = io.open(dir.path(repo, "index.html"), "w") | ||
139 | |||
140 | out:write(index_header) | ||
141 | for package, version_list in util.sortedpairs(manifest.repository) do | ||
142 | local latest_rockspec: string = nil | ||
143 | local output = index_package_begin | ||
144 | for version, data in util.sortedpairs(version_list, vers.compare_versions) do | ||
145 | local versions = {} | ||
146 | output = output..version..': ' | ||
147 | table.sort(data, function(a: Entry,b: Entry): boolean return a.arch < b.arch end) | ||
148 | for _, item in ipairs(data) do | ||
149 | local file: string | ||
150 | if item.arch == 'rockspec' then | ||
151 | file = ("%s-%s.rockspec"):format(package, version) | ||
152 | if not latest_rockspec then latest_rockspec = file end | ||
153 | else | ||
154 | file = ("%s-%s.%s.rock"):format(package, version, item.arch) | ||
155 | end | ||
156 | table.insert(versions, '<a href="'..file..'">'..item.arch..'</a>') | ||
157 | end | ||
158 | output = output .. table.concat(versions, ', ') .. '<br/>' | ||
159 | end | ||
160 | output = output .. index_package_end | ||
161 | if latest_rockspec then | ||
162 | local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec)) as Rockspec | ||
163 | local descript = rockspec.description or {} | ||
164 | local vars = { | ||
165 | anchor = package, | ||
166 | package = rockspec.package, | ||
167 | original = rockspec.source.url, | ||
168 | summary = descript.summary or "", | ||
169 | detailed = descript.detailed or "", | ||
170 | license = descript.license or "N/A", | ||
171 | homepage = descript.homepage and ('| <a href="'..descript.homepage..'"'..ext_url_target..'>project homepage</a>') or "", | ||
172 | externaldependencies = index.format_external_dependencies(rockspec) | ||
173 | } | ||
174 | vars.detailed = vars.detailed:gsub("\n\n", "</p><p>"):gsub("%s+", " ") | ||
175 | vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '<a href="%1"'..ext_url_target..'>%1</a>') | ||
176 | output = output:gsub("$(%w+)", vars) | ||
177 | else | ||
178 | output = output:gsub("$anchor", package) | ||
179 | output = output:gsub("$package", package) | ||
180 | output = output:gsub("$(%w+)", "") | ||
181 | end | ||
182 | out:write(output) | ||
183 | end | ||
184 | out:write(index_footer_begin) | ||
185 | for ver in util.lua_versions() do | ||
186 | out:write((index_manifest_ver:gsub("$VER", ver))) | ||
187 | end | ||
188 | out:write(index_footer_end) | ||
189 | out:close() | ||
190 | end | ||
191 | |||
192 | return index | ||
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index 03eedd6d..fa3e9901 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl | |||
@@ -110,6 +110,12 @@ local record cfg | |||
110 | -- cmd path | 110 | -- cmd path |
111 | package_paths: function(string | Tree): string, string, string | 111 | package_paths: function(string | Tree): string, string, string |
112 | export_path_separator: string | 112 | export_path_separator: string |
113 | -- admin cache | ||
114 | upload_server: string | ||
115 | upload_servers: {string: string} | ||
116 | -- admin add | ||
117 | upload_user: string | ||
118 | upload_password: string | ||
113 | end | 119 | end |
114 | 120 | ||
115 | return cfg \ No newline at end of file | 121 | return cfg \ No newline at end of file |
diff --git a/src/luarocks/core/types/args.d.tl b/src/luarocks/core/types/args.d.tl index d2c49ea6..00945789 100644 --- a/src/luarocks/core/types/args.d.tl +++ b/src/luarocks/core/types/args.d.tl | |||
@@ -1,103 +1,108 @@ | |||
1 | local record args | 1 | local record args |
2 | record Args | 2 | record Args |
3 | tree: string | 3 | tree: string |
4 | global: boolean | 4 | global: boolean |
5 | deps_mode: string | 5 | deps_mode: string |
6 | ["local"]: boolean --! | 6 | ["local"]: boolean --! |
7 | project_tree: string | 7 | project_tree: string |
8 | server: string | 8 | server: string |
9 | dev: boolean | 9 | dev: boolean |
10 | only_server: string --! | 10 | only_server: string --! |
11 | verbose: string | 11 | verbose: string |
12 | lua_version: string | 12 | lua_version: string |
13 | lua_dir: string | 13 | lua_dir: string |
14 | no_project: boolean | 14 | no_project: boolean |
15 | input: {string} | 15 | input: {string} |
16 | nodeps: boolean | 16 | nodeps: boolean |
17 | timeout: number --! | 17 | timeout: number --! |
18 | command: string | 18 | command: string |
19 | key: string | 19 | key: string |
20 | value: string | 20 | value: string |
21 | only_sources: string | 21 | only_sources: string |
22 | no_manifest: boolean | 22 | no_manifest: boolean |
23 | force_lock: boolean | 23 | force_lock: boolean |
24 | rockspec: string | 24 | rockspec: string |
25 | namespace: string | 25 | namespace: string |
26 | pack_binary_rock: boolean | 26 | pack_binary_rock: boolean |
27 | only_deps: boolean | 27 | only_deps: boolean |
28 | branch: string | 28 | branch: string |
29 | verify: boolean --! | 29 | verify: boolean --! |
30 | check_lua_versions: boolean --! | 30 | check_lua_versions: boolean --! |
31 | pin: boolean | 31 | pin: boolean |
32 | no_install: boolean | 32 | no_install: boolean |
33 | sign: boolean | 33 | sign: boolean |
34 | no_doc: boolean | 34 | no_doc: boolean |
35 | keep: boolean | 35 | keep: boolean |
36 | force: boolean | 36 | force: boolean |
37 | force_fast: boolean | 37 | force_fast: boolean |
38 | rock: string | 38 | rock: string |
39 | version: string | 39 | version: string |
40 | scope: string | 40 | scope: string |
41 | lua_incdir: string | 41 | lua_incdir: string |
42 | lua_libdir: string | 42 | lua_libdir: string |
43 | lua_ver: string | 43 | lua_ver: string |
44 | system_config: string | 44 | system_config: string |
45 | user_config: string | 45 | user_config: string |
46 | rock_trees: string | 46 | rock_trees: string |
47 | unset: boolean | 47 | unset: boolean |
48 | json: boolean | 48 | json: boolean |
49 | home: boolean | 49 | home: boolean |
50 | porcelain: boolean | 50 | porcelain: boolean |
51 | list: boolean --! | 51 | list: boolean --! |
52 | name: string | 52 | name: string |
53 | all: boolean | 53 | all: boolean |
54 | source: string | 54 | source: string |
55 | arch: string | 55 | arch: string |
56 | location: string | 56 | location: string |
57 | tag: string | 57 | tag: string |
58 | output: string | 58 | output: string |
59 | homepage: string | 59 | homepage: string |
60 | rockspec_format: string | 60 | rockspec_format: string |
61 | summary: string | 61 | summary: string |
62 | detailed: string | 62 | detailed: string |
63 | license: string | 63 | license: string |
64 | lua_versions: string | 64 | lua_versions: string |
65 | lib: string | 65 | lib: string |
66 | no_gitignore: boolean | 66 | no_gitignore: boolean |
67 | no_wrapper_scripts: boolean | 67 | no_wrapper_scripts: boolean |
68 | wrapper_dir: string | 68 | wrapper_dir: string |
69 | reset: boolean | 69 | reset: boolean |
70 | filter: string | 70 | filter: string |
71 | outdated: boolean | 71 | outdated: boolean |
72 | new_version: string | 72 | new_version: string |
73 | dir: string | 73 | dir: string |
74 | new_url: string | 74 | new_url: string |
75 | lr_path: string | 75 | lr_path: string |
76 | lr_cpath: string | 76 | lr_cpath: string |
77 | lr_bin: string | 77 | lr_bin: string |
78 | full: boolean | 78 | full: boolean |
79 | append: boolean | 79 | append: boolean |
80 | no_bin: boolean | 80 | no_bin: boolean |
81 | old_versions: boolean | 81 | old_versions: boolean |
82 | binary: boolean | 82 | binary: boolean |
83 | rock_tree: boolean | 83 | rock_tree: boolean |
84 | rock_namespace: boolean | 84 | rock_namespace: boolean |
85 | rock_dir: boolean | 85 | rock_dir: boolean |
86 | rock_license: boolean | 86 | rock_license: boolean |
87 | issues: boolean | 87 | issues: boolean |
88 | labels: boolean | 88 | labels: boolean |
89 | modules: boolean | 89 | modules: boolean |
90 | deps: boolean | 90 | deps: boolean |
91 | build_deps: boolean | 91 | build_deps: boolean |
92 | test_deps: boolean | 92 | test_deps: boolean |
93 | mversion: boolean | 93 | mversion: boolean |
94 | test_type: string | 94 | test_type: string |
95 | args: {string} | 95 | args: {string} |
96 | prepare: boolean | 96 | prepare: boolean |
97 | src_rock: string | 97 | src_rock: string |
98 | skip_pack: boolean | 98 | skip_pack: boolean |
99 | modname: string | 99 | modname: string |
100 | end | 100 | add_server: string |
101 | no_refresh: boolean | ||
102 | index: boolean | ||
103 | repository: string | ||
104 | local_tree: string | ||
105 | end | ||
101 | end | 106 | end |
102 | 107 | ||
103 | return args \ No newline at end of file | 108 | return args \ No newline at end of file |