def get_repo(path=None, alias=None, create=False): """ Returns ``Repository`` object of type linked with given ``alias`` at the specified ``path``. If ``alias`` is not given it will try to guess it using get_scm method """ if create: if not (path or alias): raise TypeError( "If create is specified, we need path and scm type") return get_backend(alias)(path, create=True) if path is None: path = abspath(os.path.curdir) try: scm, path = get_scm(path, search_up=True) path = abspath(path) alias = scm except VCSError: raise VCSError("No scm found at %s" % path) if alias is None: alias = get_scm(path)[0] backend = get_backend(alias) repo = backend(path, create=create) return repo
def is_valid_repo(repo_name, base_path): """ Returns True if given path is a valid repository False otherwise :param repo_name: :param base_path: :return True: if given path is a valid repository """ full_path = os.path.join(base_path, repo_name) try: get_scm(full_path) return True except VCSError: return False
def __get_instance(self): repo_full_path = self.repo_full_path try: alias = get_scm(repo_full_path)[0] log.debug('Creating instance of %s repository', alias) backend = get_backend(alias) except VCSError: log.error(traceback.format_exc()) log.error('Perhaps this repository is in db and not in ' 'filesystem run rescan repositories with ' '"destroy old data " option from admin panel') return if alias == 'hg': repo = backend(safe_str(repo_full_path), create=False, baseui=self._ui) #skip hidden web repository if repo._get_hidden(): return else: repo = backend(repo_full_path, create=False) return repo
def __init__(self, stdout=None, stderr=None, repo=None): if repo is None: curdir = abspath(os.curdir) try: scm, path = get_scm(curdir, search_recursively=True) self.repo = vcs.get_repo(path, scm) except VCSError: raise CommandError('Repository not found') else: self.repo = repo super(RepositoryCommand, self).__init__(stdout, stderr)
def get_repo(path, alias=None, create=False): """ Returns ``Repository`` object of type linked with given ``alias`` at the specified ``path``. If ``alias`` is not given it will try to guess it using get_scm method """ path = abspath(path) if alias is None: alias = get_scm(path)[0] backend = get_backend(alias) repo = backend(path, create=create) return repo
def get_repo(path=None, alias=None, create=False): """ Returns ``Repository`` object of type linked with given ``alias`` at the specified ``path``. If ``alias`` is not given it will try to guess it using get_scm method """ if create: if not (path or alias): raise TypeError("If create is specified, we need path and scm type") return get_backend(alias)(path, create=True) if path is None: path = abspath(os.path.curdir) try: scm, path = get_scm(path, search_recursively=True) path = abspath(path) alias = scm except VCSError: raise VCSError("No scm found at %s" % path) if alias is None: alias = get_scm(path)[0] backend = get_backend(alias) repo = backend(path, create=create) return repo
def __init__(self, stdout=None, stderr=None, repo=None): """ Accepts extra argument: :param repo: repository instance. If not given, repository would be calculated based on current directory. """ if repo is None: curdir = abspath(os.curdir) try: scm, path = get_scm(curdir, search_up=True) self.repo = vcs.get_repo(path, scm) except VCSError: raise CommandError('Repository not found') else: self.repo = repo super(RepositoryCommand, self).__init__(stdout, stderr)
def __init__(self, stdout=None, stderr=None, repo=None): """ Accepts extra argument: :param repo: repository instance. If not given, repository would be calculated based on current directory. """ if repo is None: curdir = abspath(os.curdir) try: scm, path = get_scm(curdir, search_recursively=True) self.repo = vcs.get_repo(path, scm) except VCSError: raise CommandError('Repository not found') else: self.repo = repo super(RepositoryCommand, self).__init__(stdout, stderr)
def get_current_revision(): """Returns tuple of (number, id) from repository containing this package or None if repository could not be found. """ try: from vcs import get_repo from vcs.utils.helpers import get_scm from vcs.exceptions import RepositoryError, VCSError repopath = os.path.join(os.path.dirname(__file__), '..', '..') scm = get_scm(repopath)[0] repo = get_repo(path=repopath, alias=scm) tip = repo.get_changeset() return (tip.revision, tip.short_id) except (ImportError, RepositoryError, VCSError), err: logging.debug("Cannot retrieve rhodecode's revision. Original error " "was: %s" % err) return None
def _get_repos(p): if not os.access(p, os.W_OK): return for dirpath in os.listdir(p): if os.path.isfile(os.path.join(p, dirpath)): continue cur_path = os.path.join(p, dirpath) try: scm_info = get_scm(cur_path) yield scm_info[1].split(path)[-1].lstrip(os.sep), scm_info except VCSError: if not recursive: continue #check if this dir containts other repos for recursive scan rec_path = os.path.join(p, dirpath) if os.path.isdir(rec_path): for inner_scm in _get_repos(rec_path): yield inner_scm
def get_current_revision(quiet=False): """ Returns tuple of (number, id) from repository containing this package or None if repository could not be found. :param quiet: prints error for fetching revision if True """ try: from vcs import get_repo from vcs.utils.helpers import get_scm repopath = os.path.join(os.path.dirname(__file__), '..', '..') scm = get_scm(repopath)[0] repo = get_repo(path=repopath, alias=scm) tip = repo.get_changeset() return (tip.revision, tip.short_id) except Exception, err: if not quiet: print ("Cannot retrieve rhodecode's revision. Original error " "was: %s" % err) return None
def get_current_revision(): """ Returns tuple of (number, id) from repository containing this package or None if repository could not be found. """ try: import vcs except ImportError: return None try: from vcs import get_repo from vcs.utils.helpers import get_scm from vcs.exceptions import RepositoryError, VCSError repopath = os.path.join(os.path.dirname(__file__), '..', '..') scm = get_scm(repopath)[0] repo = get_repo(path=repopath, alias=scm) tip = repo.get_changeset() return (tip.revision, tip.id) except (ImportError, RepositoryError, VCSError), err: logging.debug("Cannot retrieve projector's revision. Original error " "was: %s" % err) return None
def test_get_scm(self): self.assertEqual(('hg', TEST_HG_REPO), get_scm(TEST_HG_REPO)) self.assertEqual(('git', TEST_GIT_REPO), get_scm(TEST_GIT_REPO))