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
8022e7c1
Commit
8022e7c1
authored
Jun 28, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add script for automatic import of project (issue #50)
parent
38e0a88e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
weblate/trans/management/commands/import_project.py
weblate/trans/management/commands/import_project.py
+92
-0
No files found.
weblate/trans/management/commands/import_project.py
0 → 100644
View file @
8022e7c1
from
django.core.management.base
import
BaseCommand
,
CommandError
from
weblate.trans.models
import
SubProject
,
Project
from
optparse
import
make_option
from
glob
import
glob
import
tempfile
import
git
import
logging
import
os
import
re
import
fnmatch
logger
=
logging
.
getLogger
(
'weblate'
)
class
Command
(
BaseCommand
):
help
=
'forces commiting changes to git repo'
args
=
'<project> <gitrepo> <branch> <filemask>'
def
get_name
(
self
,
path
):
m
=
self
.
maskre
.
match
(
path
)
return
m
.
group
(
1
)
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
!=
4
:
raise
CommandError
(
'Not enough parameters!'
)
prjname
,
repo
,
branch
,
filemask
=
args
match
=
fnmatch
.
translate
(
filemask
)
match
=
match
.
replace
(
'.*.*'
,
'(.*.*)'
)
self
.
maskre
=
re
.
compile
(
match
)
try
:
project
=
Project
.
objects
.
get
(
slug
=
prjname
)
except
Project
.
DoesNotExist
:
raise
CommandError
(
'Project %s does not exist!'
%
prjname
)
if
not
'**'
in
filemask
:
raise
CommandError
(
'You need to specify double wildcard 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
)
# Find matching files
matches
=
glob
(
os
.
path
.
join
(
workdir
,
filemask
))
matches
=
[
f
.
replace
(
workdir
,
''
).
strip
(
'/'
)
for
f
in
matches
]
logger
.
info
(
'Found %d matching files'
,
len
(
matches
))
# Parse subproject names out of them
names
=
set
()
for
m
in
matches
:
names
.
add
(
self
.
get_name
(
m
))
logger
.
info
(
'Found %d subprojects'
,
len
(
names
))
# Create first subproject (this one will get full git repo)
name
=
names
.
pop
()
logger
.
info
(
'Creating subproject %s as main subproject'
,
name
)
# Rename gitrepository to new name
os
.
rename
(
workdir
,
os
.
path
.
join
(
project
.
get_path
(),
name
))
SubProject
.
objects
.
create
(
name
=
name
,
slug
=
name
,
project
=
project
,
repo
=
repo
,
branch
=
branch
,
filemask
=
filemask
.
replace
(
'**'
,
name
)
)
sharedrepo
=
'weblate://%s/%s'
%
(
project
.
slug
,
name
)
# Create remaining subprojects sharing git repository
for
name
in
names
:
logger
.
info
(
'Creating subproject %s'
,
name
)
SubProject
.
objects
.
create
(
name
=
name
,
slug
=
name
,
project
=
project
,
repo
=
sharedrepo
,
branch
=
branch
,
filemask
=
filemask
.
replace
(
'**'
,
name
)
)
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