aboutsummaryrefslogtreecommitdiff
path: root/libs/theme.py
blob: 9859451eefa70e64016974495aba1a15d0684f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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))