-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuller.py
More file actions
executable file
·70 lines (57 loc) · 1.94 KB
/
puller.py
File metadata and controls
executable file
·70 lines (57 loc) · 1.94 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
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import re
import subprocess
import sys
from renamer.logconfig import logger
ENDINGS = {"mkv", "avi", "mp4"}
def getMatcherString(entry):
result = re.sub("^[Tt]he*", "", entry)
result = result.lstrip()
result = re.sub("\s", ".", result)
logger.debug("converted to regex: " + result)
return re.compile(result, re.IGNORECASE)
def findDestDirectory(base, entries):
logger.info("finding dest-directory for " + base)
logger.debug(entries)
for name, e in entries.iteritems():
match = e.search(base)
if match is not None:
logger.info("found match for " + base + ": " + name)
return name
def main():
host = None
if len(sys.argv) == 4:
host = sys.argv[1]
remotedir = sys.argv[2]
lookupdir = sys.argv[3]
elif len(sys.argv) == 3:
remotedir = sys.argv[1]
lookupdir = sys.argv[2]
else:
print("missing merge-path")
sys.exit(2)
entries = os.listdir(lookupdir)
patterns = dict([(e, getMatcherString(e)) for e in entries])
logger.debug(patterns.keys())
logger.debug("Counted %s new files." % len(newFiles))
for f in newFiles:
base = os.path.basename(f)
series = findDestDirectory(base.rstrip(), patterns)
if series is None:
logger.warn("nothing found for " + f)
continue
dest = os.path.join(lookupdir, series)
if host is None:
source = f
else:
source = "%s:\"%s\"" % (host, f)
# command = ["rsync", "-hv", "--progress", "--remove-source-files", source , dest]
command = ["cp", source, dest]
logger.debug(" ".join(command))
retcode = subprocess.call(command)
subprocess.call([os.path.join(sys.path[0], "./rename.py"), dest])
subprocess.call([os.path.join(sys.path[0], "./sorter.py"), dest])
if __name__ == "__main__":
main()