On Tue, Oct 5, 2010 at 10:49 PM, Hisham <[email protected]> wrote:
> That's what I would do if I wanted to implement that (or write a
> script that did the sequence of commands)...

Well, a quick-and-dirty implementation looks like this - not much
detailed error checking, but it works. Creates a fake rockspec with
the desired dependencies and makes it.

The package name 'fake' is not right, someone may already be thinking
of assigning a good meaning to it ;)  Besides, we should also remove
the fake package afterwards, to be tidy.

$ sudo luarocks installa config date densearrays

---- BEGIN ----
module("installa", package.seeall)  -- make it "luarocks.installa" if
you put it together with the other commands

local fs = require("luarocks.fs")
local make = require("luarocks.make")
local util = require("luarocks.util")

local tmpfolder = fs.make_temp_dir('fake')
local fake_rockspec_name = tmpfolder..'/fake-1.0-1.rockspec'

local fake_template = [[
package = 'fake' -- doesn't do anything in itself!
version = '1.0-1'
source = {
    url = 'http://fake'
}

dependencies = {
    %s
}
build = {
    type = 'builtin',
    modules = { }
}
]]

help_summary = "Install multiple rocks."

help_arguments = "rock1 rock2 ..."

help = [[
Arguments must be the names of remote packages, as in install.
]]

local function quote_args(list)
    local res = {}
    for i,a in ipairs(list) do
        res[i] = fs.Q(a)
    end
    return table.concat(res,',')
end

local function writefile(name,contents)
    local f,err = io.open(name,'w')
    if not f then return nil,err end
    f:write(contents)
    f:close()
    return true
end

function run(...)
    local args = {util.parse_flags(...)}
    local flags = table.remove(args,1)

    if #args == 0 then return nil, "must provide packages" end

    args_line = quote_args(args)

    local res, err =
writefile(fake_rockspec_name,fake_template:format(args_line))
    if not res then return nil,err end

    fs.change_dir (tmpfolder)
    make.run(fake_rockspec_name)
    fs.pop_dir()
    fs.delete(tmpfolder)
    return true
end

--- END ---

_______________________________________________
Luarocks-developers mailing list
[email protected]
http://lists.luaforge.net/cgi-bin/mailman/listinfo/luarocks-developers

Reply via email to