Commits

Konstantine Rybnikov committed f3ed0c8

add clevercss_watcher

  • Participants
  • Parent commits 39385ba

Comments (0)

Files changed (5)

File clevercss_watcher.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Usage:
+#   ./autocompile.py path ext1,ext2,extn cmd
+#
+# Blocks monitoring |path| and its subdirectories for modifications on
+# files ending with suffix |extk|. Run |cmd| each time a modification
+# is detected. |cmd| is optional and defaults to 'make'.
+#
+# Example:
+#   ./autocompile.py /my-latex-document-dir .tex,.bib
+#
+# Dependancies:
+#   Linux, Python 2.6, Pyinotify
+#
+import os
+import sys
+import pyinotify
+
+class OnWriteHandler(pyinotify.ProcessEvent):
+    def my_init(self, cwd, extension, cmd):
+        self.cwd = cwd
+        self.extensions = extension.split(',')
+        self.cmd = cmd
+
+    def process_IN_MODIFY(self, event):
+        if any(event.pathname.endswith(ext) and not ('.#' in event.pathname)
+               for ext
+               in self.extensions):
+            print '%s changed' % event.pathname
+            os.system(self.cmd % dict(file_ = event.pathname))
+        return
+
+def auto_compile(path, extension, cmd):
+    wm = pyinotify.WatchManager()
+    handler = OnWriteHandler(cwd=path, extension=extension, cmd=cmd)
+    notifier = pyinotify.Notifier(wm, default_proc_fun=handler)
+    wm.add_watch(path, pyinotify.ALL_EVENTS, rec=True, auto_add=True)
+    print '==> Start monitoring %s (type c^c to exit)' % path
+    notifier.loop()
+
+if __name__ == '__main__':
+    sys.argv[1:] = [os.getcwd(), '.clevercss']
+    if len(sys.argv) < 3:
+        print >> sys.stderr, "Command line error: missing argument(s)."
+        sys.exit(1)
+
+    # Required arguments
+    path = sys.argv[1]
+    extension = sys.argv[2]
+
+    print '> path is %s' % path
+    print '> extension is %s' % extension
+
+    # Optional argument
+    cmd = r'''clevercss %(file_)s'''
+    # cmd = r"""find . -regex "[a-zA-Z\/_\.]+\.clevercss" -exec clevercss '{}' \;"""
+    # if len(sys.argv) == 4:
+    #     cmd = sys.argv[3]
+
+    # Blocks monitoring
+    auto_compile(path, extension, cmd)

File fat/fat_po_editor/static/css/base.css

-body {
-    font: large/1.556 'Linux Libertine',Palatino,'Palatino Linotype','Book Antiqua',Georgia,'Times New Roman',serif;
-    margin: 0 auto;
-    max-width: 960px;
-    padding-top: 10px;
-}
-h1, h2 {
-    font-family: 'Essays 1743',Palatino,'Palatino Linotype','Book Antiqua',Georgia,'Times New Roman',serif;
-    text-align: center;
-    text-shadow: 0 0 1px #666677;
-    text-transform: uppercase;
-}
-a {
-    color: #4f4f4f;
-}

File fat/fat_po_editor/static/css/main.clevercss

+body:
+    font: 1.556 'Linux Libertine', Palatino, 'Palatino Linotype', 'Book Antiqua', Georgia, 'Times New Roman', serif
+    margin: 0 auto
+    max-width: 960px
+    padding-top: 10px
+
+h1, h2:
+    font-family: 'Essays 1743', Palatino, 'Palatino Linotype', 'Book Antiqua', Georgia, 'Times New Roman', serif
+    font-size: 60px
+    text-align: center
+    text-shadow: 0 0 1px #666677
+    text-transform: uppercase
+
+a:
+    color: #4f4f4f

File fat/fat_po_editor/static/css/main.css

+body {
+  font: 1.556 'Linux Libertine', Palatino, 'Palatino Linotype', 'Book Antiqua', Georgia, 'Times New Roman', serif;
+  margin: 0 auto;
+  max-width: 960px;
+  padding-top: 10px;
+}
+
+h1,
+h2 {
+  font-family: 'Essays 1743', Palatino, 'Palatino Linotype', 'Book Antiqua', Georgia, 'Times New Roman', serif;
+  font-size: 60px;
+  text-align: center;
+  text-shadow: 0 0 1px #666677;
+  text-transform: uppercase;
+}
+
+a {
+  color: #4f4f4f;
+}

File fat/fat_po_editor/templates/fat_po_editor/base.djhtml

     <title></title>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
     <link rel="stylesheet" href="{{ STATIC_URL }}css/base.css" type="text/css" media="screen" />
+    <link rel="stylesheet" href="{{ STATIC_URL }}css/main.css" type="text/css" media="screen" />
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
   </head>
   <body>