Skip to content

Commit

Permalink
A new argument parser is now used: switched from sys.argv to argparse…
Browse files Browse the repository at this point in the history
…. Now wc_getTrend works. Changed name from wc_report to wc_getReport. Updated the documentation.
  • Loading branch information
weiher committed May 29, 2017
1 parent ef21868 commit 22700cc
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 63 deletions.
8 changes: 3 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ Running the tools

e.g.: webctrl$ ./dist/wc_query/wc_query

When you run the tools without any arguments you will be prompted with how to use the commands and
which arguments to pass.
Use -h or --help with all tools in order to find out more about how to use them.

Short explanation of each tool
------------------------------

wc_query : Query the paths and devices starting from /trees/geographic

wc_report : Retrieve a report for a directory or a specific device
wc_getReport : Retrieve a report for a directory or a specific device

wc_getValue : Retrieve the current value of a device

wc_getTrend : Retrieve data and date for a given time period and device
(ATTENTION: this command does not yet work because the path to the trend data is not correct)
wc_getTrend : Retrieve data and date for a given time period and device


30 changes: 9 additions & 21 deletions wc_report.py → wc_getReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,15 @@
import sys
import numpy
import xml
import argparse

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) < 2:
print "You haven't specified any arguments but I need a path. Use -h to get more details on how to use this command."

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
sys.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
sys.exit(0)
else:
path = sys.argv[1]
reportType = sys.argv[2]
parser = argparse.ArgumentParser()
parser.add_argument('--path', '-p', type=str, default=None,
help='Path to the point or node for which you want to get a report.')
args = parser.parse_args()

username = 'wsdl'
password = 'seife'
Expand All @@ -42,7 +29,7 @@

# Get the report
try:
report = client.service.runReport(path, reportType, 'csv')
report = client.service.runReport(args.path, '~point-list-report', 'csv')
except suds.WebFault as fault:
print fault
sys.exit(1)
Expand Down Expand Up @@ -89,3 +76,4 @@
print c

sys.exit(0)

53 changes: 35 additions & 18 deletions wc_getTrend.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
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???"'
sys.exit(1)
else:
path = sys.argv[1]
import argparse

if len(sys.argv) < 2:
print "You haven't specified any arguments. Need at least a path. Use -h to get more details on how to use this command."

parser = argparse.ArgumentParser()
parser.add_argument('--path', '-p', type=str, default=None,
help='The full path to the point, or trend log node whose trend data is desired.')
parser.add_argument('--sTime', '-s', type=str, default=None,
help="Start Time. Returns trend data values starting with this time. Like this: 'MM/DD/YYYY HH:MM:SS AM'.")
parser.add_argument('--eTime', '-e', type=str, default=None,
help="End Time. Returns trend data values until this time. Like this: 'MM/DD/YYYY HH:MM:SS PM'.")
parser.add_argument('--limit', '-l', type=bool, default=False,
help='Use True to retrieve maxRecords from the start or False to retrieve maxRecords from the end.')
parser.add_argument('--maxRec', '-m', type=int, default=10,
help='Maximum number of records desired. Use a number >0 to limit records; use 0 to retrieve unlimited records.')
args = parser.parse_args()

#location = '/trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006'
#location = '#g_primzuluft_trend/m006'
#startDate = '05/10/2017 08:00:00 AM'
#endDate = '05/10/2017 01:00:00 PM'
#limitFromStart = False
#maxRecords = 10

if args.path == None:
print 'Path is undifined. Type "$ wc_getTrend --help" for details.'
sys.exit(0)
if args.sTime == None:
print 'Start time is undefined. Use -s to define date and time.'
if args.eTime == None:
print 'End time is undefined. Use -e to define date and time.'

username = 'wsdl'
password = 'seife'
Expand All @@ -26,19 +49,13 @@
print("Unexpected error:", sys.exc_info()[0])
sys.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)
trendData = client.service.getTrendData(args.path, args.sTime, args.eTime, args.limit, args.maxRec)
except suds.WebFault as fault:
print fault
sys.exit(1)

print trendData
for x in range(0, args.maxRec*2-1, 2):
print trendData[x] + ' ' + trendData[x+1]

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

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???"'
sys.exit(1)
else:
path = sys.argv[1]
if len(sys.argv) < 2:
print "You haven't specified any arguments but I need a path. Use -h to get more details on how to use this command."

parser = argparse.ArgumentParser()
parser.add_argument('--path', '-p', type=str, default=None,
help='Full path to the point or node whose value is desired. Start querying by typing: $ wc_query /trees/geographic')
args = parser.parse_args()

username = 'wsdl'
password = 'seife'
Expand All @@ -27,7 +27,7 @@
sys.exit(1)

try:
value = client.service.getValue(path)
value = client.service.getValue(args.path)
except suds.WebFault as fault:
print fault
sys.exit(1)
Expand All @@ -36,6 +36,6 @@
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
print "Present value of " + args.path + " is: " + value

sys.exit(0)
19 changes: 10 additions & 9 deletions wc_query.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import suds
import sys
import xml
import argparse

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'
sys.exit(1)
else:
path = sys.argv[1]
if len(sys.argv) < 2:
print "You haven't specified any arguments but I need a path. Use -h to get more details on how to use this command."

parser = argparse.ArgumentParser()
parser.add_argument('--path', '-p', type=str, default=None,
help='Path to the point or node whose children you want to retrieve. Start querying with "-p /trees/geographic"')
args = parser.parse_args()

username = 'wsdl'
password = 'seife'
Expand All @@ -26,8 +27,8 @@
sys.exit(1)

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

0 comments on commit 22700cc

Please sign in to comment.