diff options
| author | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-06-18 15:39:49 +0000 |
|---|---|---|
| committer | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-06-18 15:39:49 +0000 |
| commit | 4cd417b8abaccea3bd08bd50b8db2af9b63371f4 (patch) | |
| tree | b58c06329c1ba3301aec0af04a952d4b5b9a2f3b | |
| parent | 1a099c9c33827bd2e73fe4c08fd47ae6b45adfd2 (diff) | |
| download | luarocks-4cd417b8abaccea3bd08bd50b8db2af9b63371f4.tar.gz luarocks-4cd417b8abaccea3bd08bd50b8db2af9b63371f4.tar.bz2 luarocks-4cd417b8abaccea3bd08bd50b8db2af9b63371f4.zip | |
added preliminary support for 'luarocks-admin add'
git-svn-id: http://luarocks.org/svn/luarocks/trunk@28 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
| -rwxr-xr-x | src/bin/luarocks-admin | 1 | ||||
| -rw-r--r-- | src/luarocks/add.lua | 91 | ||||
| -rw-r--r-- | src/luarocks/command_line.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/manif.lua | 1 |
4 files changed, 93 insertions, 2 deletions
diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index 826597f6..c35e8b93 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin | |||
| @@ -10,5 +10,6 @@ commands = { | |||
| 10 | 10 | ||
| 11 | commands.help = require("luarocks.help") | 11 | commands.help = require("luarocks.help") |
| 12 | commands.make_manifest = require("luarocks.make_manifest") | 12 | commands.make_manifest = require("luarocks.make_manifest") |
| 13 | commands.add = require("luarocks.add") | ||
| 13 | 14 | ||
| 14 | command_line.run_command(...) | 15 | command_line.run_command(...) |
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua new file mode 100644 index 00000000..5671b84e --- /dev/null +++ b/src/luarocks/add.lua | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | |||
| 2 | --- Module implementing the luarocks-admin "add" command. | ||
| 3 | -- Adds a rock or rockspec to a rocks server. | ||
| 4 | module("luarocks.add", package.seeall) | ||
| 5 | |||
| 6 | local cfg = require("luarocks.cfg") | ||
| 7 | local util = require("luarocks.util") | ||
| 8 | local fetch = require("luarocks.fetch") | ||
| 9 | local dir = require("luarocks.dir") | ||
| 10 | local manif = require("luarocks.manif") | ||
| 11 | local fs = require("luarocks.fs") | ||
| 12 | |||
| 13 | help_summary = "Add a rock or rockpec to a rocks server." | ||
| 14 | help_arguments = "[--to=<server>] {<rockspec>|<rock>]}" | ||
| 15 | help = [[ | ||
| 16 | Argument may be a local rockspec or rock file. | ||
| 17 | The flag --to indicates which server to use. | ||
| 18 | If not given, the default server set in the upload_server variable | ||
| 19 | from the configuration file is used instead. | ||
| 20 | ]] | ||
| 21 | |||
| 22 | local function add_file_to_server(rockfile, server) | ||
| 23 | local protocol, server_path = dir.split_url(server) | ||
| 24 | local user = cfg.upload_user | ||
| 25 | local password = cfg.upload_password | ||
| 26 | if server_path:match("@") then | ||
| 27 | local credentials | ||
| 28 | credentials, server_path = server_path:match("([^@]*)@(.*)") | ||
| 29 | if credentials:match(":") then | ||
| 30 | user, password = credentials:match("([^:]*):(.*)") | ||
| 31 | else | ||
| 32 | user = credentials | ||
| 33 | end | ||
| 34 | end | ||
| 35 | if not fs.exists(rockfile) then | ||
| 36 | return nil, "Could not find "..rockfile | ||
| 37 | end | ||
| 38 | local rockfile = fs.absolute_name(rockfile) | ||
| 39 | local local_cache | ||
| 40 | if cfg.local_cache then | ||
| 41 | local_cache = cfg.local_cache .. "/" .. server_path | ||
| 42 | end | ||
| 43 | local tmp_cache = false | ||
| 44 | if not local_cache then | ||
| 45 | local_cache = fs.make_temp_dir("local_cache") | ||
| 46 | tmp_cache = true | ||
| 47 | end | ||
| 48 | local ok = fs.make_dir(local_cache) | ||
| 49 | if not ok then | ||
| 50 | return nil, "Failed creating local cache dir." | ||
| 51 | end | ||
| 52 | fs.change_dir(local_cache) | ||
| 53 | print("Refreshing cache "..local_cache.."...") | ||
| 54 | |||
| 55 | local login_info = "" | ||
| 56 | if user then login_info = " --user="..user end | ||
| 57 | if password then login_info = login_info .. " --password="..password end | ||
| 58 | |||
| 59 | fs.execute("wget -q -m -nd "..protocol.."://"..server_path..login_info) | ||
| 60 | print("Copying file...") | ||
| 61 | fs.copy(rockfile, local_cache) | ||
| 62 | print("Updating manifest and index.html...") | ||
| 63 | manif.make_manifest(local_cache) | ||
| 64 | manif.make_index(local_cache) | ||
| 65 | |||
| 66 | local login_info = "" | ||
| 67 | if user then login_info = " -u "..user end | ||
| 68 | if password then login_info = login_info..":"..password end | ||
| 69 | if not server_path:match("/$") then | ||
| 70 | server_path = server_path .. "/" | ||
| 71 | end | ||
| 72 | fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..protocol.."://"..server_path) | ||
| 73 | return true | ||
| 74 | end | ||
| 75 | |||
| 76 | function run(...) | ||
| 77 | local flags, file = util.parse_flags(...) | ||
| 78 | if type(file) ~= "string" then | ||
| 79 | return nil, "Argument missing, see help." | ||
| 80 | end | ||
| 81 | local server = flags["to"] | ||
| 82 | if not server then server = cfg.upload_server end | ||
| 83 | if not server then | ||
| 84 | return nil, "No server specified with --to and no default configured with upload_server." | ||
| 85 | end | ||
| 86 | if cfg.upload_aliases then | ||
| 87 | server = cfg.upload_aliases[server] or server | ||
| 88 | end | ||
| 89 | return add_file_to_server(file, server) | ||
| 90 | end | ||
| 91 | |||
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 9368e8ad..972302ee 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
| @@ -116,7 +116,7 @@ function run_command(...) | |||
| 116 | command = command:gsub("-", "_") | 116 | command = command:gsub("-", "_") |
| 117 | if commands[command] then | 117 | if commands[command] then |
| 118 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) | 118 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) |
| 119 | die(debug.traceback("LuaRocks "..program_version | 119 | die(debug.traceback("LuaRocks "..cfg.program_version |
| 120 | .." bug (please report at luarocks-developers@lists.luaforge.net).\n" | 120 | .." bug (please report at luarocks-developers@lists.luaforge.net).\n" |
| 121 | ..err, 2)) | 121 | ..err, 2)) |
| 122 | end) | 122 | end) |
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index f5a3559a..f1e05d92 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -328,7 +328,6 @@ function make_index(repo) | |||
| 328 | return nil, "Cannot access repository at "..repo | 328 | return nil, "Cannot access repository at "..repo |
| 329 | end | 329 | end |
| 330 | local manifest = load_manifest(repo) | 330 | local manifest = load_manifest(repo) |
| 331 | files = fs.find(repo) | ||
| 332 | local out = io.open(dir.path(repo, "index.html"), "w") | 331 | local out = io.open(dir.path(repo, "index.html"), "w") |
| 333 | out:write(index_header) | 332 | out:write(index_header) |
| 334 | for package, version_list in util.sortedpairs(manifest.repository) do | 333 | for package, version_list in util.sortedpairs(manifest.repository) do |
