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"
import csv
import os
import shutil
import sys
@ -29,7 +27,7 @@ from ConfigParser import SafeConfigParser
# 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.
@ -58,7 +56,7 @@ def make_default_config(conffile):
"""
DEFAULT = dict(templatedir="~/templates",
DEFAULT = dict(templatedir="~/templates/",
prepre="pre-",
git=False)
git = dict(sectionname="git",
@ -69,7 +67,7 @@ def make_default_config(conffile):
latexbeamer = dict(sectionname="latexbeamer",
directory="latex-beamer",
preambledir="latex-preambel",
latexengine="lulatex",
latexengine="lualatex",
preambel="%(prepre)s%(latexengine)s")
sections=(git, latexbeamer)
@ -99,6 +97,30 @@ def show_config(config, *secs):
print line
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():
"""Parse Command Line Options and Arguments"""
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",
default=False,
action="store_true")
parser.add_option(
"--outdir",
"-o",
dest="outdir",
help=u"set output directory to DIR",
default="./",
metavar="DIR")
parser.add_option(
"--verbose",
@ -142,6 +172,7 @@ def main():
#read command line options and arguemnts
options,args = init_parser()
print type(options)
#check if (the specified) config exists, otherwise: create one
if options.makedefaultconf:
@ -156,21 +187,28 @@ def main():
if options.showconfig:
show_config(config)
except:
print "problems occured with conffile reading"
print "problems occured while reading configfile"
#now look at the arguemnt what to do.
# make sure there is only one
try:
if len(args)>1:
print "Too many arguments! I cannot do that! Please provide one single templatething you want to have!"
elif len(args) == 0:
print "Not enough arguments :("
elif config.has_section(args[0]):
show_config(config, args[0])
except:
print "something went wrong"
pass
if len(args)>1:
print "Too many arguments! I cannot do that! Please provide one single templatething you want to have!"
elif len(args) == 0:
print "Not enough arguments :("
if len(args)==1 & config.has_section(args[0]):
argument = args[0]
meldung = copy_template(config, argument, options.outdir, options.verbose)
print meldung
sys.exit()
else:
print "template unknown! The following templates can be used:" + config.sections()
sys.exit()
if __name__ == "__main__":