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')])
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)
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()
def __run_current_train__(): config = __validate_config__() trainPath = emel_train_file_path() # Create a backup train folder folderName = datetime.now().strftime(TRAIN_BKUP_TEMPlATE) backupPath = create_dir(create_path([trainPath, folderName])) print 'Creating backup folder "{}" ...'.format(backupPath), print 'Done.' if backupPath: config[BACKUP] = backupPath trainOrderPath = create_path([trainPath, TRAIN_ORDER_NAME]) trainObjectPath = create_path([trainPath, TRAIN_OBJECT_NAME]) # copy over the train order and train object files. print 'Backing up the train order ...', subprocess.call(['cp', trainOrderPath, backupPath]) print 'Done.' print 'Backing up train object ...', subprocess.call(['cp', trainObjectPath, backupPath]) print 'Done.' train_order = imp.load_source('train_order', trainOrderPath) train_object = imp.load_source('train', trainObjectPath) train = train_object.Train() f = open(create_path([backupPath, 'time.txt']), 'w') for function in train_order.order: print 'Running', function start = datetime.now() getattr(train, function)(**train_order.args[function]) f.write('Function "{}" (Took: {})\n'.format(function, datetime.now() - start)) f.close() else: print '[ERROR] Could not create backup train folder.'