diff options
author | Hisham <hisham@gobolinux.org> | 2016-11-14 14:15:47 -0200 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-11-14 14:15:47 -0200 |
commit | 1e7800c2993cf828f448a534106aa4046a48a591 (patch) | |
tree | f6d69aae8083deef3242d1c04c868eb7351eaa2f | |
parent | b75ca805cf6c92214568b28540a931b70367a548 (diff) | |
download | luarocks-1e7800c2993cf828f448a534106aa4046a48a591.tar.gz luarocks-1e7800c2993cf828f448a534106aa4046a48a591.tar.bz2 luarocks-1e7800c2993cf828f448a534106aa4046a48a591.zip |
Move get_versions from luarocks.core.manif to luarocks.manif.
All functions that were in core only for get_versions are moved out as well.
Made possible by PR #654.
-rw-r--r-- | src/luarocks/core/dir.lua | 12 | ||||
-rw-r--r-- | src/luarocks/core/manif.lua | 28 | ||||
-rw-r--r-- | src/luarocks/core/path.lua | 37 | ||||
-rw-r--r-- | src/luarocks/dir.lua | 12 | ||||
-rw-r--r-- | src/luarocks/manif.lua | 27 | ||||
-rw-r--r-- | src/luarocks/path.lua | 37 |
6 files changed, 76 insertions, 77 deletions
diff --git a/src/luarocks/core/dir.lua b/src/luarocks/core/dir.lua index 240bb38a..05b2c72d 100644 --- a/src/luarocks/core/dir.lua +++ b/src/luarocks/core/dir.lua | |||
@@ -39,17 +39,5 @@ function dir.split_url(url) | |||
39 | return protocol, pathname | 39 | return protocol, pathname |
40 | end | 40 | end |
41 | 41 | ||
42 | --- Normalize a url or local path. | ||
43 | -- URLs should be in the "protocol://path" format. System independent | ||
44 | -- forward slashes are used, removing trailing and double slashes | ||
45 | -- @param url string: an URL or a local pathname. | ||
46 | -- @return string: Normalized result. | ||
47 | function dir.normalize(name) | ||
48 | local protocol, pathname = dir.split_url(name) | ||
49 | pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/") | ||
50 | if protocol ~= "file" then pathname = protocol .."://"..pathname end | ||
51 | return pathname | ||
52 | end | ||
53 | |||
54 | return dir | 42 | return dir |
55 | 43 | ||
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index 49619e7f..549cfb4c 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua | |||
@@ -6,8 +6,6 @@ local persist = require("luarocks.core.persist") | |||
6 | local type_check = require("luarocks.core.type_check") | 6 | local type_check = require("luarocks.core.type_check") |
7 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
8 | local dir = require("luarocks.core.dir") | 8 | local dir = require("luarocks.core.dir") |
9 | local util = require("luarocks.core.util") | ||
10 | local path = require("luarocks.core.path") | ||
11 | local require = nil | 9 | local require = nil |
12 | -------------------------------------------------------------------------------- | 10 | -------------------------------------------------------------------------------- |
13 | 11 | ||
@@ -77,30 +75,4 @@ function manif.load_local_manifest(repo_url) | |||
77 | return manif.manifest_loader(pathname, repo_url, nil, true) | 75 | return manif.manifest_loader(pathname, repo_url, nil, true) |
78 | end | 76 | end |
79 | 77 | ||
80 | --- Get all versions of a package listed in a manifest file. | ||
81 | -- @param name string: a package name. | ||
82 | -- @param deps_mode string: "one", to use only the currently | ||
83 | -- configured tree; "order" to select trees based on order | ||
84 | -- (use the current tree and all trees below it on the list) | ||
85 | -- or "all", to use all trees. | ||
86 | -- @return table: An array of strings listing installed | ||
87 | -- versions of a package. | ||
88 | function manif.get_versions(name, deps_mode) | ||
89 | assert(type(name) == "string") | ||
90 | assert(type(deps_mode) == "string") | ||
91 | |||
92 | local version_set = {} | ||
93 | path.map_trees(deps_mode, function(tree) | ||
94 | local manifest = manif.load_local_manifest(path.rocks_dir(tree)) | ||
95 | |||
96 | if manifest and manifest.repository[name] then | ||
97 | for version in pairs(manifest.repository[name]) do | ||
98 | version_set[version] = true | ||
99 | end | ||
100 | end | ||
101 | end) | ||
102 | |||
103 | return util.keys(version_set) | ||
104 | end | ||
105 | |||
106 | return manif | 78 | return manif |
diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua index a4eb8b4b..ed85aeac 100644 --- a/src/luarocks/core/path.lua +++ b/src/luarocks/core/path.lua | |||
@@ -111,41 +111,4 @@ function path.which_i(file_name, name, version, tree, i) | |||
111 | return file_name | 111 | return file_name |
112 | end | 112 | end |
113 | 113 | ||
114 | function path.rocks_tree_to_string(tree) | ||
115 | if type(tree) == "string" then | ||
116 | return tree | ||
117 | else | ||
118 | assert(type(tree) == "table") | ||
119 | return tree.root | ||
120 | end | ||
121 | end | ||
122 | |||
123 | --- Apply a given function to the active rocks trees based on chosen dependency mode. | ||
124 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | ||
125 | -- "all" for all trees, "order" for all trees with priority >= the current default, | ||
126 | -- "none" for no trees (this function becomes a nop). | ||
127 | -- @param fn function: function to be applied, with the tree dir (string) as the first | ||
128 | -- argument and the remaining varargs of map_trees as the following arguments. | ||
129 | -- @return a table with all results of invocations of fn collected. | ||
130 | function path.map_trees(deps_mode, fn, ...) | ||
131 | local result = {} | ||
132 | if deps_mode == "one" then | ||
133 | table.insert(result, (fn(cfg.root_dir, ...)) or 0) | ||
134 | elseif deps_mode == "all" or deps_mode == "order" then | ||
135 | local use = false | ||
136 | if deps_mode == "all" then | ||
137 | use = true | ||
138 | end | ||
139 | for _, tree in ipairs(cfg.rocks_trees) do | ||
140 | if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(cfg.root_dir)) then | ||
141 | use = true | ||
142 | end | ||
143 | if use then | ||
144 | table.insert(result, (fn(tree, ...)) or 0) | ||
145 | end | ||
146 | end | ||
147 | end | ||
148 | return result | ||
149 | end | ||
150 | |||
151 | return path | 114 | return path |
diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index ad7fb870..71477804 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua | |||
@@ -24,4 +24,16 @@ function dir.dir_name(pathname) | |||
24 | return (pathname:gsub("/*$", ""):match("(.*)[/]+[^/]*")) or "" | 24 | return (pathname:gsub("/*$", ""):match("(.*)[/]+[^/]*")) or "" |
25 | end | 25 | end |
26 | 26 | ||
27 | --- Normalize a url or local path. | ||
28 | -- URLs should be in the "protocol://path" format. System independent | ||
29 | -- forward slashes are used, removing trailing and double slashes | ||
30 | -- @param url string: an URL or a local pathname. | ||
31 | -- @return string: Normalized result. | ||
32 | function dir.normalize(name) | ||
33 | local protocol, pathname = dir.split_url(name) | ||
34 | pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/") | ||
35 | if protocol ~= "file" then pathname = protocol .."://"..pathname end | ||
36 | return pathname | ||
37 | end | ||
38 | |||
27 | return dir | 39 | return dir |
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 7fdfecda..7f3085db 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
@@ -11,6 +11,7 @@ local dir = require("luarocks.dir") | |||
11 | local fs = require("luarocks.fs") | 11 | local fs = require("luarocks.fs") |
12 | local cfg = require("luarocks.core.cfg") | 12 | local cfg = require("luarocks.core.cfg") |
13 | local path = require("luarocks.path") | 13 | local path = require("luarocks.path") |
14 | local util = require("luarocks.util") | ||
14 | 15 | ||
15 | manif.rock_manifest_cache = {} | 16 | manif.rock_manifest_cache = {} |
16 | 17 | ||
@@ -194,4 +195,30 @@ function manif.get_providing_file(name, version, item_type, item_name, repo) | |||
194 | return type(subtree) == "string" and "lib" or "lua", file_path | 195 | return type(subtree) == "string" and "lib" or "lua", file_path |
195 | end | 196 | end |
196 | 197 | ||
198 | --- Get all versions of a package listed in a manifest file. | ||
199 | -- @param name string: a package name. | ||
200 | -- @param deps_mode string: "one", to use only the currently | ||
201 | -- configured tree; "order" to select trees based on order | ||
202 | -- (use the current tree and all trees below it on the list) | ||
203 | -- or "all", to use all trees. | ||
204 | -- @return table: An array of strings listing installed | ||
205 | -- versions of a package. | ||
206 | function manif.get_versions(name, deps_mode) | ||
207 | assert(type(name) == "string") | ||
208 | assert(type(deps_mode) == "string") | ||
209 | |||
210 | local version_set = {} | ||
211 | path.map_trees(deps_mode, function(tree) | ||
212 | local manifest = manif.load_local_manifest(path.rocks_dir(tree)) | ||
213 | |||
214 | if manifest and manifest.repository[name] then | ||
215 | for version in pairs(manifest.repository[name]) do | ||
216 | version_set[version] = true | ||
217 | end | ||
218 | end | ||
219 | end) | ||
220 | |||
221 | return util.keys(version_set) | ||
222 | end | ||
223 | |||
197 | return manif | 224 | return manif |
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 71893cf1..37898435 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
@@ -231,4 +231,41 @@ function path.use_tree(tree) | |||
231 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | 231 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) |
232 | end | 232 | end |
233 | 233 | ||
234 | function path.rocks_tree_to_string(tree) | ||
235 | if type(tree) == "string" then | ||
236 | return tree | ||
237 | else | ||
238 | assert(type(tree) == "table") | ||
239 | return tree.root | ||
240 | end | ||
241 | end | ||
242 | |||
243 | --- Apply a given function to the active rocks trees based on chosen dependency mode. | ||
244 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | ||
245 | -- "all" for all trees, "order" for all trees with priority >= the current default, | ||
246 | -- "none" for no trees (this function becomes a nop). | ||
247 | -- @param fn function: function to be applied, with the tree dir (string) as the first | ||
248 | -- argument and the remaining varargs of map_trees as the following arguments. | ||
249 | -- @return a table with all results of invocations of fn collected. | ||
250 | function path.map_trees(deps_mode, fn, ...) | ||
251 | local result = {} | ||
252 | if deps_mode == "one" then | ||
253 | table.insert(result, (fn(cfg.root_dir, ...)) or 0) | ||
254 | elseif deps_mode == "all" or deps_mode == "order" then | ||
255 | local use = false | ||
256 | if deps_mode == "all" then | ||
257 | use = true | ||
258 | end | ||
259 | for _, tree in ipairs(cfg.rocks_trees) do | ||
260 | if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(cfg.root_dir)) then | ||
261 | use = true | ||
262 | end | ||
263 | if use then | ||
264 | table.insert(result, (fn(tree, ...)) or 0) | ||
265 | end | ||
266 | end | ||
267 | end | ||
268 | return result | ||
269 | end | ||
270 | |||
234 | return path | 271 | return path |