- leichter Umbau der Shellskripte. Extrakt des Fonts getrennt von test des Fonts

This commit is contained in:
Michael Stangl
2012-07-25 19:38:55 +02:00
parent 9340a28d0a
commit 8f091245f1
60 changed files with 1763 additions and 6395 deletions
+27 -107
View File
@@ -9,117 +9,44 @@ __license__ = 'BSD'
import optparse
import os
import ConfigParser
import jiffys
from utils import CSVImport
from datetime import datetime
from django.utils.encoding import smart_unicode, smart_str
def logger_init(logfile):
import logging
log = logging.getLogger('master')
now = datetime.now()
timestr = now.strftime("%d-%m-%Y_%H-%M-%S")
hdlr = logging.FileHandler(logfile)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
log.addHandler(hdlr)
log.setLevel(logging.INFO)
log.info('now: '+str(now))
return log
#now = datetime.now()
#logfile = 'mapsgen_'+ now.strftime("%d-%m-%Y.log")
#log_path = os.path.normpath(
#os.path.expandvars(os.path.join('$MAPSGEN_LOG', logfile ))
#)
##if not os.path.exists(log_path): parser.error('\"'+ log_path +'\" does not exist.')
#log = logger_init(log_path)
#log.debug('template: '+template)
def main( config ):
infile = options.infile
config = options.config
now = datetime.now()
ids=[]
config_path = os.path.expandvars(os.path.join('$PICCREATE_CFG', config+'.cfg' ))
in_path = os.path.expandvars(os.path.join('$PICCREATE_IN', infile+'.csv' ))
config_path = os.path.expandvars(os.path.join('$MASTER_CFG', config+'.cfg' ))
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):
parser.error('\"'+ config_path +'\" does not exist. Please give the name to a config file for the rows!')
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)
globalsec = dict(config.items('globals'))
targets = config.get('globals', 'targets')
# Setup:
# gewünschte Box(en) auftauen, wenn noch nicht passiert
# Boxen skalieren
if options.setup:
ids = setup(globalsec)
if config.has_section('IDs'):
oldids = config.get('IDs', 'Ids')
ids = [oldids, ids]
else:
config.add_section('IDs')
# die Ids der neuen in die Config schreiben
for i in ids: config.set('IDs', i, 'True')
with open(config_path, 'wb') as configfile:
config.write(configfile)
#
# Arbeiten durchführen:
# Daten auf Boxen verteilen und Arbeiten anstossen
#
# Status des Systems anzeigen:
# - wieviel Boxen sind am Leben und aktiv?
# - welche macht gerade was?
# - wieviel % der Aufgaben sind fertig?
# - wieviel % der jobs sind erledigt?
# - wieviele Packete sind schon ausgeliefert?
# wenn alles fertig ist, Teardown:
# alle Boxen bis auf den Ursprung löschen
# Box(en) einfrieren
if options.teardown:
ids = dict(config.items('IDs')).keys()
teardown(globalsec['token'], ids)
def setup( jiffyinfos ):
''' Erstellt aus einem Backup mehrere Jiffy boxen und started diese
'''
token = jiffyinfos['token']
boxid = jiffyinfos['boxid']
num_boxes = jiffyinfos['num_boxes']
backupid = jiffyinfos['backupid']
planid = jiffyinfos['planid']
name = jiffyinfos['name']
password = jiffyinfos['password']
ids = jiffys.rebuild_backup(token, boxid, num_boxes, backupid, name,
planid, password)
jiffys.start_boxes(ids, token, planid)
return ids
# Ausgabe einer Zeile in der Konsole
##!/bin/python
#import sys
#for i in xrange(1000000):
#print i, "\r",
#sys.stdout.flush()
# z.B. build image "engine" (3/5) started (1/5)
def teardown( token, ids ):
''' killt die Jiffy boxen die angegeben sind
'''
jiffys.delete_boxes(ids,token)
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__':
@@ -141,19 +68,12 @@ Read Confg, create wakeup and scale this kind of jiffy box
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("-k", "--check", dest="check",
help="check before creation, whether a map of this type exists already",
parser.add_option("-i", "--infile", dest="infile",
help="csv file with input of names/content",
action='store')
parser.add_option("-o", "--outdir", dest="outdir",
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("-s", "--setup", dest="setup", help="setup the used boxes",
action='store_true')
parser.add_option("-t", "--teardown", dest="teardown",
help="teardown the used boxes of that project",
action='store_true')
parser.add_option("-v", "--view-status", dest="view",
help="show the status of that project: Boxes, jobs, etc.")
parser.add_option("-y", "--dry", dest="dry",
help="dont generate images. Just ask the coordinates and fill database.", action='store_true' )
+31 -2
View File
@@ -4,6 +4,9 @@
from django.utils.encoding import smart_unicode
from django.template.defaultfilters import slugify
import csv
import ConfigParser
import os.path
import re
def csv_open(csvfile, dialect=None):
fh = open(csvfile, 'rb')
@@ -43,13 +46,13 @@ class CSVImport(object):
self.firstrow = self.rows[0]
self.field_definition = []
for i, field in enumerate(self.rows[0]):
if not field:
field = 'column_%d' % i
if translate:
if field in translate:
print field + ' -> '+ translate[field]
field = translate[field]
field = slugify(field.strip()).replace('-', '_')
if not field:
field = 'column_%d' % i
self.field_definition.append(field)
def __getitem__(self, key):
@@ -65,4 +68,30 @@ class CSVImport(object):
def firstrow(self):
return self.firstrow
def get_translation(cfg_path, sec_name):
""" lädt die Zuordnung zwischen einem .csv Eingabefile und den
Attributen """
config = ConfigParser.RawConfigParser()
config.read(cfg_path)
trans = dict(config.items(sec_name))
return dict([[v,k] for k,v in trans.items()])
def CompleteEnding(path, newext):
''' Fügt die gegebene File Extension an den Filename/Pfad
'''
if not path: raise Csv2CouchError('no path given')
path, ext = os.path.splitext(path)
if not re.match(newext, ext):
path = path +'.'+newext
return path
def RemoveEnding(path, oldext):
''' entfernt die File Extension vom Filename/Pfad
'''
newpath, ext = os.path.splitext(path)
if not re.match(oldext, ext):
path = newpath
return path
# vim: set tw=75 ft=python ts=4 sw=4:
BIN
View File
Binary file not shown.