Switch to output file name instead of full path

This commit is contained in:
Christophe Bedard 2019-10-12 18:00:25 -07:00
parent 8a0c3a4eb4
commit e23c2d62c1
2 changed files with 23 additions and 14 deletions

View file

@ -32,20 +32,27 @@ def parse_args():
'trace_directory', 'trace_directory',
help='the path to the main CTF trace directory') help='the path to the main CTF trace directory')
parser.add_argument( parser.add_argument(
'-o', '--output-file-path', dest='output_file_path', '-o', '--output-file-name', dest='output_file_name',
help='the path to the output file to generate ' default=DEFAULT_CONVERT_FILE_NAME,
f'(default: $trace_directory/{DEFAULT_CONVERT_FILE_NAME})') help='the name of the output file to generate, '
args = parser.parse_args() 'under $trace_directory (default: %(default)s)')
if args.output_file_path is None: return parser.parse_args()
args.output_file_path = os.path.join(args.trace_directory, DEFAULT_CONVERT_FILE_NAME)
return args
def convert( def convert(
trace_directory: str, trace_directory: str,
output_file_path: str, output_file_name: str = DEFAULT_CONVERT_FILE_NAME,
) -> None: ) -> None:
print(f'importing trace directory: {trace_directory}') """
Convert trace directory to a file.
The output file will be placed under the trace directory.
:param trace_directory: the path to the trace directory to import
:param outout_file_name: the name of the output file
"""
print(f'converting trace directory: {trace_directory}')
output_file_path = os.path.join(os.path.expanduser(trace_directory), output_file_name)
start_time = time.time() start_time = time.time()
count = ctf.convert(trace_directory, output_file_path) count = ctf.convert(trace_directory, output_file_path)
time_diff = time.time() - start_time time_diff = time.time() - start_time
@ -57,6 +64,6 @@ def main():
args = parse_args() args = parse_args()
trace_directory = args.trace_directory trace_directory = args.trace_directory
output_file_path = args.output_file_path output_file_name = args.output_file_name
convert(trace_directory, output_file_path) convert(trace_directory, output_file_name)

View file

@ -32,7 +32,7 @@ def parse_args():
'directory and output model data.') 'directory and output model data.')
parser.add_argument( parser.add_argument(
'input_path', 'input_path',
help='the path to a converted file to import, ' help='the path to a converted file to import and process, '
'or the path to a CTF directory to convert and process') 'or the path to a CTF directory to convert and process')
return parser.parse_args() return parser.parse_args()
@ -57,11 +57,13 @@ def main():
# Result could be unexpected because it will look for trace directories recursively # Result could be unexpected because it will look for trace directories recursively
if is_trace_directory(input_path): if is_trace_directory(input_path):
# Convert trace directory first to create converted file # Convert trace directory first to create converted file
convert(input_path, prospective_converted_file) convert(input_path, DEFAULT_CONVERT_FILE_NAME)
input_path = prospective_converted_file input_path = prospective_converted_file
else: else:
# We cannot do anything # We cannot do anything
print('cannot find either a trace directory or a converted file', file=sys.stderr) print(
f'cannot find either a trace directory or a converted file: {input_path}',
file=sys.stderr)
return 1 return 1
events = load_file(input_path) events = load_file(input_path)