From a7217345e1cf9fa878e271fcc199f9a18eb9637f Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 22 Apr 2020 07:39:07 +0200 Subject: [PATCH] Debug package --- MANIFEST.in | 1 + README.md | 45 ++++++++--------- bcst | 11 ----- {libs => bcst}/__init__.py | 0 {libs => bcst}/args.py | 0 bcst/bcst | 9 ++++ {libs => bcst}/resource.py | 2 +- bcst/theme.py | 48 +++++++++++++++++++ .../themes}/default/assets/script.js | 0 .../themes}/default/assets/style.css | 0 {themes => bcst/themes}/default/index.html | 0 .../themes}/default/resources.json | 0 libs/theme.py | 29 ----------- setup.py | 6 ++- 14 files changed, 86 insertions(+), 65 deletions(-) create mode 100644 MANIFEST.in delete mode 100755 bcst rename {libs => bcst}/__init__.py (100%) rename {libs => bcst}/args.py (100%) create mode 100755 bcst/bcst rename {libs => bcst}/resource.py (95%) create mode 100644 bcst/theme.py rename {themes => bcst/themes}/default/assets/script.js (100%) rename {themes => bcst/themes}/default/assets/style.css (100%) rename {themes => bcst/themes}/default/index.html (100%) rename {themes => bcst/themes}/default/resources.json (100%) delete mode 100644 libs/theme.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..ebd498f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include bcst/themes/ ** \ No newline at end of file diff --git a/README.md b/README.md index d6cf9cd..9073e7f 100644 --- a/README.md +++ b/README.md @@ -4,28 +4,29 @@ BCST allow you to create a beautiful start page very quickly. To install the dep > pip install jinja2 -Simple right a simple json resource file: - - { - "title": "Default Theme", - "bookmarks": { - "engines": { - "Qwant": "https://www.qwant.com/", - "DDG": "https://duckduckgo.com/", - "Google": "http://google.fr" - }, - "Reddit": { - "Home": "https://www.reddit.com/", - "Unixporn": "https://www.reddit.com/r/Unixporn", - "Linux": "https://www.reddit.com/me/m/linux" - }, - "Social": { - "Discord": "https://discordapp.com/channels/@me", - "Twitter": "https://twitter.com/", - "LinuxRocks": "https://linuxrocks.online/web/getting-started" - } - } - } +Simple write a simple json resource file: +``` +{ + "title":"Default Theme", + "bookmarks":{ + "engines":{ + "Qwant":"https://www.qwant.com/", + "DDG":"https://duckduckgo.com/", + "Google":"http://google.fr" + }, + "Reddit":{ + "Home":"https://www.reddit.com/", + "Unixporn":"https://www.reddit.com/r/Unixporn", + "Linux":"https://www.reddit.com/me/m/linux" + }, + "Social":{ + "Discord":"https://discordapp.com/channels/@me", + "Twitter":"https://twitter.com/", + "LinuxRocks":"https://linuxrocks.online/web/getting-started" + } + } +} +``` Then simply run: > ./src/bcst.py \ \ diff --git a/bcst b/bcst deleted file mode 100755 index 4e3957e..0000000 --- a/bcst +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -from libs.args import args -from libs.resource import Resource -from libs.theme import Theme - - -res=Resource(args.resource) -t=Theme("themes/default",res.json) - -t.deploy(args.destination) diff --git a/libs/__init__.py b/bcst/__init__.py similarity index 100% rename from libs/__init__.py rename to bcst/__init__.py diff --git a/libs/args.py b/bcst/args.py similarity index 100% rename from libs/args.py rename to bcst/args.py diff --git a/bcst/bcst b/bcst/bcst new file mode 100755 index 0000000..ebef0d0 --- /dev/null +++ b/bcst/bcst @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +from bcst.args import args +from bcst.resource import Resource +from bcst.theme import Theme + +res=Resource(args.resource) +t=Theme("default",res.json) +t.deploy(args.destination) diff --git a/libs/resource.py b/bcst/resource.py similarity index 95% rename from libs/resource.py rename to bcst/resource.py index f521022..342e08a 100644 --- a/libs/resource.py +++ b/bcst/resource.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from os import path -import json, jsonschema +import json class Resource: diff --git a/bcst/theme.py b/bcst/theme.py new file mode 100644 index 0000000..58e7902 --- /dev/null +++ b/bcst/theme.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +from bcst.resource import Resource +from shutil import copytree, ignore_patterns +from jinja2 import Template +import os +from os import path + +themes_location=path.join(path.dirname(path.abspath(__file__)),"themes") + + +def list_themes(): + themes=list() + for f in os.listdir(themes_location): + if(not(os.path.isfile(os.path.join(themes_location,f)))): + themes.append(f) + return(themes) + +def get_theme_path(name): + p=path.join(themes_location,name) + if(path.isdir(p)): + return(p) + else: + print("Could not find theme: "+name) + exit(1) + +class Theme: + + def __init__(self, name, resource_data): + self.theme_path=get_theme_path(name) + res=Resource(self.theme_path+"/resources.json") + self.data=res.json + self.data.update(resource_data) + # Read theme + try: + with open(self.theme_path+"/index.html",'r') as f: + self.template=Template(f.read()) + except IOError: + print("Unable to found "+resource) + exit(1) + + + def deploy(self, dest_path): + copytree(self.theme_path, dest_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(dest_path+"/index.html", "w") as index: + index.write(self.template.render(self.data)) diff --git a/themes/default/assets/script.js b/bcst/themes/default/assets/script.js similarity index 100% rename from themes/default/assets/script.js rename to bcst/themes/default/assets/script.js diff --git a/themes/default/assets/style.css b/bcst/themes/default/assets/style.css similarity index 100% rename from themes/default/assets/style.css rename to bcst/themes/default/assets/style.css diff --git a/themes/default/index.html b/bcst/themes/default/index.html similarity index 100% rename from themes/default/index.html rename to bcst/themes/default/index.html diff --git a/themes/default/resources.json b/bcst/themes/default/resources.json similarity index 100% rename from themes/default/resources.json rename to bcst/themes/default/resources.json diff --git a/libs/theme.py b/libs/theme.py deleted file mode 100644 index 9859451..0000000 --- a/libs/theme.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/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)) diff --git a/setup.py b/setup.py index a62a99e..956a27d 100644 --- a/setup.py +++ b/setup.py @@ -5,14 +5,16 @@ with open("README.md", "r") as readme: setuptools.setup( name="bcst", - version="0.0.1", - scripts=['bcst'], + version="0.0.3", + scripts=["bcst/bcst"], author="Loic Guegan", author_email="manzerbredes@mailbox.org", description="A web browser start page generator.", long_description=long_description, + long_description_content_type='text/markdown', url="https://gitlab.com/manzerbredes/bcst", install_requires=["jinja2"], + include_package_data=True, packages=setuptools.find_packages(), classifiers=["License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)"])