diff options
Diffstat (limited to 'domestic/make/make_file.py')
-rw-r--r-- | domestic/make/make_file.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/domestic/make/make_file.py b/domestic/make/make_file.py new file mode 100644 index 0000000..0fb7f6e --- /dev/null +++ b/domestic/make/make_file.py @@ -0,0 +1,18 @@ +from domestic.utility.status_message import * +from domestic.make.make_directories import * +from domestic.utility.get_filename import * +from domestic.global_state import * + + +def make_file(directories, file_type, data, success_message=None): + filename = get_filename(file_type) + username = state['session']['username'] + path = f'{state["root"]}/{username}/{directories[-1]}/{filename}' + directories_to_make = [username] + [f'{username}/{directory}' for directory in directories] + make_directories(directories_to_make) + + with open(path, 'wb') as f: + f.write(data) + + if success_message: + status_message(f'Path: {path}\n{success_message}', 'success')
\ No newline at end of file |