- leichter Umbau der Shellskripte. Extrakt des Fonts getrennt von test des Fonts
This commit is contained in:
+27
-107
@@ -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' )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user