pnbp

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

commit 1e17a462193555725d6ed4c5d82c0832c49cef2c
parent 7bee492040d8ef30e117232b8b62b454fddd61a0
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Sat Jun 27 18:46:41 2015

Moved to OptParse for args, moves 'site' dir instead of obliterating it, minor tweaks

Diffstat:
 src/core/__init__.py         | 37 ++++++++++++-------------------------
 src/core/builder.py          | 20 +++++---------------
 src/core/helper/cmd.py       |  9 ---------
 src/core/helper/functions.py |  3 ++-
 src/core/module.py           |  4 +---
 src/core/template.py         |  4 +---
 src/init.py                  | 24 +++++++++++++++++++-----
 7 files changed, 40 insertions(+), 61 deletions(-)

diff --git a/src/core/__init__.py b/src/core/__init__.py @@ -1,9 +1,7 @@ ''' ' pnbp - pnbp is not a blogging platform ' __init__.py -' Paul Longtine - paullongtine@gmail.com -' -' For documentation, please visit http://static.nanner.co/pnbp +' Paul Longtine <paul@nanner.co> ''' import os, sys, yaml @@ -12,7 +10,16 @@ import core.helper.cmd import core.builder def init(arg): - bd = cli(arg) + if arg.init: + core.helper.cmd.init() + if arg.dir != "": + i = os.getcwd() + else: + if os.path.exists(arg.dir): + i = arg.dir + else: + print("'{}' does not exist".format(arg.dir)) + sys.exit(1) #Try to get the config try: @@ -24,25 +31,5 @@ def init(arg): pagedata = yaml.load(pages) - core.builder.build(pagedata,bd) + core.builder.build(pagedata,arg.dir) -#CLI Interface function -#args = list of command line arguementsn -def cli(args): - bd = "site/" - for i in args: - if i[0] != "-" and args.index(i) != 0: - bd = i - - elif i == "-d": - os.chdir(args.pop(args.index(i)+1)) - - elif i == "--help": - core.helper.cmd.phelp() - elif i == "--init" or i == "-i": - core.helper.cmd.init() - - elif 0 != args.index(i): - print("Unknown option: {}".format(i)) - - return bd diff --git a/src/core/builder.py b/src/core/builder.py @@ -1,9 +1,7 @@ ''' ' pnbp - pnbp is not a blogging platform ' builder.py -' Paul Longtine - paullongtine@gmail.com -' -' For documentation, please visit http://static.nanner.co/pnbp +' Paul Longtine <paul@nanner.co> ''' import os, shutil @@ -14,10 +12,10 @@ import core.module #site = dict of site directory tree/pages, loc = root of site def makeSite(site,loc): try: - shutil.rmtree(loc) + shutil.move(loc, loc+".bak") except: - print("No directory {}, ignoring".format(loc)) + print("No directory '{}', ignoring".format(loc)) os.mkdir(loc) for page, subpages in site.items(): @@ -42,18 +40,10 @@ def makeSite(site,loc): #p = name of page, l = location def handleDirectory(p,l): if p == "index": - if l[-1] == "/": - r = l[0:-1] - - else: - r = l + r = l[0:-1] if l[-1] == "/" else l else: - if l[-1] == "/": - r = l+p - - else: - r = l+"/"+p + r = l+p if l[-1] == "/" else l+"/"+p try: os.mkdir(r) diff --git a/src/core/helper/cmd.py b/src/core/helper/cmd.py @@ -13,12 +13,3 @@ def init(): file("pages.yml","w").write(basicConfig) file("template.html","w").write(basicTemplate) -def phelp(): - print( - "Usage: build [OPTION(s)]... [DIR]...\n" - "Build site in DIR using configuration in pwd\n" - "\n" - " -d DIR Use configuration in DIR, when not specified DIR is 'site/'\n" - " -i, --init Make a new site using the bare minimium config and build it in DIR\n" - " --help Display this help and exit\n" - ) diff --git a/src/core/helper/functions.py b/src/core/helper/functions.py @@ -13,7 +13,8 @@ import time, yaml def now(config): return time.strftime(config) -#Return an HTML list. example format: {'root':"<ul class=\"special\">%li%</ul>",'li':"<li class=\"list\">%content%</li>"} +#Return an HTML list. example format: +# {'root':"<ul class=\"special\">%li%</ul>",'li':"<li class=\"list\">%content%</li>"} def list(things,formats={}): formats['root'] = formats.get("root","<ul>%li%</ul>") formats['li'] = formats.get("li","<li>%content%</li>") diff --git a/src/core/module.py b/src/core/module.py @@ -1,9 +1,7 @@ ''' ' pnbp - pnbp is not a blogging platform ' module.py -' Paul Longtine - paullongtine@gmail.com -' -' For documentation, please visit http://static.nanner.co/pnbp +' Paul Longtine <paul@nanner.co> ''' import sys, modules, template diff --git a/src/core/template.py b/src/core/template.py @@ -1,9 +1,7 @@ ''' ' pnbp - pnbp is not a blogging platform ' template.py -' Paul Longtine - paullongtine@gmail.com -' -' For documentation, please visit http://static.nanner.co/pnbp +' Paul Longtine <paul@nanner.co> ''' import re, json, yaml diff --git a/src/init.py b/src/init.py @@ -2,20 +2,34 @@ ''' ' pnbp - pnbp is not a blogging platform ' init.py -' Paul Longtine - paullongtine@gmail.com +' Paul Longtine <paul@nanner.co> ' -' For documentation, please visit http://static.nanner.co/pnbp +' For documentation, please visit http://pnbp.nanner.co ''' -import sys + import core + from time import time +from optparse import OptionParser + +def parsearg(): + parser = OptionParser() + + parser.add_option("-d", "--directory", dest="dir", default="site", + help="Set site project root directory", metavar="<dir>") + parser.add_option("-i", "--init", dest="init", action="store_true", default=False, + help="Initalize basic project directory") + return parser.parse_args() if __name__ == "__main__": #Save the time for the caluation start = time() - + + #Parse arguements + options, args = parsearg() + #Try to build the site - core.init(sys.argv) + core.init(options) #Print the time it took to build the site print("Finished in {} ms.".format((time()-start)*1000))