pnbp

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 22b8f852aba0938b1e40c8e3e3c430b527132d27
parent 7510d4dd94c79739a276846aaa5b173c81f3e6c0
Author: Paul Longtine <paul@nanner.co>
Date:   Fri Jan 22 13:07:21 2016

Fixed weird stuff with admin module, poked at the blog module, updated builder to keep backups of all generated sites, made stagit thingy better

Diffstat:
 src/core/builder.py                        | 36 ++++++++++++++++++++----------
 src/core/module.py                         | 24 ++++++++++----------
 src/core/modules/blog.py                   |  2 +-
 src/core/modules/data/admin/index.template | 10 ++++----
 src/core/modules/data/admin/post.template  |  4 +++-
 src/init.py                                |  4 ++-
 src/stagit/__init__.py                     |  8 +++----
 src/stagit/ambassador.py                   | 37 +++++++++++++++++++++++++------
 8 files changed, 85 insertions(+), 40 deletions(-)

diff --git a/src/core/builder.py b/src/core/builder.py @@ -5,33 +5,47 @@ ''' import os, shutil +from datetime import date, datetime + import core.template import core.module #Builds the site off of a filestructure dictionary. #site = dict of site directory tree/pages, loc = root of site def makeSite(site,loc): - try: - shutil.move(loc, loc+".bak") + if not (os.path.isdir("history")): + os.mkdir("history") - except: - print("Creating directory '{}'".format(loc)) + shutil.move(loc, + os.path.join("history", + loc+date.strftime(datetime.now(), "%Y-%m-%d-%H-%M-%S") + ) + ) + + if (os.path.isdir(loc)): + shutil.rmtree(loc) os.mkdir(loc) + for page, subpages in site.items(): currentDir = handleDirectory(page,loc) subpageLoop(subpages,currentDir) - - if loc[-1] != "/": - loc = loc + "/" + try: + for i in os.listdir("data/static/"): try: - shutil.copytree("data/static/"+i,loc+i) - + shutil.copytree( + os.path.join("data/static/", i), + os.path.join(loc, i) + ) + except: - shutil.copy2("data/static/"+i,loc+i) + shutil.copy2( + os.path.join("data/static/", i), + os.path.join(loc, i) + ) except: print("No directory data/static, ignoring") @@ -58,7 +72,7 @@ def handleDirectory(p,l): def subpageLoop(d,cur): for k, v in d.iteritems(): if isinstance(v, dict): - subpageLoop(v,cur + "/" + k) + subpageLoop(v, os.path.join(cur, k)) else: f = k.split(".") fl = "" diff --git a/src/core/module.py b/src/core/module.py @@ -46,18 +46,18 @@ def getSubpages(t,var,data,name,page): if not "settings" in data: data['settings'] = {} - try: - returns = getattr(modules, data['mod']).getPages(t, data['settings'], name, page) - - except Exception,e: - print("Error occured at {} using module {}:".format(page,data['mod'])) - if type(e) == KeyError: - print("Missing attribute {}".format(e)) - sys.exit() - - else: - print(e) - +# try: + returns = getattr(modules, data['mod']).getPages(t, data['settings'], name, page) + +# except Exception,e: +# print("Error occured at {} using module {}:".format(page,data['mod'])) +# if type(e) == KeyError: +# print("Missing attribute {}".format(e)) +# sys.exit() +# +# else: +# print(e) +# return returns # Runs modules defined in pages.json diff --git a/src/core/modules/blog.py b/src/core/modules/blog.py @@ -38,7 +38,7 @@ def getPages(template,settings,name,page): pages['post'] = {} for i in data: post = generatePost(i,temp,page) - pages['post'][slug(i['title'])] = template.replace("%"+name+"%",post) + pages['post'][slug(i['title'])] = template.replace("%"+name+"%",post) return pages diff --git a/src/core/modules/data/admin/index.template b/src/core/modules/data/admin/index.template @@ -37,15 +37,15 @@ $name = [%dbn%]; $index = 0; foreach ($databases as $db) { $data = json_decode(file_get_contents($db),TRUE); - echo "<h1>".$name[$index]."</h1>"; - echo "<div class='container'>"; + echo '<h1>'.$name[$index].'</h1>'; + echo '<div class="container">'; $new = 0; foreach ($data as $val) { - echo "<a href=\\"edit.php?location=".$db."&post=".$val["post"]."\\">".$val["title"]."</a><br/>"; + echo '<a href="edit.php?location='.$db.'&post='.$val["post"].'">'.$val["title"].'</a><br/>'; $new = $new + 1; } - echo "<br /><a href=\\"edit.php?location=".$db."&newpost=".$new."\\">New Post</a><br/>"; - echo "</div>"; + echo '<br /><a href="edit.php?location='.$db.'&newpost='.$new.'">New Post</a><br/>'; + echo '</div>'; $index = $index + 1; } ?> diff --git a/src/core/modules/data/admin/post.template b/src/core/modules/data/admin/post.template @@ -34,6 +34,10 @@ if (isset($_POST['loc'])) { $posts = json_decode(file_get_contents($_POST['loc']),TRUE); parse_str(str_replace(",", "&", $_POST['vars']), $data); + if (!(isset($data["title"]))) { + $data["title"] = uniqid(); + } + $posts[$data["post"]] = array_merge($data,array("content" => $_POST["post"])); $fp = fopen($_POST['loc'], 'w'); fwrite($fp, json_encode($posts)); diff --git a/src/init.py b/src/init.py @@ -7,7 +7,7 @@ ' For documentation, please visit http://pnbp.nanner.co ''' -import core, shtml, stagit +import core, stagit from time import time from optparse import OptionParser @@ -19,6 +19,8 @@ def parsearg(): help="set site project root directory", metavar="<dir>") parser.add_option("-o", dest="out", default="site", help="where to output", metavar="<out>") + parser.add_option("-i", "--init", dest="init", action="store_true", + default=False, help="initalize basic project directory") return parser.parse_args() if __name__ == "__main__": diff --git a/src/stagit/__init__.py b/src/stagit/__init__.py @@ -1,6 +1,6 @@ import os, sys, yaml -import core.ambassador +import stagit.ambassador def init(arg): if os.path.exists(arg.dir): @@ -12,14 +12,14 @@ def init(arg): #Try to get the config try: raw_config = file("stagit_config.yml") + print("stagit enabled") except: - print("Can't open file 'stagit_config.yml'") - sys.exit(0) + return config = yaml.load(raw_config) - core.ambassador.stagit(config) + stagit.ambassador.stagit(config) diff --git a/src/stagit/ambassador.py b/src/stagit/ambassador.py @@ -7,25 +7,50 @@ def stagit(config): config['repo_dir'] = config.get("repo_dir", "src/") - repo_string = "" + repos = [] for repo in os.listdir(config['repo_dir']): - repo_path = os.path.join( config['output_dir'], repo ) + repo_path = os.path.join( config['repo_dir'], repo ) + output_path = os.path.join( config['output_dir'], repo ) - os.mkdir(repo_path) + if not os.path.exists(output_path): + os.mkdir(output_path) path = os.getcwd() - os.chdir( repo_path ) + os.chdir( output_path ) + + try: + os.symlink( + os.path.join(config['output_dir'], "favicon.png"), + os.path.join(output_path, "favicon.png")) + except: pass + + try: + os.symlink( + os.path.join(config['output_dir'], "logo.png"), + os.path.join(output_path, "logo.png")) + except: pass + + try: + os.symlink( + os.path.join(config['output_dir'], "style.css"), + os.path.join(output_path, "style.css")) + except: pass call(["stagit", repo_path]) os.chdir(path) - repo_string = " ".join(repo_string, repo) + repos.append(repo_path) + os.chdir(config['output_dir']) - call(["stagit-index", repo_string]) + f = open("index.html", "w") + + call(["stagit-index"] + repos, stdout=f) + +