Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)

        def create_repo(name, owner_id):
    (name, path) = format_name(name)

    # TODO: a synchronization problem exists here when:
    #    - the repository already exists, but doesn't appear in the DB
    #    - the repository is missing, but appears in the DB
    # If one of these conditions exists, what do we do?
    # For now:
    #    - if it exists in FS but not DB, populate DB
    #    - if it exists in DB but not FS, initialize repo in FS
    # Basically, we naively chug on through and initialize all uninitialized
    # pieces without throwing exceptions.  I'm not sure this is the best
    # policy, as desyncs here may indicate further consistency issues, and
    # ignoring them may hamper debugging.

    # error out if the repository already exists in both FS and DB
    repo = get_repo(name)
    if os.path.isdir(path) and repo:
        raise KeyError("Repository {0} already exists.".format(name))

    # if no FS directory exists, initialize the repo /w subprocess'ed git
    if not os.path.isdir(path):
        # TODO: can we use a native Python library here instead of subprocess?
        # TODO: do we need to insure git is installed properly somehow?
        import subprocess
        cmd = ['git', 'init', '--bare', path]
        proc = subprocess.Popen(
        (stdout, stderr) = proc.communicate()
        if proc.returncode != 0:
            raise Exception("git init {0} failed: {1}".format(path, stderr))

    # insert repository row
    s = repos.insert().values(
    result = db.execute(s)
    repo_id = result.inserted_primary_key[0]

    # insert default owner ACL
    # TODO: Shouldn't this be in the same transaction as above?!
    #       Theoretically a failure here could be unrecoverable.
    s = repo_acls.insert().values(
    result = db.execute(s)

    # make sure all hooks are up-to-date

    return repo_id

src/g/i/gitzebo-0.0.10/gitzebo/flask_app.py   gitzebo(Download)
    if not name or len(name) <= 3:
        raise Exception("Repository name is too short.")
    id = repos.create_repo(name=name, owner_id=request.user['user_id'])
    return redirect(url_for('repo_details', id=id))