Skip to content

Commit

Permalink
get_full_file_path refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Zvonimir Sabljic committed Oct 1, 2023
1 parent 5af4ce1 commit 6c571f0
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions pilot/helpers/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,64 @@ def save_file(self, data):
.execute())

def get_full_file_path(self, file_path: str, file_name: str) -> Tuple[str, str]:
file_path = file_path.replace('./', '', 1)
file_path = os.path.dirname(file_path)
file_name = os.path.basename(file_name)

paths = [file_name]
# WINDOWS
are_windows_paths = '\\' in file_path or '\\' in file_name or '\\' in self.root_path
if are_windows_paths:
file_name = file_name.replace('\\', '/')
file_path = file_path.replace('\\', '/')
# END WINDOWS

# Universal modifications
file_path = file_path.replace('~', '')
file_name = file_name.replace('~', '')

file_path = file_path.replace(self.root_path, '')
file_name = file_name.replace(self.root_path, '')

if '.' not in file_path and not file_path.endswith('/'):
file_path += '/'
if '.' not in file_name and not file_name.endswith('/'):
file_name += '/'

if '/' in file_path and not file_path.startswith('/'):
file_path = '/' + file_path
if '/' in file_name and not file_name.startswith('/'):
file_name = '/' + file_name
# END Universal modifications

head_path, tail_path = os.path.split(file_path)
head_name, tail_name = os.path.split(file_name)

final_file_path = head_path if head_path != '' else head_name
final_file_name = tail_name if tail_name != '' else tail_path

if head_path in head_name:
final_file_path = head_name
elif final_file_path != head_name:
if head_name not in head_path and head_path not in head_name:
if '.' in file_path:
final_file_path = head_name + head_path
else:
final_file_path = head_path + head_name

if file_path != '':
paths.insert(0, file_path)
if final_file_path == '':
final_file_path = '/'

if file_path == '/':
absolute_path = file_path + file_name
else:
if not re.match(r'^/|~|\w+:', file_path):
paths.insert(0, self.root_path)
absolute_path = '/'.join(paths)
final_absolute_path = self.root_path + final_file_path + '/' + final_file_name

if '//' in final_absolute_path:
final_absolute_path = final_absolute_path.replace('//', '/')
if '//' in final_file_path:
final_file_path = final_file_path.replace('//', '/')

# WINDOWS
if are_windows_paths:
final_file_path = final_file_path.replace('/', '\\')
final_absolute_path = final_absolute_path.replace('/', '\\')
# END WINDOWS

return file_path, absolute_path
return final_file_path, final_absolute_path

def save_files_snapshot(self, development_step_id):
files = get_files_content(self.root_path, ignore=IGNORE_FOLDERS)
Expand Down

0 comments on commit 6c571f0

Please sign in to comment.