Last active
December 14, 2015 00:29
-
-
Save elfenlaid/4999466 to your computer and use it in GitHub Desktop.
Observe given directory and tag added IPA files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from subprocess import Popen | |
from watchdog.observers import Observer | |
from watchdog.events import RegexMatchingEventHandler | |
class IpaDirectoryEventHandler(RegexMatchingEventHandler): | |
def on_modified(self, event): | |
self.tag_ipa(event.src_path) | |
def tag_ipa(self, ipa): | |
ipa_name = ipa.split('.')[0] | |
bashCommand = """cp \"{ipa}\" \"{ipa_name}_(`date +%F__%H_%M`).ipa\"""".format(**locals()) | |
stream = Popen(bashCommand, shell=True) | |
stream.wait() | |
def main(): | |
path = sys.argv[1] | |
event_handler = IpaDirectoryEventHandler(regexes=[".*/(\w|\s)+.ipa"], ignore_regexes=[]) | |
observer = Observer() | |
observer.schedule(event_handler, path='.', recursive=True) | |
observer.start() | |
print "Start observing directory (%s).." % path | |
try: | |
while True: | |
time.sleep(10) | |
except KeyboardInterrupt: | |
observer.stop() | |
observer.join() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment