-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_meta_files.py
More file actions
59 lines (48 loc) · 1.63 KB
/
generate_meta_files.py
File metadata and controls
59 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import sys
from concurrent.futures import ThreadPoolExecutor
from mtlogger import logger
from _common import exit_with_prompt, print_error
from _sound_utils import play_notification_sound
META_FILES = ['.noxml', '.nomedia']
def main():
if len(sys.argv) > 1:
process_parent_folder(sys.argv[1])
else:
prompt_parent_folder()
def prompt_parent_folder():
parent_folder = input('Enter the path to the image you want to generate the metadata files for:\n')
if not parent_folder:
return
if not os.path.isdir(parent_folder):
logger.error(f'The specified path "{parent_folder}" is not a directory.')
else:
process_parent_folder(parent_folder)
play_notification_sound()
exit_with_prompt()
def process_parent_folder(parent_folder):
folders_to_process = [parent_folder]
with os.scandir(parent_folder) as entries:
for entry in entries:
if entry.is_dir():
folders_to_process.append(entry.path)
with ThreadPoolExecutor(max_workers=1) as executor:
executor.map(process_folder, folders_to_process)
def process_folder(folder_path):
for filename in META_FILES:
try:
file_path = os.path.join(folder_path, filename)
if os.path.exists(file_path):
logger.debug(f'Skipping "{file_path}". File already exists.')
else:
open(file_path, 'w').close()
os.system(f'attrib +h "{file_path}"')
logger.log(f'Successfully created hidden file "{file_path}".')
except Exception as ex:
logger.error(f'Could not create "{filename}": {ex}')
if __name__ == '__main__':
try:
main()
except Exception as ex:
print_error(ex)
exit_with_prompt()