-
Notifications
You must be signed in to change notification settings - Fork 38
/
rw_auto_copy.py
54 lines (45 loc) · 1.41 KB
/
rw_auto_copy.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
#!/usr/bin/env python3
import argparse
import os
import os.path
import errno
import shutil
import time
from datetime import datetime
from libs import config
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Rainwave Power Hour generation script."
)
parser.add_argument("--config", default=None)
args = parser.parse_args()
config.load(args.config)
now = datetime.now()
upcoming = os.path.join(
"~upcoming",
"{}-{month:02d}-{day:02d}".format(now.year, month=now.month, day=now.day),
)
source = os.path.join(config.get("monitor_dir"), upcoming)
if not os.path.isdir(source):
print("No songs for {}".format(source))
else:
for root, subdirs, files in os.walk(source, followlinks=True):
if root == source:
continue
directory_to = root.replace("{}{}".format(upcoming, os.sep), "")
mkdir_p(directory_to)
print(directory_to)
time.sleep(10)
for f in files:
f_from = os.path.join(root, f)
f_to = os.path.join(directory_to, f)
print(" {}".format(f_to))
shutil.move(f_from, f_to)