pnbp

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

commit 1d874222049b6546df0399463ebebb059d924f08
parent bad7f91e0c2d5f72173487750bdff087f51e175b
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Wed Aug 27 22:42:26 2014

re-aranged for pretty

Diffstat:
 src/core.py | 34 +++++++++++++++++++++++++++++++++-
 src/main.py | 36 +++++-------------------------------
 2 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/src/core.py b/src/core.py @@ -18,6 +18,36 @@ from functions import * pages = "" pagedata = {} +#CLI Interface function +#args = list of command line arguementsn +def cli(args): + bd = "site/" + if len(args) > 1: + 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": + 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") + + sys.exit() + + elif 0 != args.index(i): + print("Unknown option: {}".format(i)) + + if "--init" in args or "-i" in args: + init() + + return bd + # Adds in variables defined in pages.json # # t = raw template, var = "pagevar" variables in pages.json (<pagename> -> "pagevar") @@ -129,9 +159,11 @@ def runMod(t,var,page): return subpage -def build(bd): +def build(arg): global pages, pagedata + bd = cli(arg) + #Try to get the config try: pages = file("pages.yml") except: diff --git a/src/main.py b/src/main.py @@ -9,47 +9,21 @@ import os, sys, traceback, time, core from initbasic import * -#CLI Interface function -#args = list of command line arguementsn -def cli(args): - bd = "site/" - if len(args) > 1: - 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": - 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") - - sys.exit() - - elif 0 != args.index(i): - print("Unknown option: {}".format(i)) - - if "--init" in args or "-i" in args: - init() - - return bd - if __name__ == "__main__": #Save the time for the caluation start = time.time() #Try to build the site - try: core.build(cli(sys.argv)) + try: + core.build(sys.argv) + except: print("Something went wrong...") traceback.print_exc(file=sys.stdout) + sys.exit() + #Print the time it took for the calculation print("Finished in {} ms.".format((time.time()-start)*1000))