md2html.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. from PyQt5.QtCore import QFileSystemWatcher
  5. import json
  6. class Compiler():
  7. def __init__(self,parent):
  8. self.parent = parent
  9. self.initWatching()
  10. self.compileContents()
  11. def initWatching(self):
  12. self.refreshPaths()
  13. self.fs_watcher = QFileSystemWatcher(self.paths)
  14. # self.fs_watcher.directoryChanged.connect(self.directory_changed)
  15. self.fs_watcher.fileChanged.connect(self.onMdFileChanged)
  16. def onMdFileChanged(self):
  17. print("onMdFileChanged")
  18. try:
  19. self.compileContents()
  20. except Exception as e:
  21. print("Error compiling MD files", e)
  22. pass
  23. def refreshPaths(self):
  24. jsonfilepath = os.path.join(self.parent.cwd,'.config/summary.json')
  25. sum_json = open(jsonfilepath).read()
  26. self.sum = json.loads(sum_json)
  27. self.paths = [os.path.join(self.parent.cwd,'contents')]
  28. for item in self.sum:
  29. self.paths.append(os.path.join(self.parent.cwd,'contents',item['file']))
  30. def reload(self):
  31. self.fs_watcher.removePaths(self.paths)
  32. self.refreshPaths()
  33. self.fs_watcher.addPaths(self.paths)
  34. self.compileContents()
  35. def compileContents(self):
  36. print('Compiling md')