<commit_before>import pdb
import sys
import cmd
import argparse
import importlib

from utils import pretty_xml, pretty_json

from myql import MYQL
from myql.contrib.table import TableMeta

__author__  = '<NAME>'
__email__   = '<EMAIL>'
__version__ = '0.2.3'


########################################################
#
#           COMMAND LINE QUERIES HANDLER
#
########################################################

class ExecuteAction(argparse.Action):
    '''Action performed for Execute command
    '''
    def __call__(self, parser, namespace, value, option_string=None):

        attr = {
            'community': True,
            'format': namespace.format,
            'jsonCompact': namespace.jsonCompact,
            'debug': namespace.debug,
        }

        yql = MYQL(**attr)
        yql.diagnostics = namespace.diagnostics

        response = yql.rawQuery(value)

        if not response.status_code == 200:
            print(response.content)
            sys.exit(1)

        if namespace.format == 'json':
            print(pretty_json(response.content))
        else:
            print(pretty_xml(response.content))
        sys.exit(0)

############################################################
#
#                   SHELL QUERIES HANDLER
#
############################################################

class ShellAction(argparse.Action):
    '''Action performed for shell command
    '''
    def __call__(self, parser, namespace, value, option_string=None):
        pass

class ShellCmd(cmd.Cmd):
    pass
############################################################
#
#                   YQL TABLE HANDLER
#
###########################################################

class TableAction(argparse.Action):
    '''Action performed for Table command
    '''
    def __call__(self, parser, namespace, value, option_string=None):

        if namespace.init and namespace.create:
            print("Optional arguments --init and --create can't be used together")
            sys.exit(1)

        if namespace.create :
            module_name = value
            module = importlib.import_module(module_name)
            import pdb
            pdb.set_trace()
            tables = [ v for k,v in module.__dict__.items() if isinstance(v, TableMeta) and k != 'TableModel']

            for table in tables :
                print pretty_xml(table.toxml())
                table_name = table.table.name
                print(table_name)
                table.table.save(name=table_name, path='.')

            sys.exit(0)<commit_msg>#4 : --init and --path working<commit_after>import os, sys
import cmd
import argparse
import importlib

from utils import pretty_xml, pretty_json

from myql import MYQL
from myql.contrib.table import TableMeta

__author__  = '<NAME>'
__email__   = '<EMAIL>'
__version__ = '0.2.3'


########################################################
#
#           COMMAND LINE QUERIES HANDLER
#
########################################################

class ExecuteAction(argparse.Action):
    '''Action performed for Execute command
    '''
    def __call__(self, parser, namespace, value, option_string=None):

        attr = {
            'community': True,
            'format': namespace.format,
            'jsonCompact': namespace.jsonCompact,
            'debug': namespace.debug,
        }

        yql = MYQL(**attr)
        yql.diagnostics = namespace.diagnostics

        response = yql.rawQuery(value)

        if not response.status_code == 200:
            print(response.content)
            sys.exit(1)

        if namespace.format == 'json':
            print(pretty_json(response.content))
        else:
            print(pretty_xml(response.content))
        sys.exit(0)

############################################################
#
#                   SHELL QUERIES HANDLER
#
############################################################

class ShellAction(argparse.Action):
    '''Action performed for shell command
    '''
    def __call__(self, parser, namespace, value, option_string=None):
        pass

class ShellCmd(cmd.Cmd):
    pass
############################################################
#
#                   YQL TABLE HANDLER
#
###########################################################

class TableAction(argparse.Action):
    '''Action performed for Table command
    '''
    def __call__(self, parser, namespace, value, option_string=None):

        if namespace.init and namespace.create:
            print("Optional arguments --init and --create can't be used together")
            sys.exit(1)

        if namespace.create :
            module_name = value
            module = importlib.import_module(module_name)
            tables = [ v for k,v in module.__dict__.items() if isinstance(v, TableMeta) and k != 'TableModel']

            for table in tables :
                table_name = table.table.name
                table.table.save(name=table_name, path='.')

            sys.exit(0)

        if namespace.init :
            folder = os.path.join(namespace.path if namespace.path else '.','opentable')
            folder = os.path.realpath(folder)

            if os.path.isdir(folder):
                print("{0} already exists".format(folder))
                sys.exit(1)

            os.mkdir(folder,0755)
            sys.exit(0)

        sys.exit(1)
{'fraction_non_alphanumeric': 0.22022808001495606, 'fraction_numerical': 0.00542157412600486, 'mean_word_length': 2.55718085106383, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1006450', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1352, 'n_words': 329}