Page MenuHomec4science

git.py
No OneTemporary

File Metadata

Created
Fri, May 3, 20:21
# -*- coding: utf-8 -*-
import os
import git
import logging
from .. import colored
from ..repo import Repo, RepoQuery
__author__ = "Nicolas Richart"
__copyright__ = "Copyright (C) 2016, EPFL (Ecole Polytechnique Fédérale " \
"de Lausanne) - SCITAS (Scientific IT and Application " \
"Support)"
__credits__ = ["Nicolas Richart"]
__license__ = "BSD"
__version__ = "0.1"
__maintainer__ = "Nicolas Richart"
__email__ = "nicolas.richart@epfl.ch"
_logger = logging.getLogger(__name__)
class RepoGit(RepoQuery):
"""This class handles the common part on git repositories, cloning,
retreiving tags/branches doing subtrees
"""
def __enter__(self):
super(RepoGit, self).__enter__()
_logger.info('Cloning repo {0} [{1}] in {2}'.format(
Repo.color_name(self._name),
self._url,
colored(self.working_dir, attrs=['bold'])))
if not os.path.isdir(os.path.join(self.working_dir, '.git')):
self._repo = git.Repo.clone_from(self._url,
self.working_dir)
else:
_logger.warning('Repo {0} is already cloned in {1}'.format(
Repo.color_name(self._name),
colored(self.working_dir, attrs=['bold'])))
self._repo = git.Repo(self.working_dir)
def list_tags(self):
_tags = []
for ref in self._repo.refs:
if type(ref) == git.refs.tag.TagReference:
_tags.append(ref.name)
return _tags
def list_branches(self):
_refs = []
for ref in self._repo.refs:
if type(ref) == git.refs.remote.RemoteReference and\
ref.name != 'origin/HEAD':
_refs.append(ref.name)
return _refs

Event Timeline