#!/usr/bin/env python # -*- coding: utf-8 -*- __version__ = '0.0.1' __author__ = 'Michael Stangl (mistangl[-a-]syntops.de)' __copyright__ = 'Copyright 2010, Michael Stangl' __license__ = 'BSD' import optparse import os import ConfigParser from utils import CSVImport from django.utils.encoding import smart_unicode, smart_str def main( config ): infile = options.infile config = options.config config_path = os.path.expandvars(os.path.join('$PICCREATE_CFG', config+'.cfg' )) in_path = os.path.expandvars(os.path.join('$PICCREATE_IN', infile+'.csv' )) if not config: config = 'default' if not infile: infile = 'default' out_path = options.outdir config_path = os.path.expandvars(os.path.join('$PICCREATE_CFG', CompleteEnding( config, 'cfg'))) in_path = os.path.expandvars(os.path.join('$PICCREATE_IN', CompleteEnding( infile, 'csv'))) if not os.path.exists(config_path): print '\"'+ config_path +'\" does not exist. Please give the name of a config file!' return None if not os.path.exists(in_path): print '\"'+ in_path +'\" does not exist. Please give the name to a input file!' return None if not os.path.exists(out_path): print '\"'+ out_path +'\" does not exist. Please give the path to the directory for the pictures!' return None config = ConfigParser.RawConfigParser() config.read(config_path) targets = config.get('globals', 'targets') Trans = get_translation(config_path, 'translation') Rows = CSVImport(in_path, translate=Trans) for data in Rows: filename = data.customerid pic_path = os.path.join(out_path, filename )) create_picture(data, ) if __name__ == '__main__': parser = optparse.OptionParser(usage="""%prog [options] Example usage ------------- Full help: $ %prog -h (or --help for possible options) Read Confg, create wakeup and scale this kind of jiffy box $ %prog -c test -i test """, version='%prog ' + __version__) parser.add_option("-c", "--cfg", dest="config", default="test", help="name of the config file with the Name of the rows to be used.", metavar="CONFIG_FILE") parser.add_option("-i", "--infile", dest="infile", help="csv file with input of names/content", action='store') parser.add_option("-o", "--outdir", dest="outdir", default=os.path.expandvars('$PICCREATE_OUT'), help="path to the directory where the maps will be generated", action='store') parser.add_option("-y", "--dry", dest="dry", help="dont generate images. Just ask the coordinates and fill database.", action='store_true' ) (options, args) = parser.parse_args() main(options.config) else: pass # vim: set tw=75 ft=python ts=4 sw=4: