Beispiel #1
0
def delete_app(id):
    # retrieves both the directory to used as the
    # base for the sun files and the directory used
    # to store the repositories
    suns_folder = util.get_suns_folder()
    repos_folder = util.get_repos_folder()

    # retrieves the current mongo database and removes the
    # app entry contained in it
    db = quorum.get_mongo_db()
    db.apps.remove({"id" : id})

    # retrieves the (complete) repository path for the current app
    # and removes the repository directory
    repo_path = os.path.join(repos_folder, "%s.git" % id)
    shutil.rmtree(repo_path)

    # retrieves the (complete) sun path for the current app and
    # removes the sun file from the file system
    sun_path = os.path.join(suns_folder, "%s.sun" % id)
    if os.path.exists(sun_path): os.remove(sun_path)

    return flask.redirect(
        flask.url_for("list_app")
    )
Beispiel #2
0
def create_app():
    # runs the validation process on the various arguments
    # provided to the app
    errors, app = quorum.validate(util.validate_app_new)
    if errors:
        return flask.render_template(
            "app/new.html.tpl",
            link = "new_app",
            app = app,
            errors = errors
        )

    # retrieves the name and the description attributes of
    # the app to be used in the creation
    name = quorum.get_field("name", None)
    description = quorum.get_field("description", None)

    # retrieves the current configuration structure to be able
    # to retrieve a series of configuration attributes
    config = util.get_config()
    hostname = config.get("hostname", "repo.tiberium")
    domain_suffix = config.get("domain_suffix", "tibapp")
    user = config.get("user", "git")
    group = config.get("group", "git")

    # retrieves the directory used to store the repository
    # for the various applications
    repos_folder = util.get_repos_folder()

    # creates the map containing the complete description of the
    # app from the provided parameters and configuration
    app = dict(
        id = name,
        name = name,
        description = description,
        domain = "%s.%s" % (name, domain_suffix),
        schema = "http",
        git = "git@%s:%s.git" % (hostname, name),
        env = {},
        domains = []
    )

    # retrieves the database and then saves the app in the
    # correct collection
    db = quorum.get_mongo_db()
    db.apps.save(app)

    # retrieves the (complete) repository path for the current app
    # and creates the repository in it (uses tiberium)
    repo_path = os.path.join(repos_folder, "%s.git" % name)
    tiberium.create_repo(repo_path)

    # retrieves the "proper" path to the hooks in the application
    # to copy and change their permissions
    hooks_path = os.path.join(repo_path, ".git", "hooks")

    # lists the names of the various hook files and then copies
    # each of them to the hooks folder of the application
    names = os.listdir(util.HOOKS_FOLDER)
    for _name in names:
        file_path = os.path.join(util.HOOKS_FOLDER, _name)
        target_path = os.path.join(hooks_path, _name)
        shutil.copy(file_path, target_path)
        os.chmod(target_path, 0x1ed)

    # changes the owner and group of the repository path (all the
    # applications require the same user)
    util.chown_r(repo_path, user, group)

    return flask.redirect(
        flask.url_for("show_app", id = name)
    )