Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F83546105
git_svn.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, Sep 17, 17:49
Size
4 KB
Mime Type
text/x-python
Expires
Thu, Sep 19, 17:49 (2 d)
Engine
blob
Format
Raw Data
Handle
20855382
Attached To
rPHAPI Phabricator API scripts
git_svn.py
View Options
# -*- coding: utf-8 -*-
import
os
import
re
import
git
import
svn.remote
import
logging
from
...
import
colored
from
...
import
color_code
from
...utils
import
get_password
from
.git
import
RepoGit
__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
RepoGitSvn
(
RepoGit
):
"""This class handles the git svn"""
def
__enter__
(
self
):
super
()
.
__enter__
()
_logger
.
info
(
'Getting repo {0} [{1}] from svn server'
.
format
(
self
.
_in_repo
.
color_name
(
self
.
_name
),
self
.
_url
))
_auth
=
{}
if
(
re
.
match
(
'^https://'
,
self
.
_url
)):
_auth
[
'username'
]
=
self
.
_username
_auth
[
'password'
]
=
get_password
(
self
.
_in_repo
.
backend_name
,
self
.
_in_repo
.
username
,
keyring
=
self
.
_keyring
)
self
.
_svn_client
=
svn
.
remote
.
RemoteClient
(
self
.
_url
,
**
_auth
)
return
self
def
clone
(
self
):
_svn_logs
=
self
.
_svn_client
.
log_default
()
_svn_authors
=
set
()
for
l
in
_svn_logs
:
_svn_authors
.
add
(
l
.
author
)
_authors
=
{}
for
_a
in
_svn_authors
:
_user
=
self
.
_user_db
.
user_by_in_login
(
_a
)
if
_user
is
not
None
:
_authors
[
_a
]
=
_user
_logger
.
debug
(
'Matching author {0} with "{name} <{email}>"'
.
format
(
colored
(
_a
,
color_code
[
'user'
],
attrs
=
[
'bold'
]),
**
_user
))
else
:
_authors
[
_a
]
=
{
'name'
:
_a
,
'email'
:
'{0}@{1}'
.
format
(
_a
,
self
.
_in_repo
.
backend_name
)}
_svn_authors_file
=
os
.
path
.
join
(
self
.
working_dir
,
'getmystuph.authors'
)
with
open
(
_svn_authors_file
,
'w'
)
as
afh
:
afh
.
write
(
'
\n
'
.
join
(
[
'{0} = {name} <{email}>'
.
format
(
l
,
**
a
)
for
l
,
a
in
_authors
.
items
()]))
_list
=
self
.
_svn_client
.
list
()
_branches
=
False
_trunk
=
False
_tags
=
False
for
_file
in
_list
:
_path
=
_file
.
rstrip
(
'/'
)
if
re
.
match
(
r'^branches$'
,
_path
):
_branches
=
True
if
re
.
match
(
r'^trunk$'
,
_path
):
_trunk
=
True
if
re
.
match
(
r'^tags$'
,
_path
):
_tags
=
True
_stdlayout
=
False
if
_branches
and
_tags
and
_trunk
:
_logger
.
debug
(
'Detected svn standard layout for {0}'
.
format
(
self
.
_in_repo
.
color_name
(
self
.
_name
)))
_stdlayout
=
True
_logger
.
info
(
'Cloning repo {0} [{1}] in {2}'
.
format
(
self
.
_in_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'
)):
_git
=
git
.
Git
(
self
.
working_dir
)
_git
.
svn
(
'clone'
,
self
.
_url
,
self
.
working_dir
,
preserve_empty_dirs
=
True
,
authors_file
=
_svn_authors_file
,
stdlayout
=
_stdlayout
)
super
()
.
clone
()
_tag_re
=
re
.
compile
(
'origin/tags/(.*)'
)
_trunk_re
=
re
.
compile
(
'origin/trunk'
)
for
_ref
in
self
.
_repo
.
refs
:
if
type
(
_ref
)
==
git
.
refs
.
remote
.
RemoteReference
:
_match
=
_tag_re
.
match
(
_ref
.
name
)
if
_match
is
not
None
:
_tag_name
=
_match
.
group
(
1
)
_logger
.
debug
(
'Creating tag {0} from branch {1}'
.
format
(
_tag_name
,
_ref
.
name
))
git
.
refs
.
tag
.
TagReference
.
create
(
self
.
_repo
,
_tag_name
,
ref
=
_ref
.
name
)
_logger
.
debug
(
'Deleting remote branch {1}'
.
format
(
_tag_name
,
_ref
.
name
))
git
.
refs
.
remote
.
RemoteReference
.
delete
(
self
.
_repo
,
_ref
)
elif
_trunk_re
.
match
(
_ref
.
name
):
_logger
.
debug
(
'Deleting trunk branch'
)
git
.
refs
.
remote
.
RemoteReference
.
delete
(
self
.
_repo
,
_ref
)
Event Timeline
Log In to Comment