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
5cd290a0
Commit
5cd290a0
authored
Feb 19, 2013
by
Stefano Rivera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Customizable transformation of the filemask to sub-project name
parent
c7eaaa67
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
12 deletions
+21
-12
weblate/trans/management/commands/import_project.py
weblate/trans/management/commands/import_project.py
+21
-12
No files found.
weblate/trans/management/commands/import_project.py
View file @
5cd290a0
...
...
@@ -25,6 +25,7 @@ from django.template.defaultfilters import slugify
from
weblate.trans.models
import
SubProject
,
Project
from
weblate.trans.util
import
is_repo_link
from
glob
import
glob
from
optparse
import
make_option
import
tempfile
import
git
import
logging
...
...
@@ -39,6 +40,12 @@ logger = logging.getLogger('weblate')
class
Command
(
BaseCommand
):
help
=
'imports projects with more subprojects'
args
=
'<project> <gitrepo> <branch> <filemask>'
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--name-template'
,
default
=
'%s'
,
help
=
'Python formatting string, transforming the filemask '
'match to a project name'
),
)
def
get_name
(
self
,
maskre
,
path
):
matches
=
maskre
.
match
(
path
)
...
...
@@ -132,14 +139,15 @@ class Command(BaseCommand):
except
SubProject
.
DoesNotExist
:
raise
CommandError
(
'SubProject %s does not exist, '
'you need to create it first!'
%
repo
)
names
=
self
.
get_matching_subprojects
(
sub_project
.
get_path
(),
filemask
)
else
:
names
,
sharedrepo
=
self
.
import_initial
(
project
,
repo
,
branch
,
matches
=
self
.
get_matching_subprojects
(
sub_project
.
get_path
(),
filemask
)
else
:
matches
,
sharedrepo
=
self
.
import_initial
(
project
,
repo
,
branch
,
filemask
,
options
[
'name_template'
])
# Create remaining subprojects sharing git repository
for
name
in
names
:
for
match
in
matches
:
name
=
options
[
'name_template'
]
%
match
slug
=
slugify
(
name
)
if
SubProject
.
objects
.
filter
(
Q
(
name
=
name
)
|
Q
(
slug
=
slug
),
project
=
project
).
exists
():
...
...
@@ -153,26 +161,27 @@ class Command(BaseCommand):
project
=
project
,
repo
=
sharedrepo
,
branch
=
branch
,
filemask
=
filemask
.
replace
(
'**'
,
name
)
filemask
=
filemask
.
replace
(
'**'
,
match
)
)
def
import_initial
(
self
,
project
,
repo
,
branch
,
filemask
):
def
import_initial
(
self
,
project
,
repo
,
branch
,
filemask
,
name_template
):
'''
Import the first repository of a project
'''
# Checkout git to temporary dir
workdir
=
self
.
checkout_tmp
(
project
,
repo
,
branch
)
nam
es
=
self
.
get_matching_subprojects
(
workdir
,
filemask
)
match
es
=
self
.
get_matching_subprojects
(
workdir
,
filemask
)
# Create first subproject (this one will get full git repo)
name
=
names
.
pop
()
match
=
matches
.
pop
()
name
=
name_template
%
match
slug
=
slugify
(
name
)
if
SubProject
.
objects
.
filter
(
project
=
project
,
slug
=
slug
).
exists
():
logger
.
warn
(
'Subproject %s already exists, skipping and using it '
'as main subproject'
,
name
)
shutil
.
rmtree
(
workdir
)
return
nam
es
,
'weblate://%s/%s'
%
(
project
.
slug
,
slug
)
return
match
es
,
'weblate://%s/%s'
%
(
project
.
slug
,
slug
)
logger
.
info
(
'Creating subproject %s as main subproject'
,
name
)
...
...
@@ -188,9 +197,9 @@ class Command(BaseCommand):
project
=
project
,
repo
=
repo
,
branch
=
branch
,
filemask
=
filemask
.
replace
(
'**'
,
name
)
filemask
=
filemask
.
replace
(
'**'
,
match
)
)
sharedrepo
=
'weblate://%s/%s'
%
(
project
.
slug
,
slug
)
return
nam
es
,
sharedrepo
return
match
es
,
sharedrepo
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