Inital Commit
This commit is contained in:
70
client.py
Executable file
70
client.py
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python2.7
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
__author__ = "Michael Rest"
|
||||
__date__ = "1 August 2010"
|
||||
__email__ = "michi@rosstein.de"
|
||||
__version__ = "$Revision: 1.0 $"[11:-2]
|
||||
|
||||
|
||||
import os,sys
|
||||
from log import log
|
||||
from datetime import date, datetime, timedelta
|
||||
from time import time, strptime
|
||||
from ConfigParser import *
|
||||
from SOAPpy import SOAPProxy, SOAPServer
|
||||
|
||||
pid_file= '/tmp/ioclient.lock'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#Double fork to daemonize
|
||||
from os import fork, setsid, umask, dup2
|
||||
from sys import stdin, stdout, stderr
|
||||
from os import getpid
|
||||
|
||||
|
||||
if os.path.isfile (pid_file):
|
||||
pidfile = open (pid_file, 'r')
|
||||
pid = pidfile.read ()
|
||||
_r = 0
|
||||
try:
|
||||
os.kill (int (pid), 0)
|
||||
print ("Already running")
|
||||
_r = 1
|
||||
except:
|
||||
print ("Not running")
|
||||
os.remove (pid_file)
|
||||
if _r:
|
||||
sys.exit (0)
|
||||
|
||||
|
||||
pidfile = open (pid_file, 'w')
|
||||
pidfile.write('%i' % getpid())
|
||||
pidfile.close()
|
||||
|
||||
log ("========================================================================================")
|
||||
log ("iclient.py started")
|
||||
|
||||
|
||||
config = ConfigParser ()
|
||||
config.read ('ioclient.cfg')
|
||||
|
||||
ipoint_id = config.get ('PARAM', 'id')
|
||||
if not ipoint_id:
|
||||
print ("Ipoint ID not defined")
|
||||
raise Warning
|
||||
|
||||
|
||||
#Create SOAPProxy
|
||||
url = config.get ('IOSERV', 'url')
|
||||
if url:
|
||||
ioserv = SOAPProxy (url)
|
||||
print ("Proxy created")
|
||||
|
||||
try:
|
||||
#values = ioserv.recvValueBlk ('Demo')._asdict ()
|
||||
ioserv.setMaintenance ('ABP-Buero' , 2000)
|
||||
except:
|
||||
print "FixMe"
|
||||
|
||||
28
davedefs.py
Normal file
28
davedefs.py
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
__author__ = "Michael Rest"
|
||||
__date__ = "1 June 2000"
|
||||
__email__ = "michi@rosstein.de"
|
||||
__version__ = "$Revision: 1.0 $"[11:-2]
|
||||
|
||||
daveAreas = {
|
||||
"P" : 0x80, #daveP
|
||||
"E" : 0x81, #daveInputs
|
||||
"A" : 0x82, #daveFlags
|
||||
"M" : 0x83, #daveDB Data Blocks
|
||||
"DB": 0x84, #daveDI Instance Data Blocs
|
||||
"DI": 0x85, #daveLocal !!! Untestet
|
||||
"C" : 0x1c, #daveCounter
|
||||
"T" : 0x1d #daveTimer
|
||||
}
|
||||
|
||||
daveTypes = {
|
||||
"BOOL" : 1,
|
||||
"BYTE" : 1,
|
||||
"WORD" : 2,
|
||||
"INT" : 2,
|
||||
"DWORD" : 4,
|
||||
"REAL" : 4,
|
||||
"DINT" : 4
|
||||
}
|
||||
|
||||
|
||||
10
ioclient.cfg.tpl
Normal file
10
ioclient.cfg.tpl
Normal file
@@ -0,0 +1,10 @@
|
||||
[PARAM]
|
||||
id = I001
|
||||
|
||||
[IOSERV]
|
||||
url = http://localhost:8089/
|
||||
|
||||
|
||||
[DEBUG]
|
||||
loglevel = 6
|
||||
debuglevel = 1
|
||||
42
redis-client.py
Normal file
42
redis-client.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import redis
|
||||
|
||||
r_server = redis.Redis('mail.rosstein.de') #this line creates a new Redis object and
|
||||
#connects to our redis server
|
||||
r_server.set('test_key', 'test_value') #with the created redis object we can
|
||||
#submits redis commands as its methods
|
||||
|
||||
print 'previous set key ' + r_server.get('test_key') # the previous set key is fetched
|
||||
|
||||
'''In the previous example you saw that we introduced a redis
|
||||
data type: the string, now we will set an integer and try to
|
||||
increase its value using redis object built-in methods'''
|
||||
|
||||
r_server.set('counter', 1) #set an integer to a key
|
||||
r_server.incr('counter') #we increase the key value by 1, has to be int
|
||||
print 'the counter was increased! '+ r_server.get('counter') #notice that the key is increased now
|
||||
|
||||
r_server.decr('counter') #we decrease the key value by 1, has to be int
|
||||
print 'the counter was decreased! '+ r_server.get('counter') #the key is back to normal
|
||||
|
||||
|
||||
'''Now we are ready to jump into another redis data type, the list, notice
|
||||
that they are exactly mapped to python lists once you get them'''
|
||||
|
||||
r_server.rpush('list1', 'element1') #we use list1 as a list and push element1 as its element
|
||||
|
||||
r_server.rpush('list1', 'element2') #assign another element to our list
|
||||
r_server.rpush('list2', 'element3') #the same
|
||||
|
||||
print 'our redis list len is: %s'% r_server.llen('list1') #with llen we get our redis list size right from redis
|
||||
|
||||
print 'at pos 1 of our list is: %s'% r_server.lindex('list1', 1) #with lindex we query redis to tell us which element is at pos 1 of our list
|
||||
|
||||
'''sets perform identically to the built in Python set type. Simply, sets are lists but, can only have unique values.'''
|
||||
|
||||
r_server.sadd("set1", "el1")
|
||||
r_server.sadd("set1", "el2")
|
||||
r_server.sadd("set1", "el2")
|
||||
|
||||
print 'the member of our set are: %s'% r_server.smembers("set1")
|
||||
|
||||
'''basically our redis client can do any command supported by redis, check out redis documentation for available commands for your server'''
|
||||
63
redis-clientzope.py
Executable file
63
redis-clientzope.py
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
__author__ = "Michael Rest"
|
||||
__date__ = "1 June 2009"
|
||||
__email__ = "michi@rosstein.de"
|
||||
__version__ = "$Revision: 1.0 $"[11:-2]
|
||||
|
||||
from ConfigParser import *
|
||||
from datetime import datetime
|
||||
from time import sleep
|
||||
import sys
|
||||
import os
|
||||
import string
|
||||
import signal
|
||||
import redis
|
||||
|
||||
|
||||
def GetMsgState ():
|
||||
r_server = redis.Redis ('localhost')
|
||||
r_pipe = r_server.pipeline ()
|
||||
for nr in range (1, 300):
|
||||
r_pipe.get('Counter%03d' % nr)
|
||||
ret_val = []
|
||||
ret_val.append (r_pipe.execute ())
|
||||
|
||||
for nr in range (1, 300):
|
||||
r_pipe.get('State%03d' % nr)
|
||||
ret_val.append (r_pipe.execute ())
|
||||
return ret_val
|
||||
|
||||
|
||||
def GetActionState ():
|
||||
r_server = redis.Redis ('localhost')
|
||||
r_pipe = r_server.pipeline ()
|
||||
for nr in range (1, 250):
|
||||
r_pipe.get('Action%03d' % nr)
|
||||
ret_val = []
|
||||
ret_val.append (r_pipe.execute ())
|
||||
return ret_val
|
||||
|
||||
|
||||
def GetCamState ():
|
||||
r_server = redis.Redis ('localhost')
|
||||
r_pipe = r_server.pipeline ()
|
||||
r_pipe.get('HALLEA-Cams')
|
||||
r_pipe.get('HALLEB-Cams')
|
||||
ret_val = r_pipe.execute ()
|
||||
return ret_val
|
||||
|
||||
def GetVisuState ():
|
||||
r_server = redis.Redis ('localhost')
|
||||
r_pipe = r_server.pipeline ()
|
||||
r_pipe.get('HALLEA-Visu00')
|
||||
r_pipe.get('HALLEA-Visu00')
|
||||
r_pipe.get('HALLEA-Visu01')
|
||||
r_pipe.get('HALLEA-Visu01')
|
||||
r_pipe.get('HALLEA-Visu02')
|
||||
r_pipe.get('HALLEA-Visu02')
|
||||
r_pipe.get('ABP-Buero-Visu00')
|
||||
ret_val = r_pipe.execute ()
|
||||
return ret_val
|
||||
|
||||
|
||||
43
zioclient.py
Executable file
43
zioclient.py
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python2.7
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
__author__ = "Michael Rest"
|
||||
__date__ = "1 August 2010"
|
||||
__email__ = "michi@rosstein.de"
|
||||
__version__ = "$Revision: 1.0 $"[11:-2]
|
||||
|
||||
|
||||
from SOAPpy import SOAPProxy, SOAPServer
|
||||
from time import sleep
|
||||
|
||||
def recvValueBlk (id):
|
||||
ioserv = SOAPProxy ('http://localhost:8089/')
|
||||
|
||||
try:
|
||||
#values = ioserv.recvValueBlk ('Demo')._asdict ()
|
||||
values = ioserv.recvValueBlk (id)._aslist ()
|
||||
except:
|
||||
print "FixMe"
|
||||
return values
|
||||
|
||||
def setQuit (nr):
|
||||
ioserv = SOAPProxy ('http://localhost:8089/')
|
||||
try:
|
||||
ioserv.setQuit ('ABP-Buero' , int (nr))
|
||||
except:
|
||||
print "FixMe"
|
||||
|
||||
def setMaint (nr):
|
||||
ioserv = SOAPProxy ('http://localhost:8089/')
|
||||
try:
|
||||
ioserv.setMaintenance ('ABP-Buero' , int (nr))
|
||||
except:
|
||||
print "FixMe"
|
||||
|
||||
def setDone (nr):
|
||||
ioserv = SOAPProxy ('http://localhost:8089/')
|
||||
try:
|
||||
ioserv.setDone ('ABP-Buero' , int (nr))
|
||||
except:
|
||||
print "FixMe"
|
||||
|
||||
Reference in New Issue
Block a user