From fa50fc4350ed4c8ff3e354d482e33d51890ac26c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 21 2015 10:12:34 +0000 Subject: Add a method to find the local path of a remote repo --- diff --git a/pagure/__init__.py b/pagure/__init__.py index 977f3eb..ddd978b 100644 --- a/pagure/__init__.py +++ b/pagure/__init__.py @@ -26,6 +26,7 @@ from logging.handlers import SMTPHandler import flask import pygit2 import redis +import werkzeug from pagure.flask_fas_openid import FAS from functools import wraps from sqlalchemy.exc import SQLAlchemyError @@ -400,6 +401,33 @@ def get_repo_path(repo): return repopath +def get_remote_repo_path(remote_git, branch_from): + """ Return the path of the remote git repository corresponding to the + provided information. + """ + repopath = os.path.join( + APP.config['REMOTE_GIT_FOLDER'], + werkzeug.secure_filename('%s_%s' % (remote_git, branch_from)) + ) + + if not os.path.exists(repopath): + try: + pygit2.clone_repository( + remote_git, repopath, checkout_branch=branch_from) + except Exception as err: + LOG.debug(err) + LOG.exception(err) + flask.abort(500, 'Could not clone the remote git repository') + else: + repo = pagure.lib.repo.PagureRepo(repopath) + try: + repo.pull(branch=branch_from) + except pagure.exceptions.PagureException as err: + flask.abort(500, err.message) + + return repopath + + # Import the application import pagure.ui.app import pagure.ui.admin