Skip to content

Commit

Permalink
Erste Version, die bis jetzt nur via Pycharm (Python 2.7) ausführbar ist
Browse files Browse the repository at this point in the history
  • Loading branch information
weiher committed May 23, 2017
0 parents commit 7b7ce77
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 0 deletions.
45 changes: 45 additions & 0 deletions wc_getTrend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import suds
import sys
import xml

if len(sys.argv) == 1:
print 'Usage of this command:'
print '$ wc_getTrend /trees/geographic/#path/#to/#controller/m???'
print 'or:'
print '$ wc_getTrend "#controller/m???"'
exit(1)
else:
path = sys.argv[1]

username = 'wsdl'
password = 'seife'
wsdlFile = 'https://webctrl.rz-berlin.mpg.de/_common/webservices/Trend?wsdl'

try:
client = suds.client.Client(wsdlFile, username=username, password=password)
except AttributeError:
print 'Error: Incorrect username and/or password'
except xml.sax._exceptions.SAXParseException:
print 'Error: Incorrect/Misspelled WSDL file. It should be: http(s)://URL?wsdl'
exit(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
exit(1)


location = '#g_umluftkw_trend/m009'
startDate = '05/10/2017 08:00:00 AM'
endDate = '05/10/2017 01:00:00 PM'
limitFromStart = False
maxRecords = 10

try:
trendData = client.service.getTrendData(location, startDate, endDate, limitFromStart, maxRecords)
except suds.WebFault as fault:
print fault
exit(1)

print trendData

exit(0)
42 changes: 42 additions & 0 deletions wc_getValue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import suds
import sys
import xml

if len(sys.argv) == 1:
print 'Usage of this command:'
print '$ wc_getValue /trees/geographic/#path/#to/#controller/m???'
print 'or:'
print '$ wc_getValue "#controller/m???"'
exit(1)
else:
path = sys.argv[1]

username = 'wsdl'
password = 'seife'
wsdlFile = 'https://webctrl.rz-berlin.mpg.de/_common/webservices/Eval?wsdl'

try:
client = suds.client.Client(wsdlFile, username=username, password=password)
except AttributeError:
print 'Error: Incorrect username and/or password'
except xml.sax._exceptions.SAXParseException:
print 'Error: Incorrect/Misspelled WSDL file. It should be: http(s)://URL?wsdl'
exit(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
exit(1)

try:
value = client.service.getValue(path)
except suds.WebFault as fault:
print fault
exit(1)

if value is None:
print "You haven't specified a particular controller. The command could look like this:"
print '$ wc_getValue "#controller/m001"'
else:
print "Present value of " + path + " is: " + value

exit(0)
36 changes: 36 additions & 0 deletions wc_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import suds
import sys
import xml

if len(sys.argv) == 1:
print 'Usage of this command:'
print '$ wc_query /trees/geographic/#path/#to/#controller'
print 'Start querying by typing: $ wc_query /trees/geographic'
exit(1)
else:
path = sys.argv[1]

username = 'wsdl'
password = 'seife'
wsdlFile = 'https://webctrl.rz-berlin.mpg.de/_common/webservices/Eval?wsdl'

try:
client = suds.client.Client(wsdlFile, username=username, password=password)
except AttributeError:
print 'Error: Incorrect username and/or password'
except xml.sax._exceptions.SAXParseException:
print 'Error: Incorrect/Misspelled WSDL file. It should be: http(s)://URL?wsdl'
exit(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
exit(1)

try:
print 'Children of "' + path + '":'
print client.service.getChildren(path)
except suds.WebFault as fault:
print fault
exit(1)

exit(0)
92 changes: 92 additions & 0 deletions wc_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import suds
import sys
import numpy
import xml

reportTypes = ['~schedule-instance', '~effective-schedule', '~point-list-report', '~locked-value', '~network-io',
'~test-and-balance', '~equipment-checkout', '~audit-log', '~alarms', '~alarm_source', '~network_status',
'~module_version', '~security-assignment', '~alarm-messages', '~alarm-actions', '~trend-usage',
'~parameter-mismatch']

if len(sys.argv) == 1:
print 'Usage of this command:'
print '$ wc_report /trees/geographic/#path/#to/#controller ~report_name'
print 'These are the possible types of reports:'
for rtype in reportTypes:
print rtype
exit(0)
elif len(sys.argv) == 2:
print 'Need exactly two arguments:'
print '$ wc_report /trees/geographic/#path/#to/#controller ~report_name'
for rtype in reportTypes:
print rtype
exit(0)
else:
path = sys.argv[1]
reportType = sys.argv[2]

username = 'wsdl'
password = 'seife'
wsdlFile = 'https://webctrl.rz-berlin.mpg.de/_common/webservices/Report?wsdl'

try:
client = suds.client.Client(wsdlFile, username=username, password=password)
except AttributeError:
print 'Error: Incorrect username and/or password'
except xml.sax._exceptions.SAXParseException:
print 'Error: Incorrect/Misspelled WSDL file. It should be: http(s)://URL?wsdl'
exit(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
exit(1)

# Get the report
try:
report = client.service.runReport(path, reportType, 'csv')
except suds.WebFault as fault:
print fault
exit(1)

# Split the report into separate lines and calculate the number of columns
lines = report.split("\n")
nColumns = len(lines[0].split(","))

# Declare arrays
maxColumnWidth = [0 for i in range(nColumns)]
emptyColumns = numpy.full((nColumns), True, dtype=bool)

# Initialize the maximum column widths by the width of the column headers
column = lines[0].replace('"', '').split(",")
for i, col in enumerate(column):
maxColumnWidth[i] = len(col)

# Calculate the maximum column width taking into account all entries of each column and check whether a column is completely empty.
# If only one entry of a specific column is not empty the whole column will be marked as not empty.
for l, line in enumerate(lines):
if l > 0 and len(line) > 0:
column = line.replace('"', '').split(",")
for i, col in enumerate(column):
if len(col) > maxColumnWidth[i]:
maxColumnWidth[i] = len(col)
if col.strip() != "":
emptyColumns[i] = False

# Print the report in column format skipping those columns that are marked as completely empty.
for l, line in enumerate(lines):
if len(line) > 0:
column = line.replace('"', '').split(",")
c = '|'
for i, col in enumerate(column):
if not emptyColumns[i]:
formatStr = ' {:<'+str(maxColumnWidth[i])+'}'
c = c + formatStr.format(col) + ' |'
print c
if l == 0:
c = '|'
for i, n in enumerate(maxColumnWidth):
if not emptyColumns[i]:
c = c + n * '-' + '---'
print c

exit(0)

0 comments on commit 7b7ce77

Please sign in to comment.