From 80291b09424f7068349ad856b9c1e9512075478e Mon Sep 17 00:00:00 2001 From: maste9 Date: Sun, 25 Jan 2015 17:01:00 +0100 Subject: [PATCH] bla --- picoblogger/main.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/picoblogger/main.py b/picoblogger/main.py index 7f1e61d..785971d 100644 --- a/picoblogger/main.py +++ b/picoblogger/main.py @@ -1,5 +1,8 @@ #!/usr/bin/python3 +import os +import configparser +from string import Template from argparse import ArgumentParser # check for arguments and options @@ -7,6 +10,32 @@ parser = ArgumentParser(description="Manage your weblog via commandline. Creates parser.add_argument('--blog_dir', default='~/public_html/blog', help='path to blog directory (default: %(default)s)') parser.add_argument('action', choices=['update'], help='updates blog to current state') args = parser.parse_args() +print(vars(args)) +try: + blog_dir = os.path.abspath(os.path.expanduser(vars(args)['blog_dir'])) + if not os.path.isdir(blog_dir): + print("The path you offered is not a directory!") + exit +except: + raise +def readout_conf(p): + config = configparser.ConfigParser() + config.read(p) + return config + +pbconf = readout_conf(os.path.join(blog_dir,"pb.conf")) +l10nconf = readout_conf(os.path.join(blog_dir,"l10n",pbconf['General']['BLOG_LANG'],"static.conf")) +def update_blog(): + + print(pbconf['General']['BLOG_LANG']) + print(l10nconf['General']['APP_NAME']) + print(l10nconf.defaults()) + tplIndex = os.path.join(blog_dir,"templates","index.htm") + tpl = Template(open(tplIndex,'r')) + blogIndex = os.path.join(blog_dir,"index.html") + with open(blogIndex,"w", encoding=l10nconf['General']['BLOG_CHARSET']) as f: + print(tpl.safe_substitute(l10nconf), file=f) if vars(args)['action'] == 'update': print("Updating your block.") + update_blog()