Exemple #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')])
Exemple #2
0
def __create_directory__(data_tuple, setAsCurrent=True, create=True, islocation=True):
    '''
    Sets the location of the data directory in the emel.config file.
    '''
    config = __validate_config__()
    data_tuple = data_tuple if isinstance(data_tuple, list) else [data_tuple]
    if not data_tuple:
        print '[ERROR] Please supply a lable for this data directory.'
        exit()
    
    lable = data_tuple[0]
    location = create_path([data_tuple[1],lable]) if len(data_tuple) > 1 else create_path([os.getcwd(), lable])

    if create: 
        print 'Attempting to create', lable, 'at location', location, 
        current = create_dir(location, True, True)
        if current:
            create_marker(current, Data.MARKER)
            create_marker(current, INIT_MARKER)
        if not os.path.isdir(location):
            print '\n[ERROR] "{0}" is not a valid path.'.format(location)
            exit()

    if current and setAsCurrent: config[Data.SECTION][Data.CURRENT] = lable
    if current and lable not in config[Data.SECTION][Data.ALL]: config[Data.SECTION][Data.ALL][lable] = location
    print 'Done.'

    config.write()
Exemple #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'
Exemple #4
0
def __new_project__(newProject):
    '''
    Creates a new project in the current data directory.
    '''
    config = __validate_config__()
    
    if newProject in __list_projects__():
        print '"', newProject, '" allready exists'
        exit()

    config[Project.SECTION][Project.CURRENT] = newProject
    config.write()
    
    dataDir = config[Data.SECTION][Data.CURRENT] 
    projectDir = create_path([dataDir, newProject])
    create_dir(projectDir)
    create_marker( projectDir, Project.MARKER )
    create_marker( projectDir, INIT_MARKER )

    # Create all nessesary folders.
    create_dir(emel_raw_file_path(), verbose=True)
    create_dir(emel_processed_file_path(), verbose=True)
    create_dir(emel_train_file_path(), verbose=True)
    create_dir(emel_tools_file_path(), verbose=True)

    # Create nessesary tool dirs in the project/tools folder.
    create_marker(emel_tools_file_path(), '__init__.py')
 
    print '"{0}" Successfully created.'.format(newProject)