aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2020-04-21 15:48:24 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2020-04-21 15:48:24 +0200
commit5c07eda3fa0e48c7b8337f8b57b8390da86ee6d7 (patch)
tree91c2dfa66e00a35c0fe72a04dea4f5f39c0f442f /src
Init project
Diffstat (limited to 'src')
-rw-r--r--src/args.py9
-rwxr-xr-xsrc/bcst.py11
-rw-r--r--src/resource.py23
-rw-r--r--src/theme.py29
4 files changed, 72 insertions, 0 deletions
diff --git a/src/args.py b/src/args.py
new file mode 100644
index 0000000..6ae54bf
--- /dev/null
+++ b/src/args.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+
+import argparse
+
+args_parser = argparse.ArgumentParser()
+args_parser.add_argument("resource", help="A JSON resource file.")
+args_parser.add_argument("destination", help="Start page folder name.")
+args = args_parser.parse_args()
+
diff --git a/src/bcst.py b/src/bcst.py
new file mode 100755
index 0000000..850fbdb
--- /dev/null
+++ b/src/bcst.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+from args import args
+from resource import Resource
+from theme import Theme
+
+
+res=Resource(args.resource)
+t=Theme("themes/default",res.json)
+
+t.deploy(args.destination)
diff --git a/src/resource.py b/src/resource.py
new file mode 100644
index 0000000..f521022
--- /dev/null
+++ b/src/resource.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+from os import path
+import json, jsonschema
+
+
+class Resource:
+ def __init__(self, resource):
+ self.resource=resource
+ # Read data
+ try:
+ with open(resource,'r') as f:
+ self.data=f.read()
+ except IOError:
+ print("Unable to found "+resource)
+ exit(1)
+ # Decode data
+ try:
+ self.json=json.loads(self.data)
+ except:
+ print("Unable to read json from "+resource)
+ exit(1)
+
diff --git a/src/theme.py b/src/theme.py
new file mode 100644
index 0000000..9859451
--- /dev/null
+++ b/src/theme.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+from resource import Resource
+from shutil import copytree, ignore_patterns
+from jinja2 import Template
+import os
+
+class Theme:
+
+ def __init__(self, path, resource_data):
+ res=Resource(path+"/resources.json")
+ self.theme_path=path.strip('/')
+ self.data=res.json
+ self.data.update(resource_data)
+ # Read theme
+ try:
+ with open(path+"/index.html",'r') as f:
+ self.template=Template(f.read())
+ except IOError:
+ print("Unable to found "+resource)
+ exit(1)
+
+
+ def deploy(self, path):
+ copytree(self.theme_path, path, dirs_exist_ok=True,ignore=ignore_patterns("*.json","index.html"))
+ themes_dir=os.path.split(self.theme_path)[0]
+ theme_dir=os.path.split(self.theme_path)[1]
+ with open(path+"/index.html", "w") as index:
+ index.write(self.template.render(self.data))