# Path: djangui/backend/ast/source_parser.py
# def parse_source_file(file_name):
# def read_client_module(filename):
# def get_node_args_and_keywords(assigned_objs, assignments, selector=None):
# def get_nodes_by_instance_type(nodes, object_type):
# def get_nodes_by_containing_attr(nodes, attr):
# def walk_tree(node):
# def convert_to_python(ast_source):


import argparse
import sys
import json
import imp
import traceback
import tempfile
import six
import copy
    import io
from collections import OrderedDict
from .ast import source_parser
from itertools import chain
        django_kwargs = {}
        if self.node_attrs['model'] == 'CharField':
            django_kwargs['max_length'] = 255
        django_kwargs['blank'] = not self.node_attrs['required']
        try:
            django_kwargs['default'] = self.node_attrs['value']
        except KeyError:
            pass
        return u'{0} = {1}.{2}({3})'.format(self.node_attrs['name'], field_module, self.node_attrs['model'],
                                           ', '.join(['{0}={1}'.format(i,v) for i,v in six.iteritems(django_kwargs)]),)


class ArgParseNodeBuilder(object):
    def __init__(self, script_path=None, script_name=None):
        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)
        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)

# Path: djangui/backend/ast/source_parser.py
# def parse_source_file(file_name):
# def read_client_module(filename):
# def get_node_args_and_keywords(assigned_objs, assignments, selector=None):
# def get_nodes_by_instance_type(nodes, object_type):
# def get_nodes_by_containing_attr(nodes, attr):
# def walk_tree(node):
# def convert_to_python(ast_source):


# Path: djangui/backend/argparse_specs.py
import argparse
import sys
import json
import imp
import traceback
import tempfile
import six
import copy
    import io
from collections import OrderedDict
from .ast import source_parser
from itertools import chain

        django_kwargs = {}
        if self.node_attrs['model'] == 'CharField':
            django_kwargs['max_length'] = 255
        django_kwargs['blank'] = not self.node_attrs['required']
        try:
            django_kwargs['default'] = self.node_attrs['value']
        except KeyError:
            pass
        return u'{0} = {1}.{2}({3})'.format(self.node_attrs['name'], field_module, self.node_attrs['model'],
                                           ', '.join(['{0}={1}'.format(i,v) for i,v in six.iteritems(django_kwargs)]),)


class ArgParseNodeBuilder(object):
    def __init__(self, script_path=None, script_name=None):
        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)
        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)

            python_code = source_parser.convert_to_python(list(ast_source))