From c3c0924cda186ff875709738498bf3c4c005299f Mon Sep 17 00:00:00 2001 From: Dipti Date: Tue, 9 Feb 2021 18:32:54 -0800 Subject: [PATCH] commented out broken code, added code so output_format and report_file exten. is passed in, exten is changed to csv to create file, then csv is changed to correct output format --- py-json/LANforge/lfcli_base.py | 6 +++--- py-json/realm.py | 10 ++++++---- py-scripts/test_ipv4_variable_time.py | 12 ++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/py-json/LANforge/lfcli_base.py b/py-json/LANforge/lfcli_base.py index 4954e829..643e57f1 100644 --- a/py-json/LANforge/lfcli_base.py +++ b/py-json/LANforge/lfcli_base.py @@ -633,9 +633,9 @@ class LFCliBase: if output_file_type == 'df': return df supported_formats = ['csv', 'json', 'stata', 'pickle','html'] - for format in supported_formats: - if output_file_type.lower() == format: - return exec('df.to_' + x + '("'+file_name'")') + #for format in supported_formats: + # if output_file_type.lower() == format: + # return exec('df.to_' + x + '("'+file_name'")') #takes any format of a file and returns a dataframe of it def file_to_df(file_type, file_name): diff --git a/py-json/realm.py b/py-json/realm.py index 8c687eb4..12ce23ea 100755 --- a/py-json/realm.py +++ b/py-json/realm.py @@ -1186,11 +1186,13 @@ class L3CXProfile(LFCliBase): raise ValueError("L3CXProfile::monitor wants a list of column names to monitor") if output_format is not None: if output_format.lower() != report_file.split('.')[-1]: - if output_format.lower() != 'csv': - raise ValueError('Filename %s does not match output format %s' % (report_file, output_format)) + raise ValueError('Filename %s has an extension that does not match output format %s .' % (report_file, output_format)) else: output_format = report_file.split('.')[-1] + #default save to csv first + if report_file.split('.')[-1] != 'csv': + report_file = report_file.replace(str(output_format),'csv',1) #retrieve compared report if specified - turn into dataframe === under construction === if compared_report is not None: @@ -1268,10 +1270,10 @@ class L3CXProfile(LFCliBase): csvfile.close() #here, do column manipulations - + #here, do df to final report file output if output_format.lower() != 'csv': - dataframe_output = self.file_to_df() + dataframe_output = self.file_to_df(report_file, output_format) diff --git a/py-scripts/test_ipv4_variable_time.py b/py-scripts/test_ipv4_variable_time.py index 30b79656..1842f546 100755 --- a/py-scripts/test_ipv4_variable_time.py +++ b/py-scripts/test_ipv4_variable_time.py @@ -268,21 +268,17 @@ python3 ./test_ipv4_variable_time.py except: curr_dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) path = os.path.join(curr_dir_path, new_file_path) - os.mkdir(path) - print('Saving file to ' + path) - + os.mkdir(path) if args.output_format in ['csv','json','html','hdf','stata','pickle','pdf','png','df','parquet','xlsx']: - #always save to csv first - report_f= str(path) + '/data.csv' - #report_f= str(path) + '/data.' + args.output_format - print(report_f) + report_f= str(path) + '/data.' + args.output_format output=args.output_format else: print('Defaulting to csv data file output type, naming it data.csv.') report_f= str(path)+'/data.csv' - print(report_f) output='csv' + if self.debug: + print("Saving report data in ... " + report_f) else: report_f=args.report_file if args.output_format is None: