Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UUID to 'temp' folder Fixes #28 #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions orpheus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ def update_module_storage(self): # Should be refactored eventually

def orpheus_core_download(orpheus_session: Orpheus, media_to_download, third_party_modules, separate_download_module, output_path):
downloader = Downloader(orpheus_session.settings['global'], orpheus_session.module_controls, oprinter, output_path)
os.makedirs('temp', exist_ok=True)
temp_UUID = f'temp{os.urandom(5).hex()}'
share_temp_UUID(temp_UUID)
os.makedirs(temp_UUID, exist_ok=True)

for mainmodule, items in media_to_download.items():
for media in items:
Expand Down Expand Up @@ -404,4 +406,4 @@ def orpheus_core_download(orpheus_session: Orpheus, media_to_download, third_par
else:
raise Exception(f'\tUnknown media type "{mediatype}"')

if os.path.exists('temp'): shutil.rmtree('temp')
if os.path.exists(temp_UUID): shutil.rmtree(temp_UUID)
10 changes: 7 additions & 3 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def silentremove(filename):
def read_temporary_setting(settings_location, module, root_setting=None, setting=None, global_mode=False):
temporary_settings = pickle.load(open(settings_location, 'rb'))
module_settings = temporary_settings['modules'][module] if module in temporary_settings['modules'] else None

if module_settings:
if global_mode:
session = module_settings
Expand All @@ -122,7 +122,7 @@ def read_temporary_setting(settings_location, module, root_setting=None, setting
else:
return session[root_setting] if root_setting in session else None
elif root_setting and not session:
raise Exception('Module does not use temporary settings')
raise Exception('Module does not use temporary settings')
else:
return session

Expand All @@ -146,7 +146,11 @@ def set_temporary_setting(settings_location, module, root_setting, setting=None,
session[root_setting] = value
pickle.dump(temporary_settings, open(settings_location, 'wb'))

create_temp_filename = lambda : f'temp/{os.urandom(16).hex()}'
def share_temp_UUID(UUID_value):
global temp_UUID
temp_UUID = UUID_value

create_temp_filename = lambda : f'{temp_UUID}/{os.urandom(16).hex()}'

def save_to_temp(input: bytes):
location = create_temp_filename()
Expand Down