forked from ppamidimarri/TeslaCamMerge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadSSD.py
executable file
·57 lines (45 loc) · 1.5 KB
/
LoadSSD.py
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
#!/usr/bin/env python3
# This script moves files placed in the "SHARE_PATH" location to the
# "RAW_PATH" location. I use it to pick up files placed in a
# CIFS share by teslausb and move them to a Samsung T5 SSD.
import os
import time
import shutil
import re
import TCMConstants
logger = TCMConstants.get_logger()
def main():
if not have_required_permissions():
logger.error("Missing some required permissions, exiting")
TCMConstants.exit_gracefully(TCMConstants.SPECIAL_EXIT_CODE, None)
while True:
for root, dirs, files in os.walk(TCMConstants.SHARE_PATH, topdown=False):
for name in files:
if file_has_proper_name(name):
move_file(os.path.join(root, name))
else:
logger.warn("File '{0}' has invalid name, skipping".format(name))
time.sleep(TCMConstants.SLEEP_DURATION)
### Startup functions ###
def have_required_permissions():
return TCMConstants.check_permissions(
TCMConstants.SHARE_PATH, True) and TCMConstants.check_permissions(
TCMConstants.RAW_PATH, True)
### Loop functions ###
def move_file(file):
logger.info("Moving file {0}".format(file))
if TCMConstants.check_file_for_read(file):
try:
shutil.move(file, TCMConstants.RAW_PATH)
logger.debug("Moved file {0}".format(file))
except:
logger.error("Failed to move {0}".format(file))
else:
logger.debug("File {0} still being written, skipping for now".format(file))
def file_has_proper_name(file):
if TCMConstants.FILENAME_PATTERN.match(file):
return True
else:
return False
if __name__ == '__main__':
main()