Add function for deploystatic to just deploy jinja templates
authorMagnus Hagander <magnus@hagander.net>
Tue, 15 Aug 2017 17:17:56 +0000 (19:17 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 15 Aug 2017 17:17:56 +0000 (19:17 +0200)
This will deploy the template files themselves, not the result of them
being processed. These templates are then rendered by the master system.

Since these are not pages, it explicitly excludes the pages directory.

tools/deploystatic/deploystatic.py

index 72d9bfb4833af43b4f6aad91b5159194bcdefb17..ec6832421cce0cd9a3f6fb35afeee56705208c5d 100755 (executable)
@@ -205,6 +205,7 @@ if __name__ == "__main__":
        parser.add_argument('sourcepath', type=str, help='Source path')
        parser.add_argument('destpath', type=str, help='Destination path')
        parser.add_argument('--branch', type=str, help='Deploy directly from branch')
+       parser.add_argument('--templates', action='store_true', help='Deploy templates (except pages) instead of pages')
 
        args = parser.parse_args()
 
@@ -237,6 +238,36 @@ if __name__ == "__main__":
                        print "'{0}' subdirectory does not exist in source!".format(d)
                        sys.exit(1)
 
+       if args.templates:
+               # Just deploy templates. They are simply copied over, for use by backend
+               # system.
+               knownfiles = []
+               for relpath, relname in source.walkfiles('templates'):
+                       if relpath == 'templates/pages': continue
+
+                       # Remove templates/ prefix, since it will always be there
+                       destrelpath = relpath[len('templates/'):]
+
+                       if not os.path.isdir(os.path.join(args.destpath, destrelpath)):
+                               os.makedirs(os.path.join(args.destpath, destrelpath))
+
+                       relsource = os.path.join(relpath, relname)
+                       source.copy_if_changed(relsource, os.path.join(args.destpath, destrelpath, relname))
+
+                       knownfiles.append(os.path.join(destrelpath, relname))
+
+               # Look for things to remove
+               for dn, subdirs, filenames in os.walk(args.destpath):
+                       relpath = os.path.relpath(dn, args.destpath)
+                       if relpath == '.':
+                               relpath = ''
+                       for fn in filenames:
+                               f = os.path.join(relpath, fn)
+                               if not f in knownfiles:
+                                       os.unlink(os.path.join(args.destpath, f))
+
+               sys.exit(0)
+
        staticdest = os.path.join(args.destpath, 'static/')
 
        # Set up jinja environment