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

Move options processing and validation to separate method

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 954a0e0b
...@@ -217,23 +217,8 @@ class Command(BaseCommand): ...@@ -217,23 +217,8 @@ class Command(BaseCommand):
'Failed to find suitable name for {0}'.format(name) 'Failed to find suitable name for {0}'.format(name)
) )
def handle(self, *args, **options): def parse_options(self, args, options):
''' """Parses parameters"""
Automatic import of project.
'''
# Check params
if len(args) != 4:
raise CommandError('Invalid number of parameters!')
if options['file_format'] not in FILE_FORMATS:
raise CommandError(
'Invalid file format: %s' % options['file_format']
)
# Read params
repo = args[1]
branch = args[2]
self.filemask = args[3] self.filemask = args[3]
self.vcs = options['vcs'] self.vcs = options['vcs']
self.file_format = options['file_format'] self.file_format = options['file_format']
...@@ -260,13 +245,10 @@ class Command(BaseCommand): ...@@ -260,13 +245,10 @@ class Command(BaseCommand):
'Component regullar expression lacks named group "name"' 'Component regullar expression lacks named group "name"'
) )
# Try to get project # Is file format supported?
try: if self.file_format not in FILE_FORMATS:
project = Project.objects.get(slug=args[0])
except Project.DoesNotExist:
raise CommandError( raise CommandError(
'Project %s does not exist, you need to create it first!' % 'Invalid file format: %s' % options['file_format']
args[0]
) )
# Do we have correct mask? # Do we have correct mask?
...@@ -276,6 +258,28 @@ class Command(BaseCommand): ...@@ -276,6 +258,28 @@ class Command(BaseCommand):
'for subproject part of the match!' 'for subproject part of the match!'
) )
def handle(self, *args, **options):
'''
Automatic import of project.
'''
# Check params count
if len(args) != 4:
raise CommandError('Invalid number of parameters!')
# Read params
repo = args[1]
branch = args[2]
self.parse_options(args, options)
# Try to get project
try:
project = Project.objects.get(slug=args[0])
except Project.DoesNotExist:
raise CommandError(
'Project %s does not exist, you need to create it first!' %
args[0]
)
if is_repo_link(repo): if is_repo_link(repo):
sharedrepo = repo sharedrepo = repo
try: try:
......
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