alpha directory cp works

This commit is contained in:
koeart 2013-07-10 20:57:11 +02:00
parent aeb3460246
commit d567a91f60
1 changed files with 54 additions and 16 deletions

View File

@ -15,8 +15,6 @@ __copyright__ = "Copyright (c) 2013 Paul Schwanse"
__license__ = "Python" __license__ = "Python"
import csv
import os import os
import shutil import shutil
import sys import sys
@ -29,7 +27,7 @@ from ConfigParser import SafeConfigParser
# hier muesste man eigtl. die headline nur den "name" key rauspopeln # hier muesste man eigtl. die headline nur den "name" key rauspopeln
def make_default_config(conffile): def make_default_config(conffile='config.cfg'):
""" """
Creates the basic but default configuration file. Creates the basic but default configuration file.
@ -58,7 +56,7 @@ def make_default_config(conffile):
""" """
DEFAULT = dict(templatedir="~/templates", DEFAULT = dict(templatedir="~/templates/",
prepre="pre-", prepre="pre-",
git=False) git=False)
git = dict(sectionname="git", git = dict(sectionname="git",
@ -69,7 +67,7 @@ def make_default_config(conffile):
latexbeamer = dict(sectionname="latexbeamer", latexbeamer = dict(sectionname="latexbeamer",
directory="latex-beamer", directory="latex-beamer",
preambledir="latex-preambel", preambledir="latex-preambel",
latexengine="lulatex", latexengine="lualatex",
preambel="%(prepre)s%(latexengine)s") preambel="%(prepre)s%(latexengine)s")
sections=(git, latexbeamer) sections=(git, latexbeamer)
@ -99,6 +97,30 @@ def show_config(config, *secs):
print line print line
print "Attention! Default values are written here as well! Don't wonder!" print "Attention! Default values are written here as well! Don't wonder!"
def copy_template(config, template, outdir, verbose=False):
cwd = os.getcwd()
#print cwd
parameters = config.items(template)
directory = dict(parameters)['directory']
preambledir = dict(parameters)['preambledir']
latexengine = dict(parameters)['latexengine']
preamble = dict(parameters)['preambel']
sourcedir = dict(parameters)['templatedir']
sourcedir = os.path.expanduser(sourcedir)
source = shutil.abspath(sourcedir+directory)
print source
try:
shutil.copytree(sourcedir + directory, outdir)
message = "success"
except:
message = "uups"
pass
return message
def init_parser(): def init_parser():
"""Parse Command Line Options and Arguments""" """Parse Command Line Options and Arguments"""
parser = OptionParser() parser = OptionParser()
@ -125,6 +147,14 @@ def init_parser():
help=u"shows current config. If an Argument if an argument, thus section, is supplied, list only section", help=u"shows current config. If an Argument if an argument, thus section, is supplied, list only section",
default=False, default=False,
action="store_true") action="store_true")
parser.add_option(
"--outdir",
"-o",
dest="outdir",
help=u"set output directory to DIR",
default="./",
metavar="DIR")
parser.add_option( parser.add_option(
"--verbose", "--verbose",
@ -142,6 +172,7 @@ def main():
#read command line options and arguemnts #read command line options and arguemnts
options,args = init_parser() options,args = init_parser()
print type(options)
#check if (the specified) config exists, otherwise: create one #check if (the specified) config exists, otherwise: create one
if options.makedefaultconf: if options.makedefaultconf:
@ -156,21 +187,28 @@ def main():
if options.showconfig: if options.showconfig:
show_config(config) show_config(config)
except: except:
print "problems occured with conffile reading" print "problems occured while reading configfile"
#now look at the arguemnt what to do. #now look at the arguemnt what to do.
# make sure there is only one # make sure there is only one
try:
if len(args)>1: if len(args)>1:
print "Too many arguments! I cannot do that! Please provide one single templatething you want to have!" print "Too many arguments! I cannot do that! Please provide one single templatething you want to have!"
elif len(args) == 0: elif len(args) == 0:
print "Not enough arguments :(" print "Not enough arguments :("
elif config.has_section(args[0]):
show_config(config, args[0]) if len(args)==1 & config.has_section(args[0]):
except: argument = args[0]
print "something went wrong" meldung = copy_template(config, argument, options.outdir, options.verbose)
pass print meldung
sys.exit()
else:
print "template unknown! The following templates can be used:" + config.sections()
sys.exit()
if __name__ == "__main__": if __name__ == "__main__":