From a7217345e1cf9fa878e271fcc199f9a18eb9637f Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 22 Apr 2020 07:39:07 +0200 Subject: Debug package --- MANIFEST.in | 1 + README.md | 45 +++++++------- bcst | 11 ---- bcst/__init__.py | 0 bcst/args.py | 9 +++ bcst/bcst | 9 +++ bcst/resource.py | 23 ++++++++ bcst/theme.py | 48 +++++++++++++++ bcst/themes/default/assets/script.js | 103 ++++++++++++++++++++++++++++++++ bcst/themes/default/assets/style.css | 110 +++++++++++++++++++++++++++++++++++ bcst/themes/default/index.html | 37 ++++++++++++ bcst/themes/default/resources.json | 20 +++++++ libs/__init__.py | 0 libs/args.py | 9 --- libs/resource.py | 23 -------- libs/theme.py | 29 --------- setup.py | 6 +- themes/default/assets/script.js | 103 -------------------------------- themes/default/assets/style.css | 110 ----------------------------------- themes/default/index.html | 37 ------------ themes/default/resources.json | 20 ------- 21 files changed, 387 insertions(+), 366 deletions(-) create mode 100644 MANIFEST.in delete mode 100755 bcst create mode 100644 bcst/__init__.py create mode 100644 bcst/args.py create mode 100755 bcst/bcst create mode 100644 bcst/resource.py create mode 100644 bcst/theme.py create mode 100644 bcst/themes/default/assets/script.js create mode 100644 bcst/themes/default/assets/style.css create mode 100644 bcst/themes/default/index.html create mode 100644 bcst/themes/default/resources.json delete mode 100644 libs/__init__.py delete mode 100644 libs/args.py delete mode 100644 libs/resource.py delete mode 100644 libs/theme.py delete mode 100644 themes/default/assets/script.js delete mode 100644 themes/default/assets/style.css delete mode 100644 themes/default/index.html delete mode 100644 themes/default/resources.json 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/bcst/__init__.py b/bcst/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bcst/args.py b/bcst/args.py new file mode 100644 index 0000000..6ae54bf --- /dev/null +++ b/bcst/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/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/bcst/resource.py b/bcst/resource.py new file mode 100644 index 0000000..342e08a --- /dev/null +++ b/bcst/resource.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +from os import path +import json + + +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/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/bcst/themes/default/assets/script.js b/bcst/themes/default/assets/script.js new file mode 100644 index 0000000..4681d9e --- /dev/null +++ b/bcst/themes/default/assets/script.js @@ -0,0 +1,103 @@ +// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later + +var DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] + +function startTime() { + var today = new Date(); + var h = today.getHours(); + var ampm = h >= 12 ? 'PM' : 'AM'; + var m = today.getMinutes(); + var s = today.getSeconds(); + m = checkTime(m); + s = checkTime(s); + var h = h % 12; + var h = h ? h : 12; // the hour '0' should be '12' + + //--------------------- + + var dow = DAYS[today.getDay()] + var dd = ('0' + today.getDate()).slice(-2) + var mm = ('0' + (today.getMonth() + 1 )).slice(-2) + var yy = today.getFullYear() + + document.getElementById('date').innerHTML = dow + ' ' + yy + '-' + mm + '-' + dd + + //--------------------- + + document.getElementById('time').innerHTML = + h + ":" + m + ":" + s + ' ' + ampm; + var t = setTimeout(startTime, 500); +} + +function checkTime(i) { + if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10 + return i; +} + +var dateElem = document.getElementById('date') + +var vpwidth = document.documentElement.clientWidth +var sections = document.querySelectorAll('.box') +function fixSectionHeight() { + var step = 1 + if (vpwidth >= 480) step = 2; + if (vpwidth >= 768) step = 4; + + sections.forEach(function (s) { + s.style.height = 'auto' + }) + + for (var i = 0; i < sections.length; i += step) { + var ss = Array.prototype.slice.call(sections, i, i + step) + var hss = ss.map(function (e) { return e.clientHeight }) + var h = Math.max.apply(null, hss) + ss.forEach(function (s) { + s.style.height = h + 'px' + }) + } +} + +function addLinks(DATA) { + const main = document.querySelector("main"); + + function createSection(linkGroup) { + const section = document.createElement("section"); + + const box = document.createElement("div"); + box.classList.add("box"); + + const title = document.createElement("span"); + title.classList.add("title"); + title.innerHTML = linkGroup.category; + + const content = document.createElement('div'); + content.classList.add('content'); + + for (let link of linkGroup.links) { + const anchor = document.createElement('a'); + anchor.setAttribute('href', link.url); + + const anchorSpan = document.createElement('span'); + anchorSpan.classList.add('links'); + anchorSpan.innerHTML = link.name; + + anchor.appendChild(anchorSpan); + + content.appendChild(anchor); + } + + box.appendChild(title); + box.appendChild(content) + + section.appendChild(box); + + return section; + } + + for (let linkGroup of DATA.linkGroups) { + const section = createSection(linkGroup); + + main.appendChild(section); + } +} + diff --git a/bcst/themes/default/assets/style.css b/bcst/themes/default/assets/style.css new file mode 100644 index 0000000..b2676b4 --- /dev/null +++ b/bcst/themes/default/assets/style.css @@ -0,0 +1,110 @@ + +:root { +--bgdark: #232836; +--bglight: #282e3f; +--bglighter: #2f364a; + +--fgdark: #8686a4; +--fglight: #ccccfa; + +--accent: #d39ceb; +--border: #2f364a; +--disabled: #696969; +--hover: #ffffff; +} + +* { + font-family: "t kiwi Wide"; + font-size: 20px; +} + +html { + background: var(--bgdark); + background-position: top -24px left 0; + margin-top: -26px; +} + +html, body { + width: 100vw; + height: 100vh; + padding: 0; + margin: 0; +} + +main { + display: flex; + justify-content: center;; + overflow-y: auto; + flex-flow: row wrap; + position: relative; + top: 50%; + transform: translateY(-50%); +} + +#clock { + position: relative; + top: -30px; + display: flex; + text-align: center; +} + +#time, #date { + color: var(--fglight); + display: inline-block; + margin: 0 5px; + flex-grow: 1; + width: 0; +} + +#time { + text-align: left; +} + +#date { + text-align: right; +} + +.links { + padding: 5px 15px; + width: auto; + display: block; + text-align: center; +} + +a:visited, a { + color: var(--fgdark); + text-decoration: none; + outline: none; +} + +a:not(.tablinks):visited, a:not(.tablinks) { transition: all 00ms ease 0s; } +a:hover { color: var(--fglight); } + +.slash { + color: var(--fgdark); +} + +main section { + box-sizing: border-box; + min-width: 300px; +} + +.title { + display: none; +} + +section { + margin: 12px; + padding: 12px; + /*border: 8px solid var(--fgdark);*/ + box-shadow: 10px 10px 0px 0px rgba(0,0,0,0.13); +} + +section { + background-color: var(--bglight); + border-radius: 4px; +} + +section:hover { + background-color: var(--bglighter); +} diff --git a/bcst/themes/default/index.html b/bcst/themes/default/index.html new file mode 100644 index 0000000..82133cb --- /dev/null +++ b/bcst/themes/default/index.html @@ -0,0 +1,37 @@ + + + + + + + +{{ title }} + + + + + + + + + + +
+ {% for key,value in bookmarks.items() %} +
+
{{ key }} +
+ {% for link_name,link in value.items() %} + {{link_name}} + {% endfor %} +
+
+
+ {% endfor %} + + +
+ + + + diff --git a/bcst/themes/default/resources.json b/bcst/themes/default/resources.json new file mode 100644 index 0000000..dd2e1ca --- /dev/null +++ b/bcst/themes/default/resources.json @@ -0,0 +1,20 @@ +{ + "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" + } + } +} diff --git a/libs/__init__.py b/libs/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/libs/args.py b/libs/args.py deleted file mode 100644 index 6ae54bf..0000000 --- a/libs/args.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/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/libs/resource.py b/libs/resource.py deleted file mode 100644 index f521022..0000000 --- a/libs/resource.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/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/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+)"]) diff --git a/themes/default/assets/script.js b/themes/default/assets/script.js deleted file mode 100644 index 4681d9e..0000000 --- a/themes/default/assets/script.js +++ /dev/null @@ -1,103 +0,0 @@ -// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later - -var DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] - -function startTime() { - var today = new Date(); - var h = today.getHours(); - var ampm = h >= 12 ? 'PM' : 'AM'; - var m = today.getMinutes(); - var s = today.getSeconds(); - m = checkTime(m); - s = checkTime(s); - var h = h % 12; - var h = h ? h : 12; // the hour '0' should be '12' - - //--------------------- - - var dow = DAYS[today.getDay()] - var dd = ('0' + today.getDate()).slice(-2) - var mm = ('0' + (today.getMonth() + 1 )).slice(-2) - var yy = today.getFullYear() - - document.getElementById('date').innerHTML = dow + ' ' + yy + '-' + mm + '-' + dd - - //--------------------- - - document.getElementById('time').innerHTML = - h + ":" + m + ":" + s + ' ' + ampm; - var t = setTimeout(startTime, 500); -} - -function checkTime(i) { - if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10 - return i; -} - -var dateElem = document.getElementById('date') - -var vpwidth = document.documentElement.clientWidth -var sections = document.querySelectorAll('.box') -function fixSectionHeight() { - var step = 1 - if (vpwidth >= 480) step = 2; - if (vpwidth >= 768) step = 4; - - sections.forEach(function (s) { - s.style.height = 'auto' - }) - - for (var i = 0; i < sections.length; i += step) { - var ss = Array.prototype.slice.call(sections, i, i + step) - var hss = ss.map(function (e) { return e.clientHeight }) - var h = Math.max.apply(null, hss) - ss.forEach(function (s) { - s.style.height = h + 'px' - }) - } -} - -function addLinks(DATA) { - const main = document.querySelector("main"); - - function createSection(linkGroup) { - const section = document.createElement("section"); - - const box = document.createElement("div"); - box.classList.add("box"); - - const title = document.createElement("span"); - title.classList.add("title"); - title.innerHTML = linkGroup.category; - - const content = document.createElement('div'); - content.classList.add('content'); - - for (let link of linkGroup.links) { - const anchor = document.createElement('a'); - anchor.setAttribute('href', link.url); - - const anchorSpan = document.createElement('span'); - anchorSpan.classList.add('links'); - anchorSpan.innerHTML = link.name; - - anchor.appendChild(anchorSpan); - - content.appendChild(anchor); - } - - box.appendChild(title); - box.appendChild(content) - - section.appendChild(box); - - return section; - } - - for (let linkGroup of DATA.linkGroups) { - const section = createSection(linkGroup); - - main.appendChild(section); - } -} - diff --git a/themes/default/assets/style.css b/themes/default/assets/style.css deleted file mode 100644 index b2676b4..0000000 --- a/themes/default/assets/style.css +++ /dev/null @@ -1,110 +0,0 @@ - -:root { ---bgdark: #232836; ---bglight: #282e3f; ---bglighter: #2f364a; - ---fgdark: #8686a4; ---fglight: #ccccfa; - ---accent: #d39ceb; ---border: #2f364a; ---disabled: #696969; ---hover: #ffffff; -} - -* { - font-family: "t kiwi Wide"; - font-size: 20px; -} - -html { - background: var(--bgdark); - background-position: top -24px left 0; - margin-top: -26px; -} - -html, body { - width: 100vw; - height: 100vh; - padding: 0; - margin: 0; -} - -main { - display: flex; - justify-content: center;; - overflow-y: auto; - flex-flow: row wrap; - position: relative; - top: 50%; - transform: translateY(-50%); -} - -#clock { - position: relative; - top: -30px; - display: flex; - text-align: center; -} - -#time, #date { - color: var(--fglight); - display: inline-block; - margin: 0 5px; - flex-grow: 1; - width: 0; -} - -#time { - text-align: left; -} - -#date { - text-align: right; -} - -.links { - padding: 5px 15px; - width: auto; - display: block; - text-align: center; -} - -a:visited, a { - color: var(--fgdark); - text-decoration: none; - outline: none; -} - -a:not(.tablinks):visited, a:not(.tablinks) { transition: all 00ms ease 0s; } -a:hover { color: var(--fglight); } - -.slash { - color: var(--fgdark); -} - -main section { - box-sizing: border-box; - min-width: 300px; -} - -.title { - display: none; -} - -section { - margin: 12px; - padding: 12px; - /*border: 8px solid var(--fgdark);*/ - box-shadow: 10px 10px 0px 0px rgba(0,0,0,0.13); -} - -section { - background-color: var(--bglight); - border-radius: 4px; -} - -section:hover { - background-color: var(--bglighter); -} diff --git a/themes/default/index.html b/themes/default/index.html deleted file mode 100644 index 82133cb..0000000 --- a/themes/default/index.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - -{{ title }} - - - - - - - - - - -
- {% for key,value in bookmarks.items() %} -
-
{{ key }} -
- {% for link_name,link in value.items() %} - {{link_name}} - {% endfor %} -
-
-
- {% endfor %} - - -
- - - - diff --git a/themes/default/resources.json b/themes/default/resources.json deleted file mode 100644 index dd2e1ca..0000000 --- a/themes/default/resources.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "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" - } - } -} -- cgit v1.2.3