コード例 #1
0
ファイル: commands.py プロジェクト: sekrett/gitosis-ng
def set_repo(config, user, args):
    allowed_keys = ['url', 'owner', 'description']

    try:
        (repo, remain) = args.split(None,1)
        (key, val) = remain.split(None,1) 
    except:
        return("Usage: set-repo repo key value\n")

    # strip '.git' from repo
    if repo.endswith('.git'):
        repo = repo[:-4]

    section = "repo " + repo
    if not config.has_section(section):
        return("repository '%s' does not exist.\n" % repo)

    # check that key is allowed.
    if not key in allowed_keys:
        return("key '%s' cannot be set.  Available keys: %s\n" % (key, ', '.join(allowed_keys)))

    config.set(section, key, val)

    try:
        update_config_file(config, user, repo)
    except Exception, e:
        return "Failed to update repository (%s): %s\n" % (repo, e)
コード例 #2
0
ファイル: commands.py プロジェクト: sekrett/gitosis-ng
def add_repo(config, user, args):
    if len(args) == 0:
        return("Usage: add-repo repo-name\n")
    
    # strip '.git' from repo
    repo = args
    if repo.endswith('.git'):
        repo = repo[:-4]

    # no whitespace in repo names, please
    if re.search("\s", repo):
        return("Invalid repo name ('%s'), no whitespace allowed\n" % repo)

    section = "repo " + repo
    if config.has_section(section):
        return("repository '%s' already exists\n" % repo)

    config.add_section(section)
    config.set(section, 'url', "")
    config.set(section, 'owner', user)
    config.set(section, 'description', "")
    config.set(section, 'writable', user)

    try:
        update_config_file(config, user, repo)
    except Exception, e:
        return "Failed to create repository (%s): %s\n" % (repo, e)