Example #1
0
def __create_tool__(catagory, tool_name):

    config = __validate_config__()
    data_dir = config[Data.SECTION][Data.ALL][config[Data.SECTION][Data.CURRENT]]
    project = config[Project.SECTION][Project.CURRENT]

    new_cat_path = create_path([emel_tools_file_path(), catagory])

    if catagory not in __get_catagories__(False):
        choice = yes_no_option('"{0}" is not a catagory. Would you like to create it ?'.format(catagory))
        if choice:
            create_dir(new_cat_path, verbose=True)
            create_marker(new_cat_path, '__init__.py')
        else:
            print '[WARNING] emel did not create {0}->{1}. user aborted.'.format(catagory, tool_name)
            exit()

    if os.path.exists(create_path([new_cat_path, tool_name + '.py'])):
       print '[WARNING] {0}->{1} all ready exists.'.format(catagory, tool_name)
       exit()

    fp = open( create_path([new_cat_path, tool_name+'.py']), 'w' )
    fp.write( TOOL_TEMPLATE.format(EMEL_UTILS_FILE, tool_name, re.sub('\\\\', '/', new_cat_path)) )
    fp.close()

    # add tool to the __init__.py in the tools folder.
    fp = open( create_path([emel_tools_file_path(), '__init__.py']), 'a')
    fp.write( 'import {}.{}\n'.format(catagory, tool_name) )
    fp.close()

    print 'Created a new tool at {0}/{1}.py'.format(re.sub('\\\\', '/',new_cat_path), tool_name)
    if yes_no_option('Would you like to edit the tool now?'):
        __run_editor__([os.path.join(new_cat_path, tool_name + '.py')])
Example #2
0
def __create_dep_list__(check_first=True):
    if not check_directory_status(True):
        exit()
    if not check_project_status(True):
        exit()
    create = True
    if check_first:
        message = 'Creatint dependency file for project.\n [WARNING] will overrite existing file. Continue?'
        create = yes_no_option(message)

    if create:
        depFile = create_path([emel_project_path(), DEPENDENCY_FILE])
        with open(depFile, 'w') as f:
            f.write('# emel default packages #\n')
            for module in DEFULT:
                f.write(module)
                f.write('\n')
            f.write('# End emel defaults #')
Example #3
0
def __create_train__():
    message = ('[WARNING] This will destroy any existing train objects. Continue?')
    go = yes_no_option(message)
    if go:
        trainPath = emel_train_file_path()
        train_object = TRAIN_TEMPLATE.format(EMEL_UTILS_FILE)

        print 'Creating default train order ...',
        with open(create_path([trainPath, TRAIN_ORDER_NAME]), 'w') as fp:
            fp.write(DEFAULT_TRAIN_LIST)
        print 'Done.'

        print 'Creating train object ...',
        with open( create_path([trainPath, TRAIN_OBJECT_NAME]), 'w' ) as fp:
            fp.write(train_object)
        create_marker( trainPath, INIT_MARKER )
        print 'Done.'
    else:
        print 'Aborting'
Example #4
0
def __install_dependencies__(verbose=False):
    message = ('[WARNING] This will install all listed dependencies.\n'
               'Please make sure you are sudo.')
    go = yes_no_option(message)
    if go:
        installer = __get_installer__()

        for module in __get_list__():
            print '\n*****Installing:', module,'*****\n'
            if __sanitize_moduel__(module):
                status = subprocess.call([installer, 'install', module])
                if status != 0:
                    print '\n*****Failed to install', module,'*****'
                else:
                    print '\n*****Successflly installed', module,'*****'
            else:
                print 'Rejecting', module
    else:
        print 'Aborting.'
Example #5
0
def create_dir(directory, interactive=False, force=False, verbose=False):
    '''
    creates a new directory if one does not already exist.
    directory, the path to where you want to create the directory
    interactive, if a directory already exists, ask the user if they want to create a directory with the same name
                but with a (i) next to it.
    force, same as interactive but does not ask the user. 
    '''
    if not os.path.isdir(directory):
        if verbose: print 'Creating "{0}"'.format(directory)
        os.makedirs(directory)
        return directory
    else:
        verbose = force or interactive if force or interactive else verbose
        if verbose: print 'Directory "{0}" already exists'.format(directory)
        newDirectoryFormat='{0}({1})'
        if interactive or force:
            i = 1
            while os.path.isdir( newDirectoryFormat.format(directory, i) ): 
                print 'Directory "{0}" already exists'.format(newDirectoryFormat.format(directory, i))
                i += 1

            newDirectory = newDirectoryFormat.format(directory, i)
            
            choice = yes_no_option('Would you like to create "{0}"?'.format(newDirectory)) if interactive else True

            if choice:
                if verbose: print 'Creating "{0}"'.format(newDirectory)
                os.makedirs(newDirectory)
                return newDirectory
            else:
                print 'emel failed to create "{0}"'.format(directory)
        else:
            print 'emel failed to create "{0}"'.format(directory)

        return None