def make_paths(tmp_dir, paths_end): complete_paths = [] for path_end in paths_end: complete_path = os.path.join(tmp_dir, path_end) makedirs(complete_path) complete_paths.append(complete_path) return complete_paths
def main(): parser = argparse.ArgumentParser() parser.add_argument('file') args = vars(parser.parse_args()) config_file = op.abspath(args['file']) paths.CONFIG_DIR = op.dirname(config_file) log_dir = op.join(paths.CONFIG_DIR, 'output/%s/' % time.strftime('%Y.%m.%d_%H%M%S')) makedirs(log_dir) paths.OUTPUT_DIR = log_dir log_filename = op.join(log_dir, 'experiment.log') logger = logging.getLogger() logger.setLevel(logging.DEBUG) file_logger = logging.FileHandler(log_filename) file_logger.setLevel(logging.DEBUG) file_logger.setFormatter( logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s')) logger.addHandler(file_logger) stdout_logger = logging.StreamHandler(sys.stdout) stdout_logger.setLevel(logging.INFO) stdout_logger.setFormatter(logging.Formatter('%(name)s: %(message)s')) logger.addHandler(stdout_logger) sys.path.append(op.join(paths.ROOT_DIR, 'ExperimentRunner')) try: experiment = ExperimentFactory.from_json(config_file) experiment.start() except Exception, e: logger.error('%s: %s' % (e.__class__.__name__, e.message))
def setup_paths(config_file, log_dir): paths.CONFIG_DIR = op.dirname(config_file) paths.ORIGINAL_CONFIG_DIR = config_file makedirs(log_dir) paths.OUTPUT_DIR = log_dir paths.BASE_OUTPUT_DIR = log_dir sys.path.append(op.join(paths.ROOT_DIR, 'ExperimentRunner'))
def set_dirs(self, device, profiler_name): self.dirs['subject'] = os.path.join(self.output_root, 'data', device.name, 'test_dir_1', 'test_dir_2', profiler_name) self.dirs['aggregated'] = os.path.join( paths.OUTPUT_DIR, '{}_aggregated.csv'.format(profiler_name)) self.dirs['data_folder'] = os.path.join(paths.OUTPUT_DIR, 'data') makedirs(self.dirs['subject'])
def test_makedirs_fail(self, tmpdir): os.chmod(str(tmpdir), 0444) dir_path = op.join(str(tmpdir), 'test2') assert op.isdir(dir_path) is False with pytest.raises(OSError) as except_result: util.makedirs(dir_path) assert "Permission denied" in except_result.value assert op.isdir(dir_path) is False
def test_list_dir_non_empty(self, tmpdir, android_test_plugin_handler): tmpdir = os.path.join(str(tmpdir), 'test') makedirs(tmpdir) os.makedirs(os.path.join(tmpdir, '1')) os.makedirs(os.path.join(tmpdir, '2')) sub_dirs = android_test_plugin_handler.list_subdir(tmpdir) assert len(sub_dirs) == 2 assert '1' in sub_dirs assert '2' in sub_dirs
def test_makedirs_fail_already_exist(self, tmpdir): dir_path = op.join(str(tmpdir), 'test1') assert op.isdir(dir_path) is False util.makedirs(dir_path) util.makedirs(dir_path) assert op.isdir(dir_path) is True files_in_path = [f for f in os.listdir(str(tmpdir)) if os.path.isdir(os.path.join(str(tmpdir), f))] assert len(files_in_path) == 1
def test_setup_paths(self, tmpdir): temp_config_dir = op.join(str(tmpdir), 'config') makedirs(temp_config_dir) temp_config_file = op.join(temp_config_dir, 'config.json') open(temp_config_file, "w+") temp_log_dir = op.join(str(tmpdir), 'log') main.setup_paths(temp_config_file, temp_log_dir) assert paths.CONFIG_DIR == op.dirname(temp_config_file) assert op.isdir(temp_log_dir) assert paths.OUTPUT_DIR == temp_log_dir assert paths.BASE_OUTPUT_DIR == temp_log_dir assert op.join(paths.ROOT_DIR, 'ExperimentRunner') in sys.path
def main(): parser = argparse.ArgumentParser() parser.add_argument('file') parser.add_argument('--progress', default=argparse.SUPPRESS) args = vars(parser.parse_args()) config_file = op.abspath(args['file']) paths.CONFIG_DIR = op.dirname(config_file) paths.ORIGINAL_CONFIG_DIR = config_file if 'progress' in args: progress = Progress(progress_file=args['progress'], config_file=config_file, load_progress=True) log_dir = progress.get_output_dir() else: log_dir = op.join(paths.CONFIG_DIR, 'output/%s/' % time.strftime('%Y.%m.%d_%H%M%S')) progress = None makedirs(log_dir) paths.OUTPUT_DIR = log_dir paths.BASE_OUTPUT_DIR = log_dir log_filename = op.join(log_dir, 'experiment.log') logger = logging.getLogger() logger.setLevel(logging.DEBUG) file_logger = logging.FileHandler(log_filename) file_logger.setLevel(logging.DEBUG) file_logger.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s')) logger.addHandler(file_logger) stdout_logger = logging.StreamHandler(sys.stdout) stdout_logger.setLevel(logging.INFO) stdout_logger.setFormatter(logging.Formatter('%(name)s: %(message)s')) logger.addHandler(stdout_logger) sys.path.append(op.join(paths.ROOT_DIR, 'ExperimentRunner')) progress_file = ' No progress file created' try: experiment = ExperimentFactory.from_json(config_file, progress) progress_file = experiment.get_progress_xml_file() experiment.start() except Exception, e: logger.error('%s: %s' % (e.__class__.__name__, e.message)) logger.error('An error occurred, the experiment has been stopped. ' 'To continue, add progress file argument to experiment startup: ' '--progress {}'.format(progress_file))
def test_list_dir_empty(self, tmpdir, android_test_plugin_handler): tmpdir = os.path.join(str(tmpdir), 'test') makedirs(tmpdir) assert android_test_plugin_handler.list_subdir(tmpdir) == []
def test_makedirs_succes(self, tmpdir): dir_path = op.join(str(tmpdir), 'test1') assert op.isdir(dir_path) is False util.makedirs(dir_path) assert op.isdir(dir_path) is True