Esempio n. 1
0
    def post(self):
        project_req = flask.request.json
        print project_req

        try:
            project_name = project_req['name']
            fetch_url = project_req['fetch_url']
            branchlink_url = project_req.get('branchlink_url', '')
            commitlink_url = project_req.get('commitlink_url', '')

        except KeyError as e:
            flask.abort(400, str(e))

        logger.debug('Creating project "%s" -> %s', project_name, fetch_url)

        project = model.Project(name=project_name,
                                fetch_url=fetch_url,
                                branchlink_url=branchlink_url,
                                commitlink_url=commitlink_url)

        db.session().add(project)

        try:
            db.session().commit()
        except IntegrityError:
            db.session().rollback();
            return {'error': 'A project named "%s" already exists.' % project_name}

        logger.info('Updating cache for project "%s" (%d)...', project.name, project.project_id)
        git.update_project_cache(project.project_id, project.fetch_url)

        return {'project_id': project.project_id}
Esempio n. 2
0
def init_projects():
    import api.db as db
    import git
    import model

    for project in db.session().query(model.Project).all():
        logger.info('Updating cache for project "%s" (%d)...', project.name, project.project_id)
        git.update_project_cache(project.project_id, project.fetch_url)