Skip to content

Commit

Permalink
Added README file and a build script; minor changes in error handling…
Browse files Browse the repository at this point in the history
… in the *.py files
  • Loading branch information
weiher committed May 23, 2017
1 parent 7b7ce77 commit 3464603
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 25 deletions.
28 changes: 28 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Python-based command line tools for accessing a WebCTRL server via its WSDL interface

Prerequisits
------------

1) Python 2.7
2) In order to use the WSDL API you need to download and install the SUDS python package
Download suds-0.4.tar.gz here: https://pypi.python.org/pypi/suds
Install via command line: $ sudo pip install suds-0.4.tar.gz
3) If you don't want to execute the scripts from within an IDE (e.g. Pycharm) you could install pythoninstaller
to build the tools: $ sudo pip install pyinstaller

Building the tools
------------------

webctrl$ ./build_project.sh

The executables can be found in ./dist/wc_*/wc_*

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.


11 changes: 11 additions & 0 deletions build_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

PYDIR=.
INSTALLDIR=dist/.

for FILE in ${PYDIR}/*.py; do
pyinstaller --distpath ${INSTALLDIR} ${FILE}
done



11 changes: 5 additions & 6 deletions wc_getTrend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
print '$ wc_getTrend /trees/geographic/#path/#to/#controller/m???'
print 'or:'
print '$ wc_getTrend "#controller/m???"'
exit(1)
sys.exit(1)
else:
path = sys.argv[1]

Expand All @@ -21,11 +21,10 @@
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)
sys.exit(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
exit(1)
sys.exit(1)


location = '#g_umluftkw_trend/m009'
Expand All @@ -38,8 +37,8 @@
trendData = client.service.getTrendData(location, startDate, endDate, limitFromStart, maxRecords)
except suds.WebFault as fault:
print fault
exit(1)
sys.exit(1)

print trendData

exit(0)
sys.exit(0)
11 changes: 5 additions & 6 deletions wc_getValue.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
print '$ wc_getValue /trees/geographic/#path/#to/#controller/m???'
print 'or:'
print '$ wc_getValue "#controller/m???"'
exit(1)
sys.exit(1)
else:
path = sys.argv[1]

Expand All @@ -21,22 +21,21 @@
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)
sys.exit(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
exit(1)
sys.exit(1)

try:
value = client.service.getValue(path)
except suds.WebFault as fault:
print fault
exit(1)
sys.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)
sys.exit(0)
11 changes: 5 additions & 6 deletions wc_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
print 'Usage of this command:'
print '$ wc_query /trees/geographic/#path/#to/#controller'
print 'Start querying by typing: $ wc_query /trees/geographic'
exit(1)
sys.exit(1)
else:
path = sys.argv[1]

Expand All @@ -20,17 +20,16 @@
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)
sys.exit(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
exit(1)
sys.exit(1)

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

exit(0)
sys.exit(0)
13 changes: 6 additions & 7 deletions wc_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
print 'These are the possible types of reports:'
for rtype in reportTypes:
print rtype
exit(0)
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
exit(0)
sys.exit(0)
else:
path = sys.argv[1]
reportType = sys.argv[2]
Expand All @@ -35,18 +35,17 @@
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)
sys.exit(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
exit(1)
sys.exit(1)

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

# Split the report into separate lines and calculate the number of columns
lines = report.split("\n")
Expand Down Expand Up @@ -89,4 +88,4 @@
c = c + n * '-' + '---'
print c

exit(0)
sys.exit(0)

0 comments on commit 3464603

Please sign in to comment.