- if node.can_download:
- if not download_list.has_seen(node):
- if node.download():
- download_list.mark_seen(node)
- else:
- print >>sys.stderr, "Failed to download!", node.title
- return
-
- if count >= len(pattern):
- print "No match found for pattern:", "/".join(pattern)
- return
- p = pattern[count]
- for child in node.get_children():
- if fnmatch.fnmatch(child.title, p):
- match(download_list, child, pattern, count+1)
-
-
-def main(destdir, patternfile):
- os.chdir(destdir)
- node = load_root_node()
- download_list = DownloadList()
-
- for line in open(patternfile):
- search = line.strip().split("/")
- match(download_list, node, search)
+ if node.can_download:
+ if download_list.wants(node):
+ if node.download():
+ download_list.mark_seen(node)
+ else:
+ logging.error("Failed to download! %s", node.title)
+ return
+
+ if count >= len(pattern):
+ logging.error("No match found for pattern:", "/".join(pattern))
+ return
+ p = pattern[count]
+ for child in node.get_children():
+ if fnmatch.fnmatch(child.title, p):
+ match(download_list, child, pattern, count+1)
+
+
+def process_one_dir(destdir, patternfile):
+ os.chdir(destdir)
+ node = load_root_node()
+ download_list = DownloadList()
+
+ for line in open(patternfile):
+ search = line.strip().split("/")
+ match(download_list, node, search)
+
+def check_directories(download_dirs):
+ result = []
+ failed = False
+
+ for d in download_dirs:
+ d = os.path.abspath(d)
+ if not os.path.isdir(d):
+ print("Not a directory!", d)
+ failed = True
+
+ pattern_filename = os.path.join(d, PATTERN_FILENAME)
+ if not os.path.isfile(pattern_filename):
+ print("Missing file!", pattern_filename)
+ failed = True
+
+ result.append((d, pattern_filename))
+
+ if failed:
+ print("Exiting!")
+ sys.exit(1)
+
+ return result
+
+def process_dirs(download_dirs):
+ for download_dir, pattern_filename in check_directories(download_dirs):
+ logging.info("Processing directory: %s", download_dir)
+ process_one_dir(download_dir, pattern_filename)