Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
d5e64669
Commit
d5e64669
authored
Feb 19, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate some code for importing projects
parent
807b1ee0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
17 deletions
+32
-17
weblate/trans/management/commands/import_project.py
weblate/trans/management/commands/import_project.py
+32
-17
No files found.
weblate/trans/management/commands/import_project.py
View file @
d5e64669
...
...
@@ -47,6 +47,35 @@ class Command(BaseCommand):
match
=
match
.
replace
(
'.*.*'
,
'(.*.*)'
)
return
re
.
compile
(
match
)
def
checkout_tmp
(
self
,
project
,
repo
,
branch
):
'''
Checkouts project to temporary location.
'''
# Create temporary working dir
workdir
=
tempfile
.
mkdtemp
(
dir
=
project
.
get_path
())
os
.
chmod
(
workdir
,
0755
)
# Initialize git repository
logger
.
info
(
'Initializing git repository...'
)
gitrepo
=
git
.
Repo
.
init
(
workdir
)
gitrepo
.
git
.
remote
(
'add'
,
'origin'
,
repo
)
logger
.
info
(
'Fetching remote git repository...'
)
gitrepo
.
git
.
remote
(
'update'
,
'origin'
)
gitrepo
.
git
.
branch
(
'--track'
,
branch
,
'origin/%s'
%
branch
)
logger
.
info
(
'Updating working copy in git repository...'
)
gitrepo
.
git
.
checkout
(
branch
)
return
workdir
def
get_matching_files
(
self
,
workdir
,
filemask
):
'''
Returns relative path of matched files.
'''
matches
=
glob
(
os
.
path
.
join
(
workdir
,
filemask
))
return
[
f
.
replace
(
workdir
,
''
).
strip
(
'/'
)
for
f
in
matches
]
def
handle
(
self
,
*
args
,
**
options
):
'''
Automatic import of project.
...
...
@@ -75,25 +104,11 @@ class Command(BaseCommand):
'for subproject part of the match!'
)
# Create temporary working dir
workdir
=
tempfile
.
mkdtemp
(
dir
=
project
.
get_path
())
os
.
chmod
(
workdir
,
0755
)
# Initialize git repository
logger
.
info
(
'Initializing git repository...'
)
gitrepo
=
git
.
Repo
.
init
(
workdir
)
gitrepo
.
git
.
remote
(
'add'
,
'origin'
,
repo
)
logger
.
info
(
'Fetching remote git repository...'
)
gitrepo
.
git
.
remote
(
'update'
,
'origin'
)
gitrepo
.
git
.
branch
(
'--track'
,
branch
,
'origin/%s'
%
branch
)
logger
.
info
(
'Updating working copy in git repository...'
)
gitrepo
.
git
.
checkout
(
branch
)
# Checkout git to temporary dir
workdir
=
self
.
checkout_tmp
(
project
,
repo
,
branch
)
# Find matching files
matches
=
glob
(
os
.
path
.
join
(
workdir
,
filemask
))
matches
=
[
f
.
replace
(
workdir
,
''
).
strip
(
'/'
)
for
f
in
matches
]
matches
=
self
.
get_matching_files
(
workdir
,
filemask
)
logger
.
info
(
'Found %d matching files'
,
len
(
matches
))
# Parse subproject names out of them
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment