~ubuntu-branches/ubuntu/vivid/luarocks/vivid-proposed

« back to all changes in this revision

Viewing changes to src/luarocks/add.lua

  • Committer: Package Import Robot
  • Author(s): Enrico Tassi
  • Date: 2014-10-11 15:26:47 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20141011152647-bkfciayfdz6elvv3
Tags: 2.2.0+dfsg-1
* New upstream release
* patch 0001-Fixed-detection-of-Debian-paths removed (applied upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
--- Module implementing the luarocks-admin "add" command.
3
3
-- Adds a rock or rockspec to a rocks server.
4
 
module("luarocks.add", package.seeall)
 
4
--module("luarocks.add", package.seeall)
 
5
local add = {}
 
6
package.loaded["luarocks.add"] = add
5
7
 
6
8
local cfg = require("luarocks.cfg")
7
9
local util = require("luarocks.util")
8
 
local fetch = require("luarocks.fetch")
9
10
local dir = require("luarocks.dir")
10
11
local manif = require("luarocks.manif")
11
12
local index = require("luarocks.index")
12
13
local fs = require("luarocks.fs")
13
14
local cache = require("luarocks.cache")
14
15
 
15
 
help_summary = "Add a rock or rockspec to a rocks server."
16
 
help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}"
17
 
help = [[
 
16
add.help_summary = "Add a rock or rockspec to a rocks server."
 
17
add.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}"
 
18
add.help = [[
18
19
Arguments are local files, which may be rockspecs or rocks.
19
20
The flag --server indicates which server to use.
20
21
If not given, the default server set in the upload_server variable
45
46
      login_url = protocol.."://"..server_path
46
47
   end
47
48
   
48
 
   fs.change_dir(at)
 
49
   local ok, err = fs.change_dir(at)
 
50
   if not ok then return nil, err end
49
51
   
50
52
   local files = {}
51
53
   for i, rockfile in ipairs(rockfiles) do
62
64
      return nil, "No files found"
63
65
   end
64
66
 
65
 
   fs.change_dir(local_cache)
 
67
   local ok, err = fs.change_dir(local_cache)
 
68
   if not ok then return nil, err end
66
69
 
67
70
   util.printout("Updating manifest...")
68
 
   manif.make_manifest(local_cache)
 
71
   manif.make_manifest(local_cache, "one", true)
 
72
   
 
73
   manif.zip_manifests()
 
74
   
69
75
   util.printout("Updating index.html...")
70
76
   index.make_index(local_cache)
71
77
 
76
82
      login_url = login_url .. "/"
77
83
   end
78
84
 
 
85
   table.insert(files, "index.html")
 
86
   table.insert(files, "manifest")
 
87
   for ver in util.lua_versions() do
 
88
      table.insert(files, "manifest-"..ver)
 
89
      table.insert(files, "manifest-"..ver..".zip")
 
90
   end
 
91
 
79
92
   -- TODO abstract away explicit 'curl' call
80
93
 
81
94
   local cmd
82
95
   if protocol == "rsync" then
83
96
      local srv, path = server_path:match("([^/]+)(/.+)")
84
 
      cmd = cfg.variables.RSYNC.." --exclude=.git -Oavz -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/"
 
97
      cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/"
85
98
   elseif upload_server and upload_server.sftp then
86
99
      local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$")
87
 
      cmd = cfg.variables.SCP.." manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2
 
100
      cmd = cfg.variables.SCP.." "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2
88
101
   else
89
 
      cmd = cfg.variables.CURL.." "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url
 
102
      cmd = cfg.variables.CURL.." "..login_info.." -T '{"..table.concat(files, ",").."}' "..login_url
90
103
   end
91
104
 
92
105
   util.printout(cmd)
95
108
   return true
96
109
end
97
110
 
98
 
function run(...)
 
111
function add.run(...)
99
112
   local files = { util.parse_flags(...) }
100
113
   local flags = table.remove(files, 1)
101
114
   if #files < 1 then
102
 
      return nil, "Argument missing, see help."
 
115
      return nil, "Argument missing. "..util.see_help("add", "luarocks-admin")
103
116
   end
104
117
   local server, server_table = cache.get_upload_server(flags["server"])
105
118
   if not server then return nil, server_table end
106
119
   return add_files_to_server(not flags["no-refresh"], files, server, server_table)
107
120
end
108
121
 
 
122
 
 
123
return add