Esempio n. 1
0
def __edit_older_train__():
    trainPath = emel_train_file_path()

    all_files = os.listdir(trainPath)
    all_files = [f for f in all_files if f.startswith('Train_')]

    print 'Please choos a folder to edit.'
    print '\tq - quit'
    for i, j in enumerate(all_files):
        print '\t', i, '-',j 

    choice = ''
    valid_choices = ['q'] + [str(i) for i in range(len(all_files))]
    while choice not in valid_choices:
        choice = raw_input('[ ')
        if choice == 'q':
            print 'User aborted'
            exit()
        elif choice in [str(i) for i in range(len(all_files))]:
            choice = int(choice)
            trainOrder = os.path.join(trainPath, all_files[choice], TRAIN_ORDER_NAME)
            trainObject = os.path.join(trainPath, all_files[choice], TRAIN_OBJECT_NAME)
            
            __run_editor__([trainOrder, trainObject])
            exit()
        else:
            print 'Invalid choice.'
Esempio n. 2
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')])
Esempio n. 3
0
def __edit_dependency__():
    depFile = create_path([emel_project_path(), DEPENDENCY_FILE])
    if not os.path.exists(depFile):
        print 'dependency file not created.'
        print 'please run emel.py dependency -h for more help'
        exit()
    __run_editor__([depFile])
Esempio n. 4
0
def __edit_current_train__(show='both'):
    trainPath = emel_train_file_path()
    trainOrder = create_path([trainPath, TRAIN_ORDER_NAME])
    trainObject = create_path([trainPath, TRAIN_OBJECT_NAME])

    if not os.path.exists(trainOrder):
        print '[ERROR] Could not find {}.'.format(TRAIN_ORDER_NAME)
        print 'please run train -n first.'

    if not os.path.exists(trainObject):
        print '[ERROR] Could not find {}.'.format(TRAIN_OBJECT_NAME)
        print 'please run train -n first.'

    to_open = []
    if show == 'both':
        to_open = [trainOrder, trainObject]
    if show == 'order':
        to_open = [trainOrder]
    if show == 'object':
        to_open = [trainObject]

    __run_editor__(to_open)
Esempio n. 5
0
def __edit_tool__(pattern):
    config = __validate_config__()
    data_dir = config[Data.SECTION][Data.ALL][config[Data.SECTION][Data.CURRENT]]
    project = config[Project.SECTION][Project.CURRENT]

    tools_path = emel_tools_file_path()
    regex = re.compile(pattern)

    tools = []
    append_tools = tools.append
    for root, d, files in os.walk(tools_path):
        files = [f for f in files if not f.startswith('__')]
        for f in files:
            if regex.search(f):
                append_tools(os.path.join(root, f))
    if not tools:
        print 'Did not find any tools matching the pattern', pattern
    else:
        tools = [tool for tool in tools if tool.endswith('.py')]
        if len(tools) == 1:
            __run_editor__(tools)
        else:
            print 'Found (', len(tools), ') matching the pattern "', pattern, '"'
            print 'Please choose:'
            print 'a - all'
            print 'q - cancel'
            for i, j in enumerate(tools):
                print i,'-', j

            choice = ''
            while choice not in ['a', 'q'] + [str(i) for i in range(len(tools))]:
                choice = raw_input('[ ')
                if choice == 'q':
                    print 'User aborted.'
                    exit()
                elif choice == 'a':
                    __run_editor__(tools)
                elif choice in [str(i) for i in range(len(tools))]:
                    __run_editor__([tools[int(choice)]])