diff --git a/README b/README new file mode 100644 index 0000000..127e9fa --- /dev/null +++ b/README @@ -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. + + diff --git a/build_project.sh b/build_project.sh new file mode 100755 index 0000000..82b8d0f --- /dev/null +++ b/build_project.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +PYDIR=. +INSTALLDIR=dist/. + +for FILE in ${PYDIR}/*.py; do + pyinstaller --distpath ${INSTALLDIR} ${FILE} +done + + + diff --git a/wc_getTrend.py b/wc_getTrend.py index 5a3bf75..44f6e8b 100644 --- a/wc_getTrend.py +++ b/wc_getTrend.py @@ -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] @@ -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' @@ -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) diff --git a/wc_getValue.py b/wc_getValue.py index 1150472..a6278ce 100644 --- a/wc_getValue.py +++ b/wc_getValue.py @@ -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] @@ -21,17 +21,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: 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:" @@ -39,4 +38,4 @@ else: print "Present value of " + path + " is: " + value -exit(0) +sys.exit(0) diff --git a/wc_query.py b/wc_query.py index ae0ddf3..b40d234 100644 --- a/wc_query.py +++ b/wc_query.py @@ -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] @@ -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) diff --git a/wc_report.py b/wc_report.py index 6d71b74..bd13ca1 100644 --- a/wc_report.py +++ b/wc_report.py @@ -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] @@ -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") @@ -89,4 +88,4 @@ c = c + n * '-' + '---' print c -exit(0) +sys.exit(0)