|
6 | 6 | import datetime |
7 | 7 | from cli.cli_file_writer import CliFileWriter |
8 | 8 | from cli.formatter.cli_json_formatter import CliJsonFormatter |
| 9 | +from constants import CALLED_SCRIPT |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class CliCaller: |
@@ -96,9 +97,27 @@ def get_processed_output_path(self): |
96 | 97 | if output_path.startswith('/') is True: # Given path is absolute |
97 | 98 | final_output_path = output_path |
98 | 99 | else: |
99 | | - prepared_file_path = os.path.dirname(os.path.realpath(__file__)).split('/')[:-2] + [self.cli_output_folder] |
| 100 | + path_parts = os.path.dirname(os.path.realpath(__file__)).split('/')[:-2] |
| 101 | + called_script_dir = os.path.dirname(CALLED_SCRIPT) |
| 102 | + # It's about a case when user is calling script from not root directory.€ |
| 103 | + if called_script_dir != 'vxapi.py': |
| 104 | + new_path_parts = [] |
| 105 | + bad_parts = called_script_dir.split('/') |
| 106 | + for part in reversed(path_parts): |
| 107 | + if part in bad_parts: |
| 108 | + bad_parts.remove(part) |
| 109 | + continue |
| 110 | + new_path_parts.append(part) |
| 111 | + |
| 112 | + new_path_parts.reverse() |
| 113 | + path_parts = new_path_parts |
| 114 | + |
| 115 | + prepared_file_path = path_parts + [self.cli_output_folder] |
100 | 116 | final_output_path = '/'.join(prepared_file_path) |
101 | 117 |
|
| 118 | + if not final_output_path.startswith('/'): |
| 119 | + final_output_path = '/' + final_output_path |
| 120 | + |
102 | 121 | return final_output_path |
103 | 122 |
|
104 | 123 | def get_result_msg_for_files(self): |
@@ -136,4 +155,4 @@ def save_files(self): |
136 | 155 |
|
137 | 156 | filename = '{}-{}-{}'.format(self.action_name, identifier, api_response.headers['Vx-Filename']) if identifier is not None else '{}-{}'.format(self.action_name, api_response.headers['Vx-Filename']) |
138 | 157 |
|
139 | | - return CliFileWriter.write(self.cli_output_folder, filename, api_response.content) |
| 158 | + return CliFileWriter.write(self.get_processed_output_path(), filename, api_response.content) |
0 commit comments