Skip to content

Commit

Permalink
fix for logic short-circuit in argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris7 committed Jun 23, 2015
1 parent 0b1bd24 commit 3a4e1de
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions djangui/backend/argparse_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,19 @@ def to_django(self):

class ArgParseNodeBuilder(object):
def __init__(self, script_path=None, script_name=None):
self.valid = True
self.valid = False
self.error = ''
parsers = []
try:
module = imp.load_source(script_name, script_path)
except:
sys.stderr.write('Error while loading {0}:\n'.format(script_path))
self.error = '{0}\n'.format(traceback.format_exc())
sys.stderr.write(self.error)
self.valid = False
return
main_module = module.main.__globals__ if hasattr(module, 'main') else globals()
parsers = [v for i, v in chain(six.iteritems(main_module), six.iteritems(vars(module)))
if issubclass(type(v), argparse.ArgumentParser)]
else:
main_module = module.main.__globals__ if hasattr(module, 'main') else globals()
parsers = [v for i, v in chain(six.iteritems(main_module), six.iteritems(vars(module)))
if issubclass(type(v), argparse.ArgumentParser)]
if not parsers:
f = tempfile.NamedTemporaryFile()
ast_source = source_parser.parse_source_file(script_path)
Expand All @@ -194,8 +194,8 @@ def __init__(self, script_path=None, script_name=None):
if issubclass(type(v), argparse.ArgumentParser)]
if not parsers:
sys.stderr.write('Unable to identify ArgParser for {0}:\n'.format(script_path))
self.valid = False
return
self.valid = True
parser = parsers[0]
self.class_name = script_name
self.script_path = script_path
Expand Down

0 comments on commit 3a4e1de

Please sign in to comment.