Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88618340
__init__.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Oct 19, 19:06
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Oct 21, 19:06 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21776173
Attached To
rPHAPI Phabricator API scripts
__init__.py
View Options
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
Log In to Comment