Skip to content

Instantly share code, notes, and snippets.

@umar-ahmed
Created January 4, 2017 00:17
Show Gist options
  • Save umar-ahmed/219ff3e352441cf918967896343808f9 to your computer and use it in GitHub Desktop.
Save umar-ahmed/219ff3e352441cf918967896343808f9 to your computer and use it in GitHub Desktop.
File watcher for Adobe XD project files.
import sys
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import os
import zipfile
def zip(src, dst):
zf = zipfile.ZipFile("%s.xd" % (dst), "w", zipfile.ZIP_DEFLATED)
abs_src = os.path.abspath(src)
for dirname, subdirs, files in os.walk(src):
for filename in files:
absname = os.path.abspath(os.path.join(dirname, filename))
arcname = absname[len(abs_src) + 1:]
zf.write(absname, arcname)
zf.close()
class ChangeHandler(FileSystemEventHandler):
""" EventHandler for file system """
def on_modified(self, event):
print("File changed. Regenerating XD File...", end='')
zip('files', 'test')
print("COMPLETED!")
if __name__ == "__main__":
# Use the current directory if one is not provided
path = sys.argv[1] if len(sys.argv) > 1 else '.'
event_handler = ChangeHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment