Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60990885
git.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
Fri, May 3, 20:21
Size
1 KB
Mime Type
text/x-python
Expires
Sun, May 5, 20:21 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17450098
Attached To
rPHAPI Phabricator API scripts
git.py
View Options
# -*- 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
Log In to Comment