Page MenuHomec4science

__init__.py
No OneTemporary

File Metadata

Created
Fri, Jun 7, 01:00

__init__.py

import logging
import re
from .. import export
from .. import colored
from .. import color_code
__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__)
__repo_backends = {}
def _get_class(_type, backend):
if not backend or backend not in __repo_backends:
_logger.error("{0} not a known backend".format(backend))
raise TypeError("{0} not a known backend".format(backend))
if _type not in __repo_backends[backend]:
_logger.error(("{0} is not a known type for the " +
"backend {1}").format(_type, backend))
raise TypeError(("{0} is not a known type for the " +
"backend {1}").format(_type, backend))
module_info = __repo_backends[backend][_type]
_logger.debug("Importing {0} from module {1}".format(
module_info['class'], module_info['module']))
module = __import__('getmystuph.' + module_info['module'],
globals(),
locals(),
[module_info['class']], 0)
_class = getattr(module, module_info['class'])
return _class
def _register_backend(name, backends):
__repo_backends[name] = backends
@export
def color_phid(phid):
_color = {'PROJ': color_code['group'],
'USER': color_code['user'],
'REPO': color_code['repo'],
'PLCY': 'yellow'}
regex = re.compile(r'PHID-([A-Z]{4})-.+')
match = regex.match(phid)
if match:
return colored(phid, _color[match.group(1)])
else:
return colored(phid, attrs=['bold'])
_register_backend(
'c4science', {
'git': {'module': 'backends.c4science.repo',
'class': 'C4ScienceRepo'},
'svn': {'module': 'backends.c4science.repo',
'class': 'C4ScienceRepo'},
'directory': {'module': 'backends.c4science.directory',
'class': 'C4ScienceDirectory'}
})
_register_backend(
'epfl', {
'git': {'module': 'backends.epfl.repo',
'class': 'RepoGitEPFL'},
'svn': {'module': 'backends.epfl.repo',
'class': 'RepoSvnEPFL'},
'directory': {'module': 'backends.epfl.directory',
'class': 'EPFLDirectory'}
}
)
_register_backend(
'phabricator', {
'git': {'module': 'backends.repos.phabricator',
'class': 'PhabRepo'},
'svn': {'module': 'backends.repos.phabricator',
'class': 'PhabRepo'},
'directory': {'module': 'backends.directories.phabricator',
'class': 'PhabDirectory'}
})

Event Timeline