This commit is contained in:
maste9 2015-01-25 17:01:00 +01:00 committed by Homer S
parent f6f140735e
commit 80291b0942
1 changed files with 29 additions and 0 deletions

View File

@ -1,5 +1,8 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os
import configparser
from string import Template
from argparse import ArgumentParser from argparse import ArgumentParser
# check for arguments and options # 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('--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') parser.add_argument('action', choices=['update'], help='updates blog to current state')
args = parser.parse_args() 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': if vars(args)['action'] == 'update':
print("Updating your block.") print("Updating your block.")
update_blog()