This commit is contained in:
darthsandmann
2016-10-16 21:53:15 +02:00
parent 0d10f8b9dc
commit c9f3117da1
412 changed files with 137942 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# coding: utf-8
# hier können Paket-Initialisierungen eingetragen werden

View File

@@ -0,0 +1,33 @@
# coding: utf-8
import time
import codecs
import json
from app import stream
class chargen_cl(object):
exposed = True
chargenCounter = 1
def __init__(self):
self.stream = stream.stream_cl()
def NEXT(self):
if(self.chargenCounter > self.stream.anzChargen()):
self.chargenCounter = 1
# timeout = 0
# while(self.chargenCounter > self.stream.anzChargen()):
# print(self.stream.anzChargen())
# time.sleep(1)
# timeout += 1
# if(timeout > 3600):
# return -1
newCharge = self.stream.loadCharge(self.chargenCounter)
self.chargenCounter += 1
return json.dumps(newCharge)

View File

@@ -0,0 +1,47 @@
# coding: utf-8
import os
import time
import codecs
import json
from app import stream
class log_cl(object):
exposed = True
def __init__(self):
self.stream = stream.stream_cl()
def SEND(self, user, charge, los, preis):
file = codecs.open(os.path.join('data', 'log.txt'), 'r', 'utf-8')
log = json.loads(file.read())
file.close()
counter = 1
for x in log:
counter += 1
counter = str(counter)
log[counter] = {}
log[counter]['user'] = user
log[counter]['charge'] = charge
log[counter]['los'] = los
log[counter]['preis'] = preis
log[counter]['time'] = time.time()
print(log)
file = codecs.open(os.path.join('data', 'log.txt'), 'w', 'utf-8')
file.write(json.dumps(log, indent=3, ensure_ascii=True))
file.close()
def REQ(self):
file = codecs.open(os.path.join('data', 'log.txt'), 'r', 'utf-8')
log = json.loads(file.read())
file.close()
return json.dumps(log)

View File

@@ -0,0 +1,72 @@
# coding: utf-8
import os
import time
import codecs
import json
from app import stream
class manager_cl(object):
exposed = True
def __init__(self):
self.stream = stream.stream_cl()
def LIST(self):
chargenliste = {}
filenames = os.listdir('data')
for filename in filenames:
if filename.endswith('.json'):
charge = codecs.open(os.path.join('data', filename), 'r', 'utf-8')
chargeData = eval(charge.read())
charge.close()
charge_id = filename[:-5]
chargenliste[charge_id]={}
chargenliste[charge_id]['chargeName'] = chargeData['info']['name']
print(chargenliste)
return json.dumps(chargenliste)
def GET(self, nr):
data = {}
data = self.stream.loadCharge(nr)
return json.dumps(data)
def RECEIVE(self, dieCharge):
dieCharge = json.loads(dieCharge)
if dieCharge['info']['chargenNr'] == -1:
filenames = os.listdir('data')
maxNr = 0
for filename in filenames:
if filename.endswith('.json'):
charge = codecs.open(os.path.join('data', filename), 'r', 'utf-8')
chargeData = eval(charge.read())
charge.close()
if maxNr < chargeData['info']['chargenNr']:
maxNr = chargeData['info']['chargenNr']
dieCharge['info']['chargenNr'] = maxNr + 1
name = str(maxNr + 1)
name += '.json'
file = codecs.open(os.path.join('data', name), 'w', 'utf-8')
file.write(json.dumps(dieCharge, indent = 3, ensure_ascii = True))
file.close()
else:
name = str(dieCharge['info']['chargenNr'])
name += '.json'
file = codecs.open(os.path.join('data', name), 'w', 'utf-8')
file.write(json.dumps(dieCharge, indent = 3, ensure_ascii = True))
file.close()
def DELETE(self, nr):
path = 'data/'
path += str(nr)
path += '.json'
print(path)
os.remove(path)

View File

@@ -0,0 +1,31 @@
# coding: utf-8
import os
import os.path
import codecs
import json
class stream_cl(object):
exposed = True
def __init__(self):
pass
def loadCharge(self, id):
filename = str(id)
filename += '.json'
file = codecs.open(os.path.join('data', filename), 'r', 'utf-8')
charge = file.read()
file.close()
return charge
def anzChargen(self):
files = os.listdir('data')
fileCounter = 0
for file in files:
if file.endswith('.json'):
fileCounter += 1
return fileCounter

View File

@@ -0,0 +1,55 @@
# coding: utf-8
#not planned
import json
import os
import codecs
import cherrypy
# Method-Dispatching!
# Übersicht Anforderungen / Methoden
# (beachte: / relativ zu /template, siehe Konfiguration Server!)
"""
Anforderung GET PUT POST DELETE
----------------------------------------------------------------
/ Alle - - -
Templates
liefern
"""
#----------------------------------------------------------
class Template_cl(object):
#----------------------------------------------------------
exposed = True # gilt für alle Methoden
#-------------------------------------------------------
def __init__(self):
#-------------------------------------------------------
pass
#-------------------------------------------------------
def GET(self):
#-------------------------------------------------------
retVal_o = {
'templates': {}
}
files_a = os.listdir('templates/engine')
for fileName_s in files_a:
file_o = codecs.open(os.path.join('templates/engine', fileName_s), 'rU', 'utf-8')
content_s = file_o.read()
file_o.close()
retVal_o["templates"][fileName_s] = content_s
return json.dumps(retVal_o)
# EOF