Commit fa41f13e authored by Michal Čihař's avatar Michal Čihař

Avoid using deprecated optparse

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 5314c581
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
# 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 optparse import make_option
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
...@@ -26,29 +25,28 @@ from django.contrib.sites.models import Site ...@@ -26,29 +25,28 @@ from django.contrib.sites.models import Site
class Command(BaseCommand): class Command(BaseCommand):
help = 'changes default site name' help = 'changes default site name'
option_list = BaseCommand.option_list + (
make_option( def add_arguments(self, parser):
parser.add_argument(
'--set-name', '--set-name',
type='str',
dest='set_name', dest='set_name',
default=None, default=None,
help='site name to set' help='site name to set'
), )
make_option( parser.add_argument(
'--site-id', '--site-id',
type='int', type=int,
dest='site_id', dest='site_id',
default=1, default=1,
help='site ID to manipulate (1 by default)' help='site ID to manipulate (1 by default)'
), )
make_option( parser.add_argument(
'--get-name', '--get-name',
action='store_true', action='store_true',
dest='get_name', dest='get_name',
default=False, default=False,
help='just display the site name' help='just display the site name'
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
if options['set_name']: if options['set_name']:
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
# 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 optparse import make_option
import random import random
import string import string
...@@ -28,14 +27,14 @@ from django.contrib.auth.models import User ...@@ -28,14 +27,14 @@ from django.contrib.auth.models import User
class Command(BaseCommand): class Command(BaseCommand):
help = 'setups admin user with random password' help = 'setups admin user with random password'
option_list = BaseCommand.option_list + (
make_option( def add_arguments(self, parser):
parser.add_argument(
'--password', '--password',
dest='password', dest='password',
default=None, default=None,
help='Password to set, random is generated if not specified' help='Password to set, random is generated if not specified'
), )
)
@staticmethod @staticmethod
def make_password(length): def make_password(length):
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from optparse import make_option import argparse
import json import json
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
...@@ -29,13 +29,17 @@ from django.contrib.auth.models import User ...@@ -29,13 +29,17 @@ from django.contrib.auth.models import User
class Command(BaseCommand): class Command(BaseCommand):
help = 'imports users from JSON dump of database' help = 'imports users from JSON dump of database'
args = '<json-file>'
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option( parser.add_argument(
'--check', '--check',
action='store_true', action='store_true',
help='Only check import, do not actually create users' help='Only check import, do not actually create users'
), )
parser.add_argument(
'json-file',
type=argparse.FileType('rb'),
help='File to import',
) )
def handle(self, *args, **options): def handle(self, *args, **options):
...@@ -43,10 +47,8 @@ class Command(BaseCommand): ...@@ -43,10 +47,8 @@ class Command(BaseCommand):
Creates default set of groups and optionally updates them and moves Creates default set of groups and optionally updates them and moves
users around to default group. users around to default group.
''' '''
if len(args) != 1:
raise CommandError('Please specify JSON file to import!')
data = json.load(open(args[0])) data = json.load(options['json-file'])
for line in data: for line in data:
if 'fields' in line: if 'fields' in line:
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
# 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 optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from weblate.accounts.models import create_groups, move_users from weblate.accounts.models import create_groups, move_users
...@@ -27,22 +25,22 @@ from weblate.accounts.models import create_groups, move_users ...@@ -27,22 +25,22 @@ from weblate.accounts.models import create_groups, move_users
class Command(BaseCommand): class Command(BaseCommand):
help = 'setups default user groups' help = 'setups default user groups'
option_list = BaseCommand.option_list + (
make_option( def add_arguments(self, parser):
parser.add_argument(
'--move', '--move',
action='store_true', action='store_true',
dest='move', dest='move',
default=False, default=False,
help='Move all users to Users group' help='Move all users to Users group'
), )
make_option( parser.add_argument(
'--no-privs-update', '--no-privs-update',
action='store_false', action='store_false',
dest='update', dest='update',
default=True, default=True,
help='Prevents updates of privileges of existing groups' help='Prevents updates of privileges of existing groups'
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
''' '''
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
# 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 optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from weblate.lang.models import Language from weblate.lang.models import Language
...@@ -28,15 +26,14 @@ from weblate.lang.models import Language ...@@ -28,15 +26,14 @@ from weblate.lang.models import Language
class Command(BaseCommand): class Command(BaseCommand):
help = 'Populates language definitions' help = 'Populates language definitions'
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option( parser.add_argument(
'--no-update', '--no-update',
action='store_false', action='store_false',
dest='update', dest='update',
default=True, default=True,
help='Prevents updates to existing language definitions' help='Prevents updates to existing language definitions'
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
''' '''
......
...@@ -22,10 +22,11 @@ ...@@ -22,10 +22,11 @@
# Django settings for running testsuite # Django settings for running testsuite
# #
from weblate.settings_example import *
import warnings import warnings
import os import os
from weblate.settings_example import *
if 'CI_DATABASE' in os.environ: if 'CI_DATABASE' in os.environ:
if os.environ['CI_DATABASE'] == 'mysql': if os.environ['CI_DATABASE'] == 'mysql':
DATABASES['default']['ENGINE'] = 'django.db.backends.mysql' DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
Helper classes for management commands. Helper classes for management commands.
''' '''
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.db import transaction from django.db import transaction
...@@ -33,32 +31,35 @@ class WeblateCommand(BaseCommand): ...@@ -33,32 +31,35 @@ class WeblateCommand(BaseCommand):
''' '''
Command which accepts project/component/--all params to process. Command which accepts project/component/--all params to process.
''' '''
args = '<project/component>' def add_arguments(self, parser):
option_list = BaseCommand.option_list + ( parser.add_argument(
make_option(
'--all', '--all',
action='store_true', action='store_true',
dest='all', dest='all',
default=False, default=False,
help='process all components' help='process all components'
), )
) parser.add_argument(
'component',
nargs='*',
help='Slug <project/component> of component to process'
)
def get_units(self, *args, **options): def get_units(self, **options):
''' '''
Returns list of units matching parameters. Returns list of units matching parameters.
''' '''
if options['all']: if options['all']:
return Unit.objects.all() return Unit.objects.all()
return Unit.objects.filter( return Unit.objects.filter(
translation__subproject__in=self.get_subprojects(*args, **options) translation__subproject__in=self.get_subprojects(**options)
) )
def iterate_units(self, *args, **options): def iterate_units(self, **options):
""" """
Memory effective iteration over units. Memory effective iteration over units.
""" """
units = self.get_units(*args, **options).order_by('pk') units = self.get_units(**options).order_by('pk')
count = units.count() count = units.count()
if not count: if not count:
return return
...@@ -87,25 +88,25 @@ class WeblateCommand(BaseCommand): ...@@ -87,25 +88,25 @@ class WeblateCommand(BaseCommand):
yield unit yield unit
self.stdout.write('Operation completed') self.stdout.write('Operation completed')
def get_translations(self, *args, **options): def get_translations(self, **options):
''' '''
Returns list of translations matching parameters. Returns list of translations matching parameters.
''' '''
return Translation.objects.filter( return Translation.objects.filter(
subproject__in=self.get_subprojects(*args, **options) subproject__in=self.get_subprojects(**options)
) )
def get_subprojects(self, *args, **options): def get_subprojects(self, **options):
''' '''
Returns list of components matching parameters. Returns list of components matching parameters.
''' '''
if options['all']: if options['all']:
# all components # all components
result = SubProject.objects.all() result = SubProject.objects.all()
elif len(args) == 0: elif len(options['component']) == 0:
# no argumets to filter projects # no argumets to filter projects
self.stderr.write( self.stderr.write(
'Please specify either --all or <project/component>' 'Please specify either --all or at least one <project/component>'
) )
raise CommandError('Nothing to process!') raise CommandError('Nothing to process!')
else: else:
...@@ -113,7 +114,7 @@ class WeblateCommand(BaseCommand): ...@@ -113,7 +114,7 @@ class WeblateCommand(BaseCommand):
result = SubProject.objects.none() result = SubProject.objects.none()
# process arguments # process arguments
for arg in args: for arg in options['component']:
# do we have also component? # do we have also component?
parts = arg.split('/') parts = arg.split('/')
...@@ -150,22 +151,21 @@ class WeblateLangCommand(WeblateCommand): ...@@ -150,22 +151,21 @@ class WeblateLangCommand(WeblateCommand):
Command accepting additional language parameter to filter Command accepting additional language parameter to filter
list of languages to process. list of languages to process.
''' '''
option_list = WeblateCommand.option_list + ( def add_arguments(self, parser):
make_option( super(WeblateLangCommand, self).add_arguments(parser)
parser.add_argument(
'--lang', '--lang',
action='store', action='store',
type='string',
dest='lang', dest='lang',
default=None, default=None,
help='Limit only to given languages (comma separated list)' help='Limit only to given languages (comma separated list)'
), )
)
def get_units(self, *args, **options): def get_units(self, **options):
''' '''
Returns list of units matching parameters. Returns list of units matching parameters.
''' '''
units = super(WeblateLangCommand, self).get_units(*args, **options) units = super(WeblateLangCommand, self).get_units(**options)
if options['lang'] is not None: if options['lang'] is not None:
units = units.filter( units = units.filter(
...@@ -174,12 +174,12 @@ class WeblateLangCommand(WeblateCommand): ...@@ -174,12 +174,12 @@ class WeblateLangCommand(WeblateCommand):
return units return units
def get_translations(self, *args, **options): def get_translations(self, **options):
''' '''
Returns list of translations matching parameters. Returns list of translations matching parameters.
''' '''
result = super(WeblateLangCommand, self).get_translations( result = super(WeblateLangCommand, self).get_translations(
*args, **options **options
) )
if options['lang'] is not None: if options['lang'] is not None:
...@@ -199,15 +199,28 @@ class WeblateLangCommand(WeblateCommand): ...@@ -199,15 +199,28 @@ class WeblateLangCommand(WeblateCommand):
class WeblateTranslationCommand(BaseCommand): class WeblateTranslationCommand(BaseCommand):
"""Command with target of one translation.""" """Command with target of one translation."""
args = '<project> <component> <language>'
def get_translation(self, args): def add_arguments(self, parser):
parser.add_argument(
'project',
help='Slug of project'
)
parser.add_argument(
'component',
help='Slug of component'
)
parser.add_argument(
'language',
help='Slug of language'
)
def get_translation(self, **options):
"""Get translation object""" """Get translation object"""
try: try:
return Translation.objects.get( return Translation.objects.get(
subproject__project__slug=args[0], subproject__project__slug=options['project'],
subproject__slug=args[1], subproject__slug=options['component'],
language__code=args[2], language__code=options['language'],
) )
except Translation.DoesNotExist: except Translation.DoesNotExist:
raise CommandError('No matching translation project found!') raise CommandError('No matching translation project found!')
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# 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 optparse import make_option import argparse
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -33,24 +33,25 @@ class Command(WeblateTranslationCommand): ...@@ -33,24 +33,25 @@ class Command(WeblateTranslationCommand):
Command for mass importing suggestions. Command for mass importing suggestions.
""" """
help = 'imports suggestions' help = 'imports suggestions'
args = '<project> <component> <language> <file>'
option_list = WeblateTranslationCommand.option_list + ( def add_arguments(self, parser):
make_option( super(Command, self).add_arguments(parser)
parser.add_argument(
'--author', '--author',
default='noreply@weblate.org', default='noreply@weblate.org',
help=( help=(
'Email address of author (has to be registered in Weblate)' 'Email address of author (has to be registered in Weblate)'
) )
), )
) parser.add_argument(
'file',
type=argparse.FileType('rb'),
help='File to import',
)
def handle(self, *args, **options): def handle(self, *args, **options):
# Check params
if len(args) != 4:
raise CommandError('Invalid number of parameters!')
# Get translation object # Get translation object
translation = self.get_translation(args) translation = self.get_translation(**options)
# Get user # Get user
try: try:
...@@ -64,10 +65,9 @@ class Command(WeblateTranslationCommand): ...@@ -64,10 +65,9 @@ class Command(WeblateTranslationCommand):
# Process import # Process import
try: try:
with open(args[3], 'rb') as handle: translation.merge_upload(
translation.merge_upload( request, options['file'], False, method='suggest',
request, handle, False, method='suggest', author=get_author_name(user),
author=get_author_name(user), )
)
except IOError: except IOError:
raise CommandError('Failed to import translation file!') raise CommandError('Failed to import translation file!')
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
# 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 optparse import make_option
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -33,46 +31,43 @@ class Command(WeblateTranslationCommand): ...@@ -33,46 +31,43 @@ class Command(WeblateTranslationCommand):
Command for mass automatic translation. Command for mass automatic translation.
""" """
help = 'performs automatic translation based on other components' help = 'performs automatic translation based on other components'
option_list = WeblateTranslationCommand.option_list + (
make_option( def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument(
'--user', '--user',
default='anonymous', default='anonymous',
help=( help=(
'User performing the change' 'User performing the change'
) )
), )
make_option( parser.add_argument(
'--source', '--source',
default='', default='',
help=( help=(
'Source component <project/component>' 'Source component <project/component>'
) )
), )
make_option( parser.add_argument(
'--overwrite', '--overwrite',
default=False, default=False,
action='store_true', action='store_true',
help=( help=(
'Overwrite existing translations in target component' 'Overwrite existing translations in target component'
) )
), )
make_option( parser.add_argument(
'--inconsistent', '--inconsistent',
default=False, default=False,
action='store_true', action='store_true',
help=( help=(
'Process only inconsistent translations' 'Process only inconsistent translations'
) )
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
# Check params
if len(args) != 3:
raise CommandError('Invalid number of parameters!')
# Get translation object # Get translation object
translation = self.get_translation(args) translation = self.get_translation(**options)
# Get user # Get user
try: try:
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
# 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 optparse import make_option
import cProfile import cProfile
import pstats import pstats
...@@ -32,28 +31,37 @@ class Command(BaseCommand): ...@@ -32,28 +31,37 @@ class Command(BaseCommand):
Runs simple project import to perform benchmarks. Runs simple project import to perform benchmarks.
''' '''
help = 'performs import benchmark' help = 'performs import benchmark'
args = '<project> <repo> <mask>'
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option( super(Command, self).add_arguments(parser)
parser.add_argument(
'--profile-sort', '--profile-sort',
type='str',
dest='profile_sort', dest='profile_sort',
default='cumulative', default='cumulative',
help='sort order for profile stats', help='sort order for profile stats',
), )
make_option( parser.add_argument(
'--profile-count', '--profile-count',
type='int', type=int,
dest='profile_count', dest='profile_count',
default=20, default=20,
help='number of profile stats to show', help='number of profile stats to show',
), )
) parser.add_argument(
'project',
help='Existing project slug for tests',
)
parser.add_argument(
'repo',
help='VCS repository URL',
)
parser.add_argument(
'mask',
help='File mask',
)
def handle(self, *args, **options): def handle(self, *args, **options):
if len(args) < 3: project = Project.objects.get(slug=options['project'])
raise CommandError('Missing arguments!')
project = Project.objects.get(slug=args[0])
# Delete any possible previous tests # Delete any possible previous tests
SubProject.objects.filter( SubProject.objects.filter(
project=project, project=project,
...@@ -64,8 +72,8 @@ class Command(BaseCommand): ...@@ -64,8 +72,8 @@ class Command(BaseCommand):
SubProject.objects.create, SubProject.objects.create,
name='Benchmark', name='Benchmark',
slug='benchmark', slug='benchmark',
repo=args[1], repo=options['repo'],
filemask=args[2], filemask=options['mask'],
project=project project=project
) )
stats = pstats.Stats(profiler) stats = pstats.Stats(profiler)
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
# #
from datetime import timedelta from datetime import timedelta
from optparse import make_option
from django.utils import timezone from django.utils import timezone
from weblate.trans.management.commands import WeblateLangCommand from weblate.trans.management.commands import WeblateLangCommand
...@@ -28,22 +26,23 @@ from weblate.trans.management.commands import WeblateLangCommand ...@@ -28,22 +26,23 @@ from weblate.trans.management.commands import WeblateLangCommand
class Command(WeblateLangCommand): class Command(WeblateLangCommand):
help = 'commits pending changes older than given age' help = 'commits pending changes older than given age'
option_list = WeblateLangCommand.option_list + (
make_option( def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument(
'--age', '--age',
action='store', action='store',
type='int', type=int,
dest='age', dest='age',
default=24, default=24,
help='Age of changes to commit in hours (default is 24 hours)' help='Age of changes to commit in hours (default is 24 hours)'
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
age = timezone.now() - timedelta(hours=options['age']) age = timezone.now() - timedelta(hours=options['age'])
for translation in self.get_translations(*args, **options): for translation in self.get_translations(**options):
if not translation.repo_needs_commit(): if not translation.repo_needs_commit():
continue continue
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
# #
from glob import glob from glob import glob
from optparse import make_option
import tempfile import tempfile
import os import os
import re import re
...@@ -43,45 +42,46 @@ class Command(BaseCommand): ...@@ -43,45 +42,46 @@ class Command(BaseCommand):
Command for mass importing of repositories into Weblate. Command for mass importing of repositories into Weblate.
""" """
help = 'imports projects with more components' help = 'imports projects with more components'
args = '<project> <gitrepo> <branch> <filemask>'
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option( super(Command, self).add_arguments(parser)
parser.add_argument(
'--name-template', '--name-template',
default='%s', default='%s',
help=( help=(
'Python formatting string, transforming the filemask ' 'Python formatting string, transforming the filemask '
'match to a project name' 'match to a project name'
) )
), )
make_option( parser.add_argument(
'--component-regexp', '--component-regexp',
default=None, default=None,
help=( help=(
'Regular expression to match component out of filename' 'Regular expression to match component out of filename'
) )
), )
make_option( parser.add_argument(
'--base-file-template', '--base-file-template',
default='', default='',
help=( help=(
'Python formatting string, transforming the filemask ' 'Python formatting string, transforming the filemask '
'match to a monolingual base file name' 'match to a monolingual base file name'
) )
), )
make_option( parser.add_argument(
'--file-format', '--file-format',
default='auto', default='auto',
help='File format type, defaults to autodetection', help='File format type, defaults to autodetection',
), )
make_option( parser.add_argument(
'--language-regex', '--language-regex',
default=None, default=None,
help=( help=(
'Language filter regular expression to be used for created' 'Language filter regular expression to be used for created'
' components' ' components'
), ),
), )
make_option( parser.add_argument(
'--no-skip-duplicates', '--no-skip-duplicates',
action='store_true', action='store_true',
default=False, default=False,
...@@ -90,31 +90,46 @@ class Command(BaseCommand): ...@@ -90,31 +90,46 @@ class Command(BaseCommand):
'Avoid skipping duplicate component names/slugs. ' 'Avoid skipping duplicate component names/slugs. '
'Use this if importing project with long names ' 'Use this if importing project with long names '
) )
), )
make_option( parser.add_argument(
'--license', '--license',
default=None, default=None,
help='License of imported components', help='License of imported components',
), )
make_option( parser.add_argument(
'--license-url', '--license-url',
default=None, default=None,
help='License URL of imported components', help='License URL of imported components',
), )
make_option( parser.add_argument(
'--vcs', '--vcs',
default='git', default='git',
help='Version control system to use', help='Version control system to use',
), )
make_option( parser.add_argument(
'--main-component', '--main-component',
default=None, default=None,
help=( help=(
'Define which component will be used as main - including full' 'Define which component will be used as main - including full'
' VCS repository' ' VCS repository'
) )
), )
) parser.add_argument(
'project',
help='Existing project slug',
)
parser.add_argument(
'repo',
help='VCS repository URL',
)
parser.add_argument(
'branch',
help='VCS repository branch',
)
parser.add_argument(
'filemask',
help='File mask',
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs) super(Command, self).__init__(*args, **kwargs)
...@@ -219,9 +234,9 @@ class Command(BaseCommand): ...@@ -219,9 +234,9 @@ class Command(BaseCommand):
'Failed to find suitable name for {0}'.format(name) 'Failed to find suitable name for {0}'.format(name)
) )
def parse_options(self, args, options): def parse_options(self, options):
"""Parses parameters""" """Parses parameters"""
self.filemask = args[3] self.filemask = options['filemask']
self.vcs = options['vcs'] self.vcs = options['vcs']
self.file_format = options['file_format'] self.file_format = options['file_format']
self.language_regex = options['language_regex'] self.language_regex = options['language_regex']
...@@ -264,22 +279,18 @@ class Command(BaseCommand): ...@@ -264,22 +279,18 @@ class Command(BaseCommand):
''' '''
Automatic import of project. Automatic import of project.
''' '''
# Check params count
if len(args) != 4:
raise CommandError('Invalid number of parameters!')
# Read params # Read params
repo = args[1] repo = options['repo']
branch = args[2] branch = options['branch']
self.parse_options(args, options) self.parse_options(options)
# Try to get project # Try to get project
try: try:
project = Project.objects.get(slug=args[0]) project = Project.objects.get(slug=options['project'])
except Project.DoesNotExist: except Project.DoesNotExist:
raise CommandError( raise CommandError(
'Project %s does not exist, you need to create it first!' % 'Project %s does not exist, you need to create it first!' %
args[0] options['project']
) )
if is_repo_link(repo): if is_repo_link(repo):
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
# 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 optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from weblate.trans.models import Check, get_related_units from weblate.trans.models import Check, get_related_units
...@@ -27,22 +25,23 @@ from weblate.trans.models import Check, get_related_units ...@@ -27,22 +25,23 @@ from weblate.trans.models import Check, get_related_units
class Command(BaseCommand): class Command(BaseCommand):
help = 'lists top ignored checks' help = 'lists top ignored checks'
option_list = BaseCommand.option_list + (
make_option( def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument(
'--count', '--count',
type='int', type=int,
dest='count', dest='count',
default=100, default=100,
help='Number of top checks to list', help='Number of top checks to list',
), )
make_option( parser.add_argument(
'--list-all', '--list-all',
action='store_true', action='store_true',
dest='list_all', dest='list_all',
default=False, default=False,
help='List all checks (not only ignored)', help='List all checks (not only ignored)',
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
results = {} results = {}
......
...@@ -18,26 +18,25 @@ ...@@ -18,26 +18,25 @@
# 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 optparse import make_option
from weblate.trans.management.commands import WeblateLangCommand from weblate.trans.management.commands import WeblateLangCommand
class Command(WeblateLangCommand): class Command(WeblateLangCommand):
help = '(re)loads translations from disk' help = '(re)loads translations from disk'
option_list = WeblateLangCommand.option_list + (
make_option( def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument(
'--force', '--force',
action='store_true', action='store_true',
dest='force', dest='force',
default=False, default=False,
help='Force rereading files even when they should be up to date' help='Force rereading files even when they should be up to date'
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
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 subproject in self.get_subprojects(*args, **options): for subproject in self.get_subprojects(**options):
subproject.create_translations(options['force'], langs) subproject.create_translations(options['force'], langs)
...@@ -18,23 +18,22 @@ ...@@ -18,23 +18,22 @@
# 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 optparse import make_option
from weblate.trans.management.commands import WeblateCommand from weblate.trans.management.commands import WeblateCommand
class Command(WeblateCommand): class Command(WeblateCommand):
help = 'pushes all changes to upstream respository' help = 'pushes all changes to upstream respository'
option_list = WeblateCommand.option_list + (
make_option( def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument(
'--force-commit', '--force-commit',
action='store_true', action='store_true',
dest='force_commit', dest='force_commit',
default=False, default=False,
help='Forces commiting pending changes' help='Forces commiting pending changes'
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
for subproject in self.get_subprojects(*args, **options): for subproject in self.get_subprojects(**options):
subproject.do_push(None, force_commit=options['force_commit']) subproject.do_push(None, force_commit=options['force_commit'])
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
# 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 optparse import make_option
from weblate.trans.management.commands import WeblateCommand from weblate.trans.management.commands import WeblateCommand
from weblate.trans.search import ( from weblate.trans.search import (
get_source_index, get_target_index, get_source_index, get_target_index,
...@@ -31,22 +29,23 @@ from weblate.lang.models import Language ...@@ -31,22 +29,23 @@ from weblate.lang.models import Language
class Command(WeblateCommand): class Command(WeblateCommand):
help = 'rebuilds index for fulltext search' help = 'rebuilds index for fulltext search'
option_list = WeblateCommand.option_list + (
make_option( def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument(
'--clean', '--clean',
action='store_true', action='store_true',
dest='clean', dest='clean',
default=False, default=False,
help='removes also all words from database' help='removes also all words from database'
), )
make_option( parser.add_argument(
'--optimize', '--optimize',
action='store_true', action='store_true',
dest='optimize', dest='optimize',
default=False, default=False,
help='optimize index without rebuilding it' help='optimize index without rebuilding it'
), )
)
def optimize_index(self): def optimize_index(self):
"""Optimizes index structures""" """Optimizes index structures"""
...@@ -72,7 +71,7 @@ class Command(WeblateCommand): ...@@ -72,7 +71,7 @@ class Command(WeblateCommand):
try: try:
# Process all units # Process all units
for unit in self.iterate_units(*args, **options): for unit in self.iterate_units(**options):
lang = unit.translation.language.code lang = unit.translation.language.code
# Lazy open writer # Lazy open writer
if lang not in target_writers: if lang not in target_writers:
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
# 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 optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db import transaction from django.db import transaction
...@@ -29,16 +27,17 @@ from weblate.trans.search import update_index, delete_search_unit ...@@ -29,16 +27,17 @@ from weblate.trans.search import update_index, delete_search_unit
class Command(BaseCommand): class Command(BaseCommand):
help = 'updates index for fulltext search' help = 'updates index for fulltext search'
option_list = BaseCommand.option_list + (
make_option( def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument(
'--limit', '--limit',
action='store', action='store',
type='int', type=int,
dest='limit', dest='limit',
default=1000, default=1000,
help='number of updates to process in one run' help='number of updates to process in one run'
), )
)
def handle(self, *args, **options): def handle(self, *args, **options):
self.do_update(options['limit']) self.do_update(options['limit'])
......
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