Commit 0c055d7a authored by Michal Čihař's avatar Michal Čihař

Unifiy params handling for subproject based commands

parent 95227ec0
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from optparse import make_option from optparse import make_option
from weblate.trans.models import Unit from weblate.trans.models import Unit, SubProject
class UnitCommand(BaseCommand): class UnitCommand(BaseCommand):
''' '''
...@@ -54,7 +54,40 @@ class UnitCommand(BaseCommand): ...@@ -54,7 +54,40 @@ class UnitCommand(BaseCommand):
else: else:
prj = parts[0] prj = parts[0]
base |= Unit.objects.filter(translation__subproject__project__slug = prj) base |= Unit.objects.filter(translation__subproject__project__slug = prj)
else: if len(args) == 0 or base.count() == 0:
print 'Nothing to process, please use either --all or <project/subproject>'
return base
class SubProjectCommand(BaseCommand):
'''
Command which accepts project/subproject/--all params to process subprojects.
'''
args = '<project/subproject>'
option_list = BaseCommand.option_list + (
make_option('--all',
action='store_true',
dest='all',
default=False,
help='work on all projects'),
)
def get_subprojects(self, *args, **options):
'''
Returns list of units matching parameters.
'''
if options['all']:
base = SubProject.objects.all()
else:
base = SubProject.objects.none()
for arg in args:
parts = arg.split('/')
if len(parts) == 2:
prj, subprj = parts
base |= SubProject.objects.filter(slug = subprj, project__slug = prj)
else:
prj = parts[0]
base |= SubProject.objects.filter(project__slug = prj)
if len(args) == 0 or base.count() == 0:
print 'Nothing to process, please use either --all or <project/subproject>' print 'Nothing to process, please use either --all or <project/subproject>'
return base return base
...@@ -18,33 +18,16 @@ ...@@ -18,33 +18,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from django.core.management.base import BaseCommand from weblate.trans.management.commands import SubProjectCommand
from weblate.trans.models import SubProject
from optparse import make_option
class Command(BaseCommand): class Command(SubProjectCommand):
help = 'checks status of git repo' help = 'checks status of git repo'
args = '<project/subproject>'
option_list = BaseCommand.option_list + (
make_option('--all',
action='store_true',
dest='all',
default=False,
help='Check all projects'),
)
def handle(self, *args, **options): def handle(self, *args, **options):
''' '''
Shows status of git repository in given projects. Shows status of git repository in given projects.
''' '''
if options['all']: for s in self.get_subprojects(*args, **options):
for s in SubProject.objects.all():
r = s.get_repo()
print '%s:' % s
print r.git.status()
for arg in args:
prj, subprj = arg.split('/')
s = SubProject.objects.get(slug = subprj, project__slug = prj)
r = s.get_repo() r = s.get_repo()
print '%s:' % s print '%s:' % s
print r.git.status() print r.git.status()
......
...@@ -18,31 +18,16 @@ ...@@ -18,31 +18,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from django.core.management.base import BaseCommand from weblate.trans.management.commands import SubProjectCommand
from weblate.trans.models import SubProject
from optparse import make_option
class Command(BaseCommand): class Command(SubProjectCommand):
help = 'forces commiting changes to git repo' help = 'forces commiting changes to git repo'
args = '<project/subproject>'
option_list = BaseCommand.option_list + (
make_option('--all',
action='store_true',
dest='all',
default=False,
help='Check all projects'),
)
def handle(self, *args, **options): def handle(self, *args, **options):
''' '''
Commits pending translations in given projects. Commits pending translations in given projects.
''' '''
if options['all']: for s in self.get_subprojects(*args, **options):
for s in SubProject.objects.all():
s.commit_pending()
for arg in args:
prj, subprj = arg.split('/')
s = SubProject.objects.get(slug = subprj, project__slug = prj)
s.commit_pending() s.commit_pending()
......
...@@ -18,14 +18,12 @@ ...@@ -18,14 +18,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from django.core.management.base import BaseCommand from weblate.trans.management.commands import SubProjectCommand
from weblate.trans.models import SubProject
from optparse import make_option from optparse import make_option
class Command(BaseCommand): class Command(SubProjectCommand):
help = '(re)loads translations from disk' help = '(re)loads translations from disk'
args = '<project/subproject>' option_list = SubProjectCommand.option_list + (
option_list = BaseCommand.option_list + (
make_option('--force', make_option('--force',
action='store_true', action='store_true',
dest='force', dest='force',
...@@ -45,7 +43,5 @@ class Command(BaseCommand): ...@@ -45,7 +43,5 @@ class Command(BaseCommand):
langs = None langs = None
if options['lang'] is not None: if options['lang'] is not None:
langs = options['lang'].split(',') langs = options['lang'].split(',')
for arg in args: for s in self.get_subprojects(*args, **options):
prj, subprj = arg.split('/')
s = SubProject.objects.get(slug = subprj, project__slug = prj)
s.create_translations(options['force'], langs) s.create_translations(options['force'], langs)
...@@ -18,32 +18,11 @@ ...@@ -18,32 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from django.core.management.base import BaseCommand from weblate.trans.management.commands import SubProjectCommand
from weblate.trans.models import SubProject, Project
from optparse import make_option
class Command(BaseCommand): class Command(SubProjectCommand):
help = 'updates git repos' help = 'updates git repos'
args = '<project/subproject>'
option_list = BaseCommand.option_list + (
make_option('--all',
action='store_true',
dest='all',
default=False,
help='Update all projects'),
)
def handle(self, *args, **options): def handle(self, *args, **options):
if options['all']: for s in self.get_subprojects(*args, **options):
for s in SubProject.objects.all(): s.do_update()
s.do_update()
for arg in args:
parts = arg.split('/')
if len(parts) == 2:
prj, subprj = parts
s = SubProject.objects.get(slug = subprj, project__slug = prj)
s.do_update()
else:
p = Project.objects.get(slug = parts[0])
p.do_update()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment