This is a Python script "gmkrepo" that I used a year ago to do this. Haven't 
tried running it recently to make sure it still works though.

Reid

- - -
#!/usr/bin/env python
"""
        gmkrepo
                A script to create (and delete) Gitorious repositories on the 
command line.
                This is especially useful if you are writing scripts to bring 
over old subversion
                repositories to git, and would like to make it an automated 
batch operation.
                Being able to delete (in case it's not your first try) and 
create repositories
                comes in very, very handy in such scripts.
        
        Reid Ellis <[email protected]>
"""
import sys
import os
import re
from getopt import *

options = {
    "user"              : "[email protected]",
        "password"      : "notMyPassword",
        "project"       : "defaultProject",
        "server"        : "gitorious.org",
        "port"          : 80,
        "delete"        : False,
}

def usage():
    print """
Usage: %s [-u user] [-p password] [-s server] [-P port] [-j project] [-d] repo 
[repo..]
        --user email         The email address of the user on the gitorious 
server
        --password pass      The password of the user
        --server serv        The gitorious server with which to connect 
(default: gitorious.org)
        --project proj       The project under which the repo will be created 
[or deleted]
        --port num           Port number to use when connecting to http server 
(default: 80)
        --delete             Delete the repo instead of creating it
        repo [repo..]        The name of the repository[ies] to create
""" % os.path.basename(sys.argv[0])
    sys.exit(0)

try:
        opts, args = getopt(sys.argv[1:], "u:p:P:s:j:d", ["user=", "password=", 
"port=", "server=", "project=", "delete"])
except GetoptError:
        usage()
        sys.exit(2)

for opt, arg in opts:
        if opt in ("-u", "--user"):
                options["user"] = arg
        elif opt in ("-p", "--password"):
                options["password"] = arg
        elif opt in ("-P", "--port"):
                options["port"] = int(arg)
        elif opt in ("-s", "--server"):
                options["server"] = arg
        elif opt in ("-j", "--project"):
                options["project"] = arg
        elif opt in ("-d", "--delete"):
                options["delete"] = True

# Handle non-standard port # by appending it to the server string
if options["port"] != 80:
        options["server"] = "%s:%d" % (options["server"], options["port"])

def run(cmd):
        disp = cmd
        disp = re.sub(r'\s\s+', ' ', cmd)
        disp = re.sub(r'\s*-', "\n\t-", disp)
        disp = re.sub(r'^\s*', '    ', disp)
        print
        print disp
        print
        status = os.system(cmd)
        # alas, a bad request does *not* return a non-zero exit status
        if status: print "command returned %d" % status

def delete_repo(repo, opts):
        "Delete a repo using the options specified in opts"
        print "Deleting \"%s\" on \"%s\"" % (repo, options["server"])
        opts["repo"] = repo
        cmd = """
                curl \
                -H "Accept: text/xml" \
                -d "repository[name]=%(repo)s" \
                -d "_method=delete" \
                -u "%(user)s:%(password)s" \
                "http://%(server)s/%(project)s/%(repo)s" \
                """ % opts
        run(cmd)

def make_repo(repo, opts):
        "Create a repo using the options specified in opts"
        print "Creating \"%s\" on \"%s\"" % (repo, options["server"])
        opts["repo"] = repo
        cmd = """
                curl \
                -H "Accept: text/xml" \
                -d "repository[name]=%(repo)s" \
                -d "repository[description]=%(repo)s" \
                -d "repository[merge_requests_enabled]=1" \
                -u "%(user)s:%(password)s" \
                "http://%(server)s/%(project)s/repositories" \
                """ % opts
        run(cmd)

if len(args) < 1:
        usage()
        raise SystemExit()

if(options["delete"]):
        [delete_repo(repo, options) for repo in args]
else:
        [make_repo(repo, options) for repo in args]

- - -
On 2012-02-21, at 16:38 , Dub wrote:
> Hello,
> 
> I am trying to programatically create a repo inside a project. I found
> a thread mentioning CURL and I tried paying around with it to no luck,
> I assume the authentication system has changed since then, as I keep
> getting auth errors (Invalid Token...).
> 
> Any idea of how I could do this? My final test was
> 
> curl -X put -H "Accept: text/xml" -d
> "repository[name]=test&repository[description]=Test&repository[merge_requests_enabled]=1"
> -u [email protected]:password -k 
> https://192.168.1.106/project/repositories/new
> 
> -- 
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]

Reply via email to