diff options
| author | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-07-16 21:14:12 +0000 |
|---|---|---|
| committer | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-07-16 21:14:12 +0000 |
| commit | f1e7565c7a93b213f09216aaa2c50e10df44d187 (patch) | |
| tree | 6dd969112d29e01494eeb4af832905fbcb754f10 /src | |
| parent | ba906abeafae6ebc199bb3ed447bc2a31bb9b770 (diff) | |
| download | luarocks-f1e7565c7a93b213f09216aaa2c50e10df44d187.tar.gz luarocks-f1e7565c7a93b213f09216aaa2c50e10df44d187.tar.bz2 luarocks-f1e7565c7a93b213f09216aaa2c50e10df44d187.zip | |
add get_rockspec command
git-svn-id: http://luarocks.org/svn/luarocks/trunk@41 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
| -rwxr-xr-x | src/bin/luarocks | 1 | ||||
| -rw-r--r-- | src/luarocks/fetch.lua | 13 | ||||
| -rw-r--r-- | src/luarocks/get_rockspec.lua | 81 | ||||
| -rw-r--r-- | src/luarocks/search.lua | 2 |
4 files changed, 94 insertions, 3 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks index ae0c2b42..2e2ac422 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks | |||
| @@ -15,5 +15,6 @@ commands.search = require("luarocks.search") | |||
| 15 | commands.list = require("luarocks.list") | 15 | commands.list = require("luarocks.list") |
| 16 | commands.remove = require("luarocks.remove") | 16 | commands.remove = require("luarocks.remove") |
| 17 | commands.make = require("luarocks.make") | 17 | commands.make = require("luarocks.make") |
| 18 | commands.get_rockspec = require("luarocks.get_rockspec") | ||
| 18 | 19 | ||
| 19 | command_line.run_command(...) | 20 | command_line.run_command(...) |
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 4e17c91d..fc0535a9 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
| @@ -200,9 +200,11 @@ end | |||
| 200 | -- Only the LuaRocks runtime loader should use | 200 | -- Only the LuaRocks runtime loader should use |
| 201 | -- load_local_rockspec directly. | 201 | -- load_local_rockspec directly. |
| 202 | -- @param filename string: Local or remote filename of a rockspec. | 202 | -- @param filename string: Local or remote filename of a rockspec. |
| 203 | -- @param location string or nil: Where to download. If not given, | ||
| 204 | -- a temporary dir is created. | ||
| 203 | -- @return table or (nil, string, [string]): A table representing the rockspec | 205 | -- @return table or (nil, string, [string]): A table representing the rockspec |
| 204 | -- or nil followed by an error message and optional error code. | 206 | -- or nil followed by an error message and optional error code. |
| 205 | function load_rockspec(filename) | 207 | function load_rockspec(filename, location) |
| 206 | assert(type(filename) == "string") | 208 | assert(type(filename) == "string") |
| 207 | 209 | ||
| 208 | local name = dir.base_name(filename):match("(.*)%.rockspec") | 210 | local name = dir.base_name(filename):match("(.*)%.rockspec") |
| @@ -210,7 +212,14 @@ function load_rockspec(filename) | |||
| 210 | return nil, "Filename '"..filename.."' does not look like a rockspec." | 212 | return nil, "Filename '"..filename.."' does not look like a rockspec." |
| 211 | end | 213 | end |
| 212 | 214 | ||
| 213 | local filename, err, errcode = fetch_url_at_temp_dir(filename,"luarocks-rockspec-"..name) | 215 | local err, errcode |
| 216 | if location then | ||
| 217 | fs.change_dir(location) | ||
| 218 | filename, err = fetch_url(filename) | ||
| 219 | fs.pop_dir() | ||
| 220 | else | ||
| 221 | filename, err, errcode = fetch_url_at_temp_dir(filename,"luarocks-rockspec-"..name) | ||
| 222 | end | ||
| 214 | if not filename then | 223 | if not filename then |
| 215 | return nil, err, errcode | 224 | return nil, err, errcode |
| 216 | end | 225 | end |
diff --git a/src/luarocks/get_rockspec.lua b/src/luarocks/get_rockspec.lua new file mode 100644 index 00000000..77fb6d21 --- /dev/null +++ b/src/luarocks/get_rockspec.lua | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | |||
| 2 | --- Module implementing the luarocks "get_rockspec" command. | ||
| 3 | -- Download a rockspec from the repository. | ||
| 4 | module("luarocks.get_rockspec", package.seeall) | ||
| 5 | |||
| 6 | local util = require("luarocks.util") | ||
| 7 | local path = require("luarocks.path") | ||
| 8 | local fetch = require("luarocks.fetch") | ||
| 9 | local search = require("luarocks.search") | ||
| 10 | |||
| 11 | help_summary = "Download a specific rockspec file from a rocks server." | ||
| 12 | help_arguments = "[--all] [<name> [<version>]]" | ||
| 13 | |||
| 14 | help = [[ | ||
| 15 | --all Download multiple rockspec files if there is more than one match. | ||
| 16 | ]] | ||
| 17 | |||
| 18 | local function get_rockspec(rockspec_file) | ||
| 19 | local rockspec = fetch.load_rockspec(rockspec_file, ".") | ||
| 20 | if not rockspec then | ||
| 21 | return nil, "Failed loading rockspec "..rockspec_file | ||
| 22 | end | ||
| 23 | return true | ||
| 24 | end | ||
| 25 | |||
| 26 | --- Driver function for the "get_rockspec" command. | ||
| 27 | -- @param name string: a rock name. | ||
| 28 | -- @param version string or nil: if the name of a package is given, a | ||
| 29 | -- version may also be passed. | ||
| 30 | -- @return boolean or (nil, string): true if successful or nil followed | ||
| 31 | -- by an error message. | ||
| 32 | function run(...) | ||
| 33 | local flags, name, version = util.parse_flags(...) | ||
| 34 | |||
| 35 | assert(type(version) == "string" or not version) | ||
| 36 | if type(name) ~= "string" and not flags["all"] then | ||
| 37 | return nil, "Argument missing, see help." | ||
| 38 | end | ||
| 39 | if not name then name, version = "", "" end | ||
| 40 | |||
| 41 | local query = search.make_query(name, version) | ||
| 42 | query.arch = "rockspec" | ||
| 43 | local results, err | ||
| 44 | if flags["all"] then | ||
| 45 | if name == "" then query.exact_name = false end | ||
| 46 | results, err = search.search_repos(query) | ||
| 47 | print(results, err) | ||
| 48 | else | ||
| 49 | results, err = search.find_suitable_rock(query) | ||
| 50 | end | ||
| 51 | if type(results) == "string" then | ||
| 52 | return get_rockspec(results) | ||
| 53 | elseif type(results) == "table" and next(results) then | ||
| 54 | if flags["all"] then | ||
| 55 | local all_ok = true | ||
| 56 | local any_err = "" | ||
| 57 | for name, result in pairs(results) do | ||
| 58 | for version, versions in pairs(result) do | ||
| 59 | for _,items in pairs(versions) do | ||
| 60 | local filename = path.make_url(items.repo, name, version, items.arch) | ||
| 61 | local ok, err = get_rockspec(filename) | ||
| 62 | if not ok then | ||
| 63 | all_ok = false | ||
| 64 | any_err = any_err .. "\n" .. err | ||
| 65 | end | ||
| 66 | end | ||
| 67 | end | ||
| 68 | end | ||
| 69 | return all_ok, any_err | ||
| 70 | else | ||
| 71 | print("Multiple search results were returned.") | ||
| 72 | print() | ||
| 73 | print("Search results:") | ||
| 74 | print("---------------") | ||
| 75 | print_results(results) | ||
| 76 | return nil, "Please narrow your query or use --all." | ||
| 77 | end | ||
| 78 | else | ||
| 79 | return nil, "Could not find a result named "..name.."." | ||
| 80 | end | ||
| 81 | end | ||
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 06868810..e31c0c1b 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
| @@ -191,7 +191,7 @@ end | |||
| 191 | -- and values are tables matching version strings to an array of | 191 | -- and values are tables matching version strings to an array of |
| 192 | -- rocks servers; if no results are found, an empty table is returned. | 192 | -- rocks servers; if no results are found, an empty table is returned. |
| 193 | -- In case of errors, nil and and error message are returned. | 193 | -- In case of errors, nil and and error message are returned. |
| 194 | local function search_repos(query) | 194 | function search_repos(query) |
| 195 | assert(type(query) == "table") | 195 | assert(type(query) == "table") |
| 196 | 196 | ||
| 197 | local results = {} | 197 | local results = {} |
