|
1 | 1 | import time |
2 | 2 | import shutil |
3 | | -import subprocess |
4 | | -import sys |
5 | | -import os.path |
6 | 3 | import argparse |
7 | 4 | from git import Repo, Actor |
8 | 5 | from watchdog.observers import Observer |
9 | 6 | from watchdog.events import PatternMatchingEventHandler |
10 | 7 |
|
11 | 8 | """ |
12 | | - FileUpdaterPDF watches for creations and modifications of pdf files at the scheduled source and moves them to the destination. |
| 9 | + FileUpdater watches for creations and modifications of pdf files at the scheduled source and moves them to the destination. |
13 | 10 |
|
14 | 11 | Note: The destination should contain the new name if needed. Example: /path/some-new-name.pdf |
15 | 12 | """ |
16 | 13 |
|
17 | 14 |
|
18 | | -class FileUpdaterPDF(PatternMatchingEventHandler): |
19 | | - # Change this to include other specific extensions. |
20 | | - patterns = ["*.pdf"] |
| 15 | +class FileUpdater(PatternMatchingEventHandler): |
| 16 | + patterns = [] |
21 | 17 |
|
22 | | - def __init__(self, author_name, author_email, commit_message, git_directory, destinations): |
| 18 | + def __init__(self, author_name, author_email, commit_message, git_directory, destinations, pattern_matcher): |
23 | 19 | """ |
24 | | - Construct a FileUpdaterPDF. |
| 20 | + Construct a FileUpdater. |
25 | 21 | """ |
26 | | - super(FileUpdaterPDF, self).__init__() |
| 22 | + super(FileUpdater, self).__init__() |
27 | 23 | self.git_directory = git_directory |
28 | 24 | self.destinations = destinations |
29 | 25 | self.author_name = author_name |
30 | 26 | self.author_email = author_email |
31 | 27 | self.commit_message = commit_message |
| 28 | + self.patterns += pattern_matcher |
32 | 29 |
|
33 | 30 | def process(self, event): |
34 | 31 | """ |
@@ -111,15 +108,17 @@ def main(): |
111 | 108 | parser.add_argument("-s", "--source_path", |
112 | 109 | help="the directory to watch", required=True) |
113 | 110 | parser.add_argument("-d", "--destinations", |
114 | | - help="the destination(s) of the file", nargs="+") |
| 111 | + help="the destination(s) of the file", nargs="+", required=True) |
| 112 | + parser.add_argument("-p", "--pattern_matcher", |
| 113 | + help="file pattern to match in source directory", nargs="+", required=True) |
115 | 114 |
|
116 | 115 | # Parse arguments. |
117 | 116 | arguments = parser.parse_args() |
118 | 117 |
|
119 | | - # Run WatchDog with FileUpdaterPDF. |
| 118 | + # Run WatchDog with FileUpdater. |
120 | 119 | observer = Observer() |
121 | | - observer.schedule(FileUpdaterPDF( |
122 | | - arguments.author_name, arguments.author_email, arguments.commit_message, arguments.git_directory, arguments.destinations), arguments.source_path) |
| 120 | + observer.schedule(FileUpdater( |
| 121 | + arguments.author_name, arguments.author_email, arguments.commit_message, arguments.git_directory, arguments.destinations, arguments.pattern_matcher), arguments.source_path) |
123 | 122 | observer.start() |
124 | 123 |
|
125 | 124 | # Print some initial information. |
|
0 commit comments