Commit 9f9b0abd authored by Michal Čihař's avatar Michal Čihař

Avoid using deprecated interface for positional args in commands

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 6270b71f
...@@ -20,23 +20,26 @@ ...@@ -20,23 +20,26 @@
import json import json
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand
from weblate.accounts.models import Profile from weblate.accounts.models import Profile
class Command(BaseCommand): class Command(BaseCommand):
help = 'dumps user data to JSON file' help = 'dumps user data to JSON file'
args = '<json-file>'
def add_arguments(self, parser):
parser.add_argument(
'json-file',
type=argparse.FileType('w'),
help='File where to export',
)
def handle(self, *args, **options): def handle(self, *args, **options):
''' '''
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 create!')
data = [] data = []
fields = ( fields = (
'language', 'language',
...@@ -72,4 +75,4 @@ class Command(BaseCommand): ...@@ -72,4 +75,4 @@ class Command(BaseCommand):
data.append(item) data.append(item)
json.dump(data, open(args[0], 'w'), indent=2) json.dump(data, options['json-file'], indent=2)
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
import json import json
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand
from django.contrib.auth.models import User from django.contrib.auth.models import User
from weblate.accounts.models import Profile from weblate.accounts.models import Profile
...@@ -30,7 +30,13 @@ from weblate.trans.models import Project ...@@ -30,7 +30,13 @@ from weblate.trans.models import Project
class Command(BaseCommand): class Command(BaseCommand):
help = 'imports userdata from JSON dump of database' help = 'imports userdata from JSON dump of database'
args = '<json-file>'
def add_arguments(self, parser):
parser.add_argument(
'json-file',
type=argparse.FileType('r'),
help='File to import',
)
def import_subscriptions(self, profile, userprofile): def import_subscriptions(self, profile, userprofile):
""" """
...@@ -63,15 +69,12 @@ class Command(BaseCommand): ...@@ -63,15 +69,12 @@ class Command(BaseCommand):
Language.objects.get(code=lang) Language.objects.get(code=lang)
) )
def handle(self, *args, **options): def handle(self, **options):
''' '''
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: userdata = json.load(options['json-file'])
raise CommandError('Please specify JSON file to import!')
userdata = json.load(open(args[0]))
for userprofile in userdata: for userprofile in userdata:
try: try:
......
...@@ -38,7 +38,7 @@ class Command(BaseCommand): ...@@ -38,7 +38,7 @@ class Command(BaseCommand):
) )
parser.add_argument( parser.add_argument(
'json-file', 'json-file',
type=argparse.FileType('rb'), type=argparse.FileType('r'),
help='File to import', help='File to import',
) )
......
...@@ -24,16 +24,18 @@ from weblate.lang.models import Language ...@@ -24,16 +24,18 @@ from weblate.lang.models import Language
class Command(BaseCommand): class Command(BaseCommand):
help = 'Checks language definitions against rst/csv file' help = 'Checks language definitions against rst/csv file'
args = '<test-file>'
def add_arguments(self, parser):
parser.add_argument(
'test-file',
help='File to test',
)
def handle(self, *args, **options): def handle(self, *args, **options):
''' '''
Creates default set of languages, optionally updating them Creates default set of languages, optionally updating them
to match current shipped definitions. to match current shipped definitions.
''' '''
if len(args) != 1: errors = Language.objects.check_definitions(options['test-file'])
raise CommandError('Use: checklang file')
errors = Language.objects.check_definitions(args[0])
for error in errors: for error in errors:
self.stderr.write(error) self.stderr.write(error)
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