diff options
Diffstat (limited to 'bcst')
| -rw-r--r-- | bcst/args.py | 6 | ||||
| -rwxr-xr-x | bcst/bcst | 17 | ||||
| -rw-r--r-- | bcst/theme.py | 16 |
3 files changed, 29 insertions, 10 deletions
diff --git a/bcst/args.py b/bcst/args.py index 6ae54bf..993c9ed 100644 --- a/bcst/args.py +++ b/bcst/args.py @@ -3,7 +3,9 @@ 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_parser.add_argument("resource", nargs="?", help="A JSON resource file.") +args_parser.add_argument("destination", nargs="?",help="Start page folder name.") +args_parser.add_argument("-l","--list", dest="list",action="store_true", help="List available themes.") +args_parser.add_argument("-e","--extract", metavar="theme",dest="extract", help="Extract theme resource.") args = args_parser.parse_args() @@ -2,8 +2,17 @@ from bcst.args import args from bcst.resource import Resource -from bcst.theme import Theme +from bcst.theme import * -res=Resource(args.resource) -t=Theme("default",res.json) -t.deploy(args.destination) +if args.list: + for theme in list_themes(): + print("- "+theme) + exit(0) +elif args.extract: + t=Theme("default") + t.extract("resources.json") + exit(0) +elif args.resource and args.destination: + t=Theme("default") + t.update_resource(args.resource) + t.deploy(args.destination) diff --git a/bcst/theme.py b/bcst/theme.py index 58e7902..9bdd956 100644 --- a/bcst/theme.py +++ b/bcst/theme.py @@ -26,11 +26,10 @@ def get_theme_path(name): class Theme: - def __init__(self, name, resource_data): + def __init__(self, name): self.theme_path=get_theme_path(name) - res=Resource(self.theme_path+"/resources.json") - self.data=res.json - self.data.update(resource_data) + self.res_path=self.theme_path+"/resources.json" + self.data=Resource(self.res_path).json # Read theme try: with open(self.theme_path+"/index.html",'r') as f: @@ -39,6 +38,15 @@ class Theme: print("Unable to found "+resource) exit(1) + def update_resource(self,resource_path): + r=Resource(resource_path) + self.data.update(r.json) + + + def extract(self, dest): + with open(dest, "w") as resFile: + resFile.write(self.data.data) + def deploy(self, dest_path): copytree(self.theme_path, dest_path, dirs_exist_ok=True,ignore=ignore_patterns("*.json","index.html")) |
