Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F72657570
git_repo.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
Tue, Jul 16, 10:30
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Jul 18, 10:30 (2 d)
Engine
blob
Format
Raw Data
Handle
19085993
Attached To
rPHAPI Phabricator API scripts
git_repo.py
View Options
# -*- coding: utf-8 -*-
from
..
import
export
from
..repo
import
Repo
from
.tequila
import
TequilaGet
from
bs4
import
BeautifulSoup
import
copy
import
re
__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"
@export
class
GitRepo
(
Repo
):
'''
Description of a repostitory on git.epfl.ch
'''
__ROOT_URL
=
'https://git.epfl.ch/polyrepo/private'
__LIST_REPOS
=
'{root}/repository/my.go'
__MANAGE_REPO
=
'{root}/repository/manage.go?id={id}'
__PERMISSION
=
'{root}/objectRole/list.go?objectId={id}'
__REPO_REGEX
=
'/polyrepo/private/repository/manage\.go\?id=([0-9]+)'
def
__init__
(
self
,
repo_name
,
repo_id
=
None
,
tequila_ctx
=
None
,
*
args
,
**
kwargs
):
super
(
GitRepo
,
self
)
.
__init__
(
repo_name
,
*
args
,
**
kwargs
)
option
=
copy
.
copy
(
kwargs
)
_password
=
option
.
pop
(
'password'
,
None
)
if
tequila_ctx
is
None
:
self
.
_tequila
=
TequilaGet
(
self
.
__LIST_REPOS
.
format
(
root
=
self
.
__ROOT_URL
),
username
=
self
.
_username
,
password
=
_password
)
else
:
self
.
_tequila
=
tequila_ctx
if
repo_id
is
None
:
(
repo
,
info
)
=
self
.
list_repositories
(
tequila_ctx
=
self
.
_tequila
)
if
repo_name
in
repo
:
self
.
_id
=
info
[
repo_name
][
'id'
]
else
:
raise
RuntimeError
(
'The repo {0} was not found in your list
\
of repositories'
.
format
(
repo_name
))
else
:
self
.
_id
=
repo_id
def
get_permissions
(
self
):
'''Get the group and user permissions on the repository'''
_html_resp
=
self
.
_tequila
.
get
(
self
.
__PERMISSION
.
format
(
root
=
self
.
__ROOT_URL
,
id
=
self
.
_id
))
_html_soup
=
BeautifulSoup
(
_html_resp
.
text
,
'html.parser'
)
_group_regex
=
re
.
compile
(
'([US][0-9]+)'
)
_list_soup
=
_html_soup
.
find
(
'form'
,
{
'name'
:
'lister'
})
.
find_all
(
'td'
,
{
'align'
:
'right'
})
for
_td
in
_list_soup
:
_ug_id
=
_td
.
text
_is_group
=
_group_regex
.
match
(
_ug_id
)
if
_is_group
:
print
(
'group: {0}'
.
format
(
_ug_id
))
else
:
print
(
'user: {0}'
.
format
(
_ug_id
))
@classmethod
def
list_repositories
(
cls
,
username
=
None
,
password
=
None
,
tequila_ctx
=
None
):
_repos
=
[]
_extra_info
=
{}
if
tequila_ctx
is
None
:
_tequila
=
TequilaGet
(
cls
.
__LIST_REPOS
.
format
(
root
=
cls
.
__ROOT_URL
),
username
=
username
,
password
=
password
)
else
:
_tequila
=
tequila_ctx
_html_resp
=
_tequila
.
get
(
cls
.
__LIST_REPOS
.
format
(
root
=
cls
.
__ROOT_URL
)
)
_html_soup
=
BeautifulSoup
(
_html_resp
.
text
,
'html.parser'
)
_list_soup
=
_html_soup
.
find
(
'tbody'
)
_id_regex
=
re
.
compile
(
cls
.
__REPO_REGEX
)
for
_link
in
_list_soup
.
find_all
(
'a'
):
_repo
=
_link
.
get_text
()
_repos
.
append
(
_repo
)
_repo_link
=
_link
.
get
(
'href'
)
_match
=
_id_regex
.
match
(
_repo_link
)
if
_match
:
_id
=
_match
.
group
(
1
)
_extra_info
[
_repo
]
=
{
'id'
:
_id
}
return
(
_repos
,
_extra_info
)
Event Timeline
Log In to Comment