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 @@
import json
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
from weblate.accounts.models import Profile
class Command(BaseCommand):
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):
'''
Creates default set of groups and optionally updates them and moves
users around to default group.
'''
if len(args) != 1:
raise CommandError('Please specify JSON file to create!')
data = []
fields = (
'language',
......@@ -72,4 +75,4 @@ class Command(BaseCommand):
data.append(item)
json.dump(data, open(args[0], 'w'), indent=2)
json.dump(data, options['json-file'], indent=2)
......@@ -20,7 +20,7 @@
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 weblate.accounts.models import Profile
......@@ -30,7 +30,13 @@ from weblate.trans.models import Project
class Command(BaseCommand):
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):
"""
......@@ -63,15 +69,12 @@ class Command(BaseCommand):
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
users around to default group.
'''
if len(args) != 1:
raise CommandError('Please specify JSON file to import!')
userdata = json.load(open(args[0]))
userdata = json.load(options['json-file'])
for userprofile in userdata:
try:
......
......@@ -38,7 +38,7 @@ class Command(BaseCommand):
)
parser.add_argument(
'json-file',
type=argparse.FileType('rb'),
type=argparse.FileType('r'),
help='File to import',
)
......
......@@ -24,16 +24,18 @@ from weblate.lang.models import Language
class Command(BaseCommand):
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):
'''
Creates default set of languages, optionally updating them
to match current shipped definitions.
'''
if len(args) != 1:
raise CommandError('Use: checklang file')
errors = Language.objects.check_definitions(args[0])
errors = Language.objects.check_definitions(options['test-file'])
for error in errors:
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