From 4cd417b8abaccea3bd08bd50b8db2af9b63371f4 Mon Sep 17 00:00:00 2001 From: hisham Date: Thu, 18 Jun 2009 15:39:49 +0000 Subject: added preliminary support for 'luarocks-admin add' git-svn-id: http://luarocks.org/svn/luarocks/trunk@28 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- src/bin/luarocks-admin | 1 + src/luarocks/add.lua | 91 +++++++++++++++++++++++++++++++++++++++++++ src/luarocks/command_line.lua | 2 +- src/luarocks/manif.lua | 1 - 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/luarocks/add.lua (limited to 'src') 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 = { commands.help = require("luarocks.help") commands.make_manifest = require("luarocks.make_manifest") +commands.add = require("luarocks.add") 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 @@ + +--- Module implementing the luarocks-admin "add" command. +-- Adds a rock or rockspec to a rocks server. +module("luarocks.add", package.seeall) + +local cfg = require("luarocks.cfg") +local util = require("luarocks.util") +local fetch = require("luarocks.fetch") +local dir = require("luarocks.dir") +local manif = require("luarocks.manif") +local fs = require("luarocks.fs") + +help_summary = "Add a rock or rockpec to a rocks server." +help_arguments = "[--to=] {|]}" +help = [[ +Argument may be a local rockspec or rock file. +The flag --to indicates which server to use. +If not given, the default server set in the upload_server variable +from the configuration file is used instead. +]] + +local function add_file_to_server(rockfile, server) + local protocol, server_path = dir.split_url(server) + local user = cfg.upload_user + local password = cfg.upload_password + if server_path:match("@") then + local credentials + credentials, server_path = server_path:match("([^@]*)@(.*)") + if credentials:match(":") then + user, password = credentials:match("([^:]*):(.*)") + else + user = credentials + end + end + if not fs.exists(rockfile) then + return nil, "Could not find "..rockfile + end + local rockfile = fs.absolute_name(rockfile) + local local_cache + if cfg.local_cache then + local_cache = cfg.local_cache .. "/" .. server_path + end + local tmp_cache = false + if not local_cache then + local_cache = fs.make_temp_dir("local_cache") + tmp_cache = true + end + local ok = fs.make_dir(local_cache) + if not ok then + return nil, "Failed creating local cache dir." + end + fs.change_dir(local_cache) + print("Refreshing cache "..local_cache.."...") + + local login_info = "" + if user then login_info = " --user="..user end + if password then login_info = login_info .. " --password="..password end + + fs.execute("wget -q -m -nd "..protocol.."://"..server_path..login_info) + print("Copying file...") + fs.copy(rockfile, local_cache) + print("Updating manifest and index.html...") + manif.make_manifest(local_cache) + manif.make_index(local_cache) + + local login_info = "" + if user then login_info = " -u "..user end + if password then login_info = login_info..":"..password end + if not server_path:match("/$") then + server_path = server_path .. "/" + end + fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..protocol.."://"..server_path) + return true +end + +function run(...) + local flags, file = util.parse_flags(...) + if type(file) ~= "string" then + return nil, "Argument missing, see help." + end + local server = flags["to"] + if not server then server = cfg.upload_server end + if not server then + return nil, "No server specified with --to and no default configured with upload_server." + end + if cfg.upload_aliases then + server = cfg.upload_aliases[server] or server + end + return add_file_to_server(file, server) +end + 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(...) command = command:gsub("-", "_") if commands[command] then local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) - die(debug.traceback("LuaRocks "..program_version + die(debug.traceback("LuaRocks "..cfg.program_version .." bug (please report at luarocks-developers@lists.luaforge.net).\n" ..err, 2)) 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) return nil, "Cannot access repository at "..repo end local manifest = load_manifest(repo) - files = fs.find(repo) local out = io.open(dir.path(repo, "index.html"), "w") out:write(index_header) for package, version_list in util.sortedpairs(manifest.repository) do -- cgit v1.2.3-55-g6feb