From 4c9acce2a8bf79a59ee964d29373afb00241cd1b Mon Sep 17 00:00:00 2001 From: Stefan Weiher Date: Tue, 1 Aug 2017 14:20:13 +0200 Subject: [PATCH] Mostly changes in the argument handling: now, almost all arguments can be passed via command line and via the settings file; established default values; tested the correct functionality of all tools and created new examples; updated the README file --- EXAMPLES | 197 ++++++++++++++++++++++++++-------------------- README | 22 +++++- SETTINGS | 18 +++-- wc_checkAlarms.py | 108 ++++++++++++++++--------- wc_getReport.py | 42 ++++++---- wc_getTrend.py | 100 ++++++++++++++--------- wc_getValue.py | 34 +++++--- wc_monitor.py | 34 +++++--- wc_query.py | 34 +++++--- 9 files changed, 365 insertions(+), 224 deletions(-) diff --git a/EXAMPLES b/EXAMPLES index 22ff81b..c3b6174 100644 --- a/EXAMPLES +++ b/EXAMPLES @@ -3,52 +3,67 @@ Example(s) for each of the webctrl command line tools ### wc_query - Query the children of a node -$ ./wc_query -u wsdl -n /trees/geographic +webctrl/bin$ ./wc_query -u wsdl -f ../SETTINGS -n /trees/geographic No password specified via -p. Please enter your WebCTRL login password: Children of "/trees/geographic": [#verbrauchszaehlung, #geb_a, #geb_b, #geb_c, #geb_d, #geb_e, #geb_f, #geb_g, #geb_k, #geb_l, #geb_m, #geb_pnq, ...] -$ ./wc_query -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel +webctrl/bin$ ./wc_query -u wsdl -f ../SETTINGS -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel No password specified via -p. Please enter your WebCTRL login password: Children of "/trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel": -[m032, m007, m008, m034, m033, m001, m005, m004, m003, m002, m006, ...] +[m032, m007, m008, m034, m033, m001, m005, m004, m003, m002, m006, m019, m020, m017, m018, m012, m013, m014, m015, ...] + +ODER: + +/webctrl/bin$ ./wc_query -u wsdl -f ../SETTINGS -n '#km_speicher_fel' +No password specified via -p. Please enter your WebCTRL login password: +Children of "#km_speicher_fel": +[m032, m007, m008, m034, m033, m001, m005, m004, m003, m002, m006, m019, m020, m017, m018, m012, m013, m014, m015, ...] ### wc_getValue - get the present value (the present_value attribute) of a m??? controller -$ ./wc_getValue -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel/m001 +webctrl/bin$ ./wc_getValue -u wsdl -f ../SETTINGS -n '#km_speicher_fel/m001' +No password specified via -p. Please enter your WebCTRL login password: +Present value of #km_speicher_fel/m001 is: 15.187662 + +OR with WC_NODE='#km_speicher_fel/m001' in the SETTINGS file: + +webctrl/bin$ ./wc_getValue -u wsdl -f ../SETTINGS No password specified via -p. Please enter your WebCTRL login password: -Present value of /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel/m001 is: 15.600924 +Present value of #km_speicher_fel/m001 is: 15.342966 ### wc_monitor - monitor a specific controller -$ ./wc_monitor -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel/m003 +# with WC_NODE='#km_speicher_fel/m001' in the SETTINGS file: +webctrl/bin$ ./wc_monitor -u wsdl -f ../SETTINGS No password specified via -p. Please enter your WebCTRL login password: -16:48:09 9.033137 -16:48:17 8.982448 -16:48:39 8.931475 +09:54:49 15.342966 +09:54:51 15.290968 +09:55:38 15.342427 +09:56:18 15.393141 ^CExiting due to keyboard interupt... ### wc_getReport - get a report for a node (one level lower than m???) -$ ./wc_getReport -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel/m001 +webctrl/bin$ ./wc_getReport -u wsdl -f ../SETTINGS -n '#km_speicher_fel/m001' No password specified via -p. Please enter your WebCTRL login password: | Standort | |--------------------------------------------------------------- | Fr die aktuellen Optionen wurden keine Ergebnisse gefunden.x | -$ ./wc_getReport -u wsdl -n /trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel +webctrl/bin$ ./wc_getReport -u wsdl -f ../SETTINGS -n '#km_speicher_fel' No password specified via -p. Please enter your WebCTRL login password: | Standort | Regelungsprogramm | Name | Wert | Typ | Objekt-ID | Gerte-ID | Objektname | Offset/Polaritt | Pfad | |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Durchflussmenge Verteiler | 6.5 m3/Std. | BMAI | AI:315818 | DEV:34157 | m032_5 | | #km_speicher_fel/m032 | -| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Kltemaschine Rcklauftemperatur x | 9.724116 C | BMAI | AI:2796280 | DEV:34157 | m007_5 | | #km_speicher_fel/m007 | -| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Kltemaschine Vorlauftemperatur | 8.348758 C | BMAI | AI:2796279 | DEV:34157 | m008_5 | | #km_speicher_fel/m008 | +| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Durchflussmenge Verteiler | 6.0 m3/Std. | BMAI | AI:315818 | DEV:34157 | m032_5 | | #km_speicher_fel/m032 | +| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Kltemaschine Rcklauftemperatur x | 9.684903 C | BMAI | AI:2796280 | DEV:34157 | m007_5 | | #km_speicher_fel/m007 | +| /Fritz-Haber-Institut/Bauteil E/Kaltwassererzeuger | Kaltwassererzeuger | FEL Kaltwasser Kltemaschine Vorlauftemperatur | 9.069413 C | BMAI | AI:2796279 | DEV:34157 | m008_5 | | #km_speicher_fel/m008 | | ... @@ -56,104 +71,116 @@ No password specified via -p. Please enter your WebCTRL login password: ### wc_getTrend - get timestamps and data values of a specific controller for a specific time period ### If no time period and number of values to retrieve are specified you'll get the last ten values -$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 +webctrl/bin$ ./wc_getTrend -u wsdl -f ../SETTINGS -n '#g_primzuluft_trend/m006' No password specified via -p. Please enter your WebCTRL login password: -Start time is undefined. Use -s to define date and time. -End time is undefined. Use -e to define date and time. -05/30/2017 02:19:00 PM 63.292435 -05/30/2017 02:20:00 PM 63.292435 -05/30/2017 02:21:00 PM 63.292435 -05/30/2017 02:22:00 PM 63.292435 -05/30/2017 02:23:00 PM 63.292435 -05/30/2017 02:24:00 PM 63.292435 -05/30/2017 02:25:00 PM 63.292435 -05/30/2017 02:26:00 PM 63.292435 -05/30/2017 02:27:00 PM 63.292435 -05/30/2017 02:28:00 PM 63.292435 +No start time specified. ... +No end time specified. ... +No parameter 'limit' specified. ... +No parameter 'maxRec' specified. ... +08/01/2017 09:30:00 AM 49.748962 +08/01/2017 09:45:00 AM 49.74543 +08/01/2017 10:00:00 AM 49.6482 +08/01/2017 10:15:00 AM 50.137894 +08/01/2017 10:30:00 AM 51.30997 +08/01/2017 10:45:00 AM 51.014744 +08/01/2017 11:00:00 AM 51.01651 +08/01/2017 11:15:00 AM 51.205673 +08/01/2017 11:30:00 AM 51.209206 +08/01/2017 11:45:00 AM 51.01651 ### Specify the amount of values you want to retrieve starting from the time of retrieval -$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 -m 5 +webctrl/bin$ ./wc_getTrend -u wsdl -f ../SETTINGS -n '#g_primzuluft_trend/m006' No password specified via -p. Please enter your WebCTRL login password: -Start time is undefined. Use -s to define date and time. -End time is undefined. Use -e to define date and time. -05/30/2017 04:25:00 PM 63.783897 -05/30/2017 04:26:00 PM 63.783897 -05/30/2017 04:27:00 PM 63.783897 -05/30/2017 04:28:00 PM 63.783897 -05/30/2017 04:29:00 PM 63.783897 +No start time specified. ... +No end time specified. ... +No parameter 'limit' specified. ... +No parameter 'maxRec' specified. ... +08/01/2017 10:45:00 AM 51.014744 +08/01/2017 11:00:00 AM 51.01651 +08/01/2017 11:15:00 AM 51.205673 +08/01/2017 11:30:00 AM 51.209206 +08/01/2017 11:45:00 AM 51.01651 ### Specify the amount of values you want to retrieve starting from the beginning of recording the specified controller -$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 -m 5 -l +### by using the -l switch +webctrl/bin$ ./wc_getTrend -u wsdl -f ../SETTINGS -n '#g_primzuluft_trend/m006' -m 5 -l No password specified via -p. Please enter your WebCTRL login password: -Start time is undefined. Use -s to define date and time. -End time is undefined. Use -e to define date and time. -03/15/2017 04:10:48 PM 0.0 -03/15/2017 04:10:48 PM 0.0 -03/15/2017 04:12:21 PM 33.726974 -05/30/2017 04:27:00 PM 63.783897 -05/30/2017 04:28:00 PM 63.783897 - -### The usage of the date+time options -s and -e are examplified. -l ist not specified, thus, the last ten values are returned: -$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 -s '05/30/2017 03:00:00 AM' -e '05/30/2017 06:00:00 AM' +No start time specified. ... +No end time specified. ... +05/03/2017 12:13:27 AM 45.4478 +05/03/2017 05:43:32 AM 44.273945 +05/03/2017 06:23:31 AM 43.200867 +05/03/2017 07:13:32 AM 42.028778 +05/03/2017 08:26:02 AM 47.01764 + +### The usage of the date+time options -s and -e as well as in connection to -l are examplified: +webctrl/bin$ ./wc_getTrend -u wsdl -f ../SETTINGS -n '#g_primzuluft_trend/m006' -m 5 -s '07/30/2017 03:00:00 AM' -e '07/30/2017 06:00:00 AM' No password specified via -p. Please enter your WebCTRL login password: -05/30/2017 05:51:00 AM 59.97419 -05/30/2017 05:52:00 AM 59.97419 -05/30/2017 05:53:00 AM 59.97419 -05/30/2017 05:54:00 AM 59.97419 -05/30/2017 05:55:00 AM 59.97419 -05/30/2017 05:56:00 AM 59.97419 -05/30/2017 05:57:00 AM 59.97419 -05/30/2017 05:58:00 AM 59.97419 -05/30/2017 05:59:00 AM 59.97419 -05/30/2017 06:00:00 AM 59.97419 - -### -l is specified, thus, the first ten values starting from the time given in -s are returned: -$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 -s '05/30/2017 03:00:00 AM' -e '05/30/2017 06:00:00 AM' -l +No parameter 'limit' specified. ... +07/30/2017 05:00:00 AM 49.358273 +07/30/2017 05:15:00 AM 49.358273 +07/30/2017 05:30:00 AM 49.360043 +07/30/2017 05:45:00 AM 49.25927 +07/30/2017 06:00:00 AM 49.26281 +stefan@muonio: ~/PycharmProjects/webctrl/bin$ ./wc_getTrend -u wsdl -f ../SETTINGS -n '#g_primzuluft_trend/m006' -m 5 -s '07/30/2017 03:00:00 AM' -e '07/30/2017 06:00:00 AM' -l No password specified via -p. Please enter your WebCTRL login password: -05/30/2017 03:01:00 AM 63.87936 -05/30/2017 03:02:00 AM 63.87936 -05/30/2017 03:03:00 AM 63.87936 -05/30/2017 03:04:00 AM 64.26652 -05/30/2017 03:05:00 AM 64.26652 -05/30/2017 03:06:00 AM 64.26652 -05/30/2017 03:07:00 AM 64.26652 -05/30/2017 03:08:00 AM 64.26652 -05/30/2017 03:09:00 AM 64.26652 -05/30/2017 03:10:00 AM 64.26652 - -### Get all values (-m 0) between the times given in -s and -e: -$ python wc_getTrend.py -u wsdl -n /trees/geographic/#geb_g/#g_luft/#primzuluft_1_2_stm/#g_primzuluft_trend/m006 -s '05/30/2017 03:00:00 AM' -e '05/30/2017 04:00:00 AM' -l -m 0 +07/30/2017 03:15:00 AM 49.361805 +07/30/2017 03:30:00 AM 49.55097 +07/30/2017 03:45:00 AM 49.55627 +07/30/2017 04:00:00 AM 49.459038 +07/30/2017 04:15:00 AM 49.552734 + +### Get all values (-m 0) between the times given in -s and -e. Notice the difference when using -l: +webctrl/bin$ ./wc_getTrend -u wsdl -f SETTINGS -n '#g_primzuluft_trend/m006' -m 5 -s '07/30/2017 03:00:00 AM' -e '07/30/2017 06:00:00 AM' -m 0 No password specified via -p. Please enter your WebCTRL login password: -05/30/2017 03:01:00 AM 63.87936 -05/30/2017 03:02:00 AM 63.87936 -05/30/2017 03:03:00 AM 63.87936 -05/30/2017 03:04:00 AM 64.26652 +No parameter 'limit' specified. ... +07/30/2017 03:15:00 AM 49.361805 +07/30/2017 03:30:00 AM 49.55097 +07/30/2017 03:45:00 AM 49.55627 ... -05/30/2017 03:57:00 AM 60.07319 -05/30/2017 03:58:00 AM 60.07319 -05/30/2017 03:59:00 AM 60.07319 -05/30/2017 04:00:00 AM 60.07319 +07/30/2017 05:30:00 AM 49.360043 +07/30/2017 05:45:00 AM 49.25927 +07/30/2017 06:00:00 AM 49.26281 +webctrl/bin$ ./wc_getTrend -u wsdl -f SETTINGS -n '#g_primzuluft_trend/m006' -m 5 -s '07/30/2017 03:00:00 AM' -e '07/30/2017 06:00:00 AM' -m 0 -l +No password specified via -p. Please enter your WebCTRL login password: +07/30/2017 03:00:00 AM 49.552734 +07/30/2017 03:15:00 AM 49.361805 +07/30/2017 03:30:00 AM 49.55097 +... +07/30/2017 05:15:00 AM 49.358273 +07/30/2017 05:30:00 AM 49.360043 +07/30/2017 05:45:00 AM 49.25927 + ### wc_checkAlarms - check all alarms of a specified node -$ python wc_checkAlarms.py -u wsdl -n /trees/geographic -i 1 -a 1 -No password specified via -p. Please enter your WebCTRL login password: +webctrl/bin$ ./wc_checkAlarms -u wsdl -f SETTINGS -i 1 -t 1 +No password specified via -p. Please enter your WebCTRL login password now: +No verbosity specified. ... +No interval specified. ... +No time to take action specified. ... + +# You don't see anything if there are no unhandled/unchecked alarms. So, switch on the verbose output to see a bit +# what's happening: + +webctrl/bin$ ./wc_checkAlarms -u wsdl -f SETTINGS -i 1 -t 1 -v +No password specified via -p. Please enter your WebCTRL login password now: Appending alarm 2017-07-25 12:24:25 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung to alarmsActive Removing alarm 2017-07-25 12:24:37 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung from alarmsActive Appending alarm 2017-07-25 13:14:21 DI_Wasser_Sensor_Lichtschacht_TZ to alarmsActive No alarms in list alarmsChecked (datetime.datetime(2017, 7, 25, 13, 14, 21), '/Fritz-Haber-Institut/Bauteil R/Meldungen/Geb.R Meldungen', 'Geb.R Wasser-Sensor Lichtschacht Technikzentrale Keller ausgelst!', 'DI_Wasser_Sensor_Lichtschacht_TZ', 'Nicht besttigt', 'Heizung, Lftung, Klimatechnik - Allgemein', 'Unnormal') -Age: 0 +Age: 0.0 Appending alarm 2017-07-25 12:24:25 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung to alarmsActive Removing alarm 2017-07-25 12:24:37 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung from alarmsActive No alarms in list alarmsChecked (datetime.datetime(2017, 7, 25, 13, 14, 21), '/Fritz-Haber-Institut/Bauteil R/Meldungen/Geb.R Meldungen', 'Geb.R Wasser-Sensor Lichtschacht Technikzentrale Keller ausgelst!', 'DI_Wasser_Sensor_Lichtschacht_TZ', 'Nicht besttigt', 'Heizung, Lftung, Klimatechnik - Allgemein', 'Unnormal') -Age: 1 +Age: 1.0 Sending an e-mail to weiher@fhi-berlin.mpg.de Appending alarm 2017-07-25 12:24:25 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung to alarmsActive Removing alarm 2017-07-25 12:24:37 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung from alarmsActive No alarms in list alarmsChecked (datetime.datetime(2017, 7, 25, 13, 14, 21), '/Fritz-Haber-Institut/Bauteil R/Meldungen/Geb.R Meldungen', 'Geb.R Wasser-Sensor Lichtschacht Technikzentrale Keller ausgelst!', 'DI_Wasser_Sensor_Lichtschacht_TZ', 'Nicht besttigt', 'Heizung, Lftung, Klimatechnik - Allgemein', 'Unnormal') -Age: 2 +Age: 2.0 Sending an e-mail to weiher@fhi-berlin.mpg.de diff --git a/README b/README index 6da72f0..a8e2ac1 100644 --- a/README +++ b/README @@ -63,7 +63,23 @@ To be able to import the wc_* tools append to the PYTHONPATH the webctrl directo 2) Set the python path inside the python script before the import statement: sys.path.append('/path/to/webctrl') +Set the PATH variable to be able to execute the compiled wc tools system-wide: PATH=$PATH:/path/to/webctrl/bin + +Argument passing +---------------- + +There are three ways to pass arguments to the tools: + +1) webctrl$ python wc_query.py -n '/trees/geographic' or + webctrl$ ./bin/wc_query -n '/trees/geographic' + +2) via a dictonary, myDictionary = {..., 'node':'/trees/geographic', ...}, when using one of the tools in another python + script: wc_query.main(myDictonary) + +3) via the SETTINGS file, e.g.: WC_NODE='/trees/geographic' + +To see which arguments are required and which ones are optional type: webctrl$ python wc_*.py -h +All required arguments (except the password for the WebCTRL login) need to be passed in any one of the three above ways. +The password cannot be given via the SETTINGS file. If the password is not specified via -p you will be prompted to +type it interactively. All optional arguments have default values which will be shown to you when using one of the tools. -Alle Argumente können via Kommandozeile UND via Env. Var. angegeben werden. Es werden KEINE Defaults gesetzt. -Die URL ist nur über die Env. Var. setzbar. -Das Passwort ist nur via Kommandozeile setzbar. diff --git a/SETTINGS b/SETTINGS index 8d44e34..bab0111 100644 --- a/SETTINGS +++ b/SETTINGS @@ -1,16 +1,20 @@ WC_USERNAME = 'wsdl' #WC_NODE = '/trees/geographic' -WC_NODE = '/trees/geographic/#geb_e/#kaltw_erzeuger_fel/#km_speicher_fel' +WC_NODE = '#km_speicher_fel' WC_URL = 'https://webctrl.rz-berlin.mpg.de' +WC_VERBOSITY = + # wc_checkAlarms WC_ALARMS_ALERT_EMAIL = 'weiher@fhi-berlin.mpg.de,weiher@fhi-berlin.mpg.de,weiher@fhi-berlin.mpg.de' WC_ALARMS_ALERT_PERIODS = '8-16,16-22,22-8' -WC_ALARMS_INTERVAL = 1 -WC_ALARMS_TAKEACTION = 1 +WC_ALARMS_INTERVAL = +WC_ALARMS_TAKEACTION = + # wc_getReport WC_REPORT_TYPE = '~point-list-report' + # wc_getTrend -WC_TREND_STIME = '' -WC_TREND_ETIME = '' -WC_TREND_LIMIT = '' -WC_TREND_MAXREC = '' \ No newline at end of file +WC_TREND_STIME = +WC_TREND_ETIME = +WC_TREND_LIMIT = +WC_TREND_MAXREC = \ No newline at end of file diff --git a/wc_checkAlarms.py b/wc_checkAlarms.py index 17410f9..0a8e3f8 100644 --- a/wc_checkAlarms.py +++ b/wc_checkAlarms.py @@ -45,7 +45,7 @@ def main(args): sys.exit(1) # The password cannot be given via environment variable - errorMessage = "No password specified. Provide one via '-p my_password' or {..., 'password':'my_password', ...}" + errorMessage = "No password specified. Provide one via {..., 'password':'my_password', ...}" try: if args['password'] is None or not args['password']: print(errorMessage) @@ -56,63 +56,90 @@ def main(args): print(errorMessage) sys.exit(1) - errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node" + verbosityDefault = False + errorMessage = "No verbosity specified. Provide one via '-v my_verbosity' or {..., 'verbosity':'my_verbosity', ...} or WC_VERBOSITY=my_verbosity. " \ + "Using a default now: '" + str(verbosityDefault) + "'" + try: + if args['verbosity'] is None or not args['verbosity']: + if not settings['WC_VERBOSITY']: + print(errorMessage) + verbosity = verbosityDefault + else: + verbosity = settings['WC_VERBOSITY'] + else: + verbosity = str(args['verbosity']) + except KeyError: + print(errorMessage) + verbosity = verbosityDefault + + nodeDefault = '/trees/geographic' + errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node. " \ + "Using a default now: '" + nodeDefault + "'" try: if args['node'] is None or not args['node']: if not settings['WC_NODE']: print(errorMessage) - sys.exit(1) + node = nodeDefault else: node = settings['WC_NODE'] else: node = str(args['node']) except KeyError: print(errorMessage) - sys.exit(1) + node = nodeDefault - errorMessage = "No URL specified. Provide one via WC_URL=my_url" - url = settings['WC_URL'] + urlDefault = 'https://webctrl.rz-berlin.mpg.de' + errorMessage = "No URL specified. Provide one via '-url my_url' or {..., 'url':'my_url', ...} or WC_URL=my_url. " \ + "Using a default now: '" + urlDefault + "'" try: - if not url: - print(errorMessage) - sys.exit(1) + if args['url'] is None or not args['url']: + if not settings['WC_URL']: + print(errorMessage) + url = urlDefault + else: + url = settings['WC_URL'] else: - wsdlFile = url + '/_common/webservices/Report?wsdl' + url = str(args['url']) except KeyError: print(errorMessage) - sys.exit(1) + url = urlDefault + wsdlFile = url + '/_common/webservices/Report?wsdl' - errorMessage = "No interval specified. Provide one via '-i my_interval' or {..., 'interval':'my_interval', ...} or WC_ALARMS_INTERVAL=my_interval" + intervalDefault = 5.0 + errorMessage = "No interval specified. Provide one via '-i my_interval' or {..., 'interval':'my_interval', ...} or " \ + "WC_ALARMS_INTERVAL=my_interval. Using a default now: " + str(intervalDefault) + " minutes" try: if args['interval'] is None or not args['interval']: - if float(settings['WC_ALARMS_INTERVAL']) is None: + if not settings['WC_ALARMS_INTERVAL']: print(errorMessage) - sys.exit(1) + interval = intervalDefault else: interval = float(settings['WC_ALARMS_INTERVAL']) else: interval = args['interval'] except KeyError: print(errorMessage) - sys.exit(1) + interval = intervalDefault if interval <= 0.0: print 'The interval must be bigger than 0.0.' sys.exit(1) checkForNewAlarmsInterval = interval - errorMessage = "No time to take action specified. Provide one via '-a my_takeAction' or {..., 'takeAction':'my_takeAction', ...} or WC_ALARMS_TAKEACTION=my_takeAction" + takeActionDefault = 10.0 + errorMessage = "No time to take action specified. Provide one via '-a my_takeAction' or {..., 'takeAction':'my_takeAction', ...} " \ + "or WC_ALARMS_TAKEACTION=my_takeAction. Using a default now: " + str(takeActionDefault) + " minutes" try: if args['takeAction'] is None or not args['takeAction']: - if float(settings['WC_ALARMS_TAKEACTION']) is None: + if not settings['WC_ALARMS_TAKEACTION']: print(errorMessage) - sys.exit(1) + takeAction = takeActionDefault else: takeAction = float(settings['WC_ALARMS_TAKEACTION']) else: takeAction = args['takeAction'] except KeyError: print(errorMessage) - sys.exit(1) + takeAction = takeActionDefault if takeAction <= 0.0: print 'The time to take action must be bigger than 0.0.' sys.exit(1) @@ -159,10 +186,11 @@ def main(args): print fault sys.exit(1) - lines = report.split("\n") - lines = lines[1:] - #file = open("testAlarms.txt", "r") - #lines = file.read().split("\n") + #lines = report.split("\n") + #lines = lines[1:] + # Comment above two lines and uncomment below two lines in order to test the program + file = open("testAlarms.txt", "r") + lines = file.read().split("\n") # Go through the report and create alarm objects distinguishing by their current alarm status. # Start looping from the last line in order to process the oldest alarms first. @@ -216,7 +244,7 @@ def main(args): # Remove alarm from running and do not append to checked removedAlarm = True alarmsActive.remove(a) - print('Removing alarm ' + str(date) + ' ' + quelle + ' from alarmsActive') + if verbosity: print('Removing alarm ' + str(date) + ' ' + quelle + ' from alarmsActive') if not removedAlarm: # Ignore the alarms that have a 'Normal' status without another matching alarm with 'Unnormal' # status because it's already solved @@ -232,28 +260,30 @@ def main(args): # Observe the age of the alarm, i.e, increase the age by the time interval in which new alarms are caught a.age += checkForNewAlarmsInterval if not alarmAlreadyKnown: - print('Appending alarm ' + str(date) + ' ' + quelle + ' to alarmsActive') + if verbosity: print('Appending alarm ' + str(date) + ' ' + quelle + ' to alarmsActive') age = 0.0 alarmsActive.append(alarm(date, age, standort, message, quelle, bestaetigtVon, kategorie, status)) - if alarmsChecked: - for a in alarmsChecked: - print(a.date, a.standort, a.message, a.quelle, a.bestaetigtVon, a.kategorie, a.status) - else: - print('No alarms in list alarmsChecked') + if verbosity: + if alarmsChecked: + for a in alarmsChecked: + print(a.date, a.standort, a.message, a.quelle, a.bestaetigtVon, a.kategorie, a.status) + else: + print('No alarms in list alarmsChecked') if alarmsActive: for a in alarmsActive: - print(a.date, a.standort, a.message, a.quelle, a.bestaetigtVon, a.kategorie, a.status) + if verbosity: + print(a.date, a.standort, a.message, a.quelle, a.bestaetigtVon, a.kategorie, a.status) + print 'Age: ' + str(a.age) # Check the age of the still active alarms and take action in case of, for example, the age is greater than e.g. 20 min - print 'Age: ' + str(a.age) if a.age >= takeActionTime: currentHour = datetime.datetime.now().hour mailAddress = getMailAddress(currentHour, settings['WC_ALARMS_ALERT_EMAIL'], settings['WC_ALARMS_ALERT_PERIODS']) - print 'Sending an e-mail to ' + mailAddress + if verbosity: print 'Sending an e-mail to ' + mailAddress sendEmail(mailAddress, a.date, a.standort, a.message, a.quelle) else: - print('No alarms in list alarmsActive') + if verbosity: print('No alarms in list alarmsActive') # sleep for n minutes sleep(checkForNewAlarmsInterval*60) @@ -272,7 +302,11 @@ def main(args): optional = parser.add_argument_group('optional arguments (can also be specified via SETTINGS file)') required.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') required.add_argument('--settingsFile', '-f', type=str, default=None, help='File name of settings containing WC_* variables') - optional.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + required.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + + optional.add_argument('--verbosity', '-v', action='store_true', default=None, help="If '-v' is selected you'll get verbose output") + + optional.add_argument('--url', '-url', type=str, default=None, help="URL of the webctrl server like 'http(s)://webctrl.de'.") optional.add_argument('--node', '-n', type=str, default=None, help='Path to the point or node whose children you want to retrieve. Start querying at the lowest level with "-n /trees/geographic"') optional.add_argument('-interval', '-i', type=int, default=None, help="Interval in MINUTES in which the script checks for new alarms") @@ -280,8 +314,8 @@ def main(args): args = parser.parse_args() # Get the password if it hasn't been passed as argument - if args.password is None: - args.password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') + if args.password is None or not args.password: + args.password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password now: ') # Convert the argparse.Namespace to a dictionary via vars(args) main(vars(args)) diff --git a/wc_getReport.py b/wc_getReport.py index 68a9a9d..59091c8 100644 --- a/wc_getReport.py +++ b/wc_getReport.py @@ -42,7 +42,7 @@ def main(args): sys.exit(1) # The password cannot be given via environment variable - errorMessage = "No password specified. Provide one via '-p my_password' or {..., 'password':'my_password', ...}" + errorMessage = "No password specified. Provide one via {..., 'password':'my_password', ...}" try: if args['password'] is None or not args['password']: print(errorMessage) @@ -53,45 +53,54 @@ def main(args): print(errorMessage) sys.exit(1) - errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node" + nodeDefault = '/trees/geographic' + errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node. " \ + "Using a default now: '" + nodeDefault + "'" try: if args['node'] is None or not args['node']: if not settings['WC_NODE']: print(errorMessage) - sys.exit(1) + node = nodeDefault else: node = settings['WC_NODE'] else: node = str(args['node']) except KeyError: print(errorMessage) - sys.exit(1) + node = nodeDefault - errorMessage = "No URL specified. Provide one via WC_URL=my_url" - url = settings['WC_URL'] + urlDefault = 'https://webctrl.rz-berlin.mpg.de' + errorMessage = "No URL specified. Provide one via '-url my_url' or {..., 'url':'my_url', ...} or WC_URL=my_url. " \ + "Using a default now: '" + urlDefault + "'" try: - if not url: - print(errorMessage) - sys.exit(1) + if args['url'] is None or not args['url']: + if not settings['WC_URL']: + print(errorMessage) + url = urlDefault + else: + url = settings['WC_URL'] else: - wsdlFile = url + '/_common/webservices/Report?wsdl' + url = str(args['url']) except KeyError: print(errorMessage) - sys.exit(1) + url = urlDefault + wsdlFile = url + '/_common/webservices/Report?wsdl' - errorMessage = "No report type specified. Provide one via '-t my_reportType' or {..., 'reportType':'my_reportType', ...} or WC_REPORT_TYPE=my_reportType" + reportTypeDefault = '~point-list-report' + errorMessage = "No report type specified. Provide one via '-t my_reportType' or {..., 'reportType':'my_reportType', ...} " \ + "or WC_REPORT_TYPE=my_reportType" try: if args['reportType'] is None or not args['reportType']: if not settings['WC_REPORT_TYPE']: print(errorMessage) - sys.exit(1) + reportType = reportTypeDefault else: reportType = settings['WC_REPORT_TYPE'] else: reportType = str(args['reportType']) except KeyError: print(errorMessage) - sys.exit(1) + reportType = reportTypeDefault #################################################################################################################### ### Connect to the webCTRL server @@ -174,7 +183,8 @@ def main(args): optional = parser.add_argument_group('optional arguments (can also be specified via SETTINGS file)') required.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') required.add_argument('--settingsFile', '-f', type=str, default=None, help='File name of settings containing WC_* variables') - optional.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + required.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + optional.add_argument('--url', '-url', type=str, default=None, help="URL of the webctrl server like 'http(s)://webctrl.de'.") optional.add_argument('--node', '-n', type=str, default=None, help='Path to the point or node whose children you want to retrieve. Start querying at the lowest level with "-n /trees/geographic"') optional.add_argument('-reportType', '-t', type=str, default=None, @@ -184,7 +194,7 @@ def main(args): args = parser.parse_args() # Get the password if it hasn't been passed as argument - if args.password is None: + if args.password is None or not args.password: args.password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') # Convert the argparse.Namespace to a dictionary via vars(args) diff --git a/wc_getTrend.py b/wc_getTrend.py index b117ae6..21239e9 100644 --- a/wc_getTrend.py +++ b/wc_getTrend.py @@ -41,7 +41,7 @@ def main(args): sys.exit(1) # The password cannot be given via environment variable - errorMessage = "No password specified. Provide one via '-p my_password' or {..., 'password':'my_password', ...}" + errorMessage = "No password specified. Provide one via {..., 'password':'my_password', ...}" try: if args['password'] is None or not args['password']: print(errorMessage) @@ -52,84 +52,107 @@ def main(args): print(errorMessage) sys.exit(1) - errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node" + nodeDefault = '/trees/geographic' + errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node. " \ + "Using a default now: '" + nodeDefault + "'" try: if args['node'] is None or not args['node']: if not settings['WC_NODE']: print(errorMessage) - sys.exit(1) + node = nodeDefault else: node = settings['WC_NODE'] else: node = str(args['node']) except KeyError: print(errorMessage) - sys.exit(1) + node = nodeDefault - errorMessage = "No URL specified. Provide one via WC_URL=my_url" - url = settings['WC_URL'] + urlDefault = 'https://webctrl.rz-berlin.mpg.de' + errorMessage = "No URL specified. Provide one via '-url my_url' or {..., 'url':'my_url', ...} or WC_URL=my_url. " \ + "Using a default now: '" + urlDefault + "'" try: - if not url: - print(errorMessage) - sys.exit(1) + if args['url'] is None or not args['url']: + if not settings['WC_URL']: + print(errorMessage) + url = urlDefault + else: + url = settings['WC_URL'] else: - wsdlFile = url + '/_common/webservices/Report?wsdl' + url = str(args['url']) except KeyError: print(errorMessage) - sys.exit(1) + url = urlDefault + wsdlFile = url + '/_common/webservices/Trend?wsdl' + sTimeDefault = '' errorMessage = "No start time specified. Provide one via '-s my_stime' or {..., 'sTime':'my_sTime', ...} or WC_TREND_STIME=my_sTime. " \ - "sTime requires the following pattern: 'MM/DD/YYYY HH:MM:SS AM'. Using a default now." + "sTime requires the following pattern: 'MM/DD/YYYY HH:MM:SS AM'. Using a default now: sTime = '" + sTimeDefault + "'" try: if args['sTime'] is None or not args['sTime']: if not settings['WC_TREND_STIME']: print(errorMessage) - sys.exit(1) + sTime = sTimeDefault else: sTime = settings['WC_TREND_STIME'] else: sTime = str(args['sTime']) except KeyError: print(errorMessage) + sTime = sTimeDefault + eTimeDefault = '' errorMessage = "No end time specified. Provide one via '-e my_eTime' or {..., 'eTime':'my_eTime', ...} or WC_TREND_ETIME=my_eTime. " \ - "eTime requires the following pattern: 'MM/DD/YYYY HH:MM:SS PM'. Using a default now." + "eTime requires the following pattern: 'MM/DD/YYYY HH:MM:SS PM'. Using a default now: eTime = '" + eTimeDefault + "'" try: if args['eTime'] is None or not args['eTime']: if not settings['WC_TREND_ETIME']: print(errorMessage) - sys.exit(1) + eTime = eTimeDefault else: eTime = settings['WC_TREND_ETIME'] else: eTime = str(args['eTime']) except KeyError: print(errorMessage) + eTime = eTimeDefault + limitDefault = False errorMessage = "No parameter 'limit' specified. Provide one via '-l my_limit' or {..., 'limit':'my_limit', ...} or " \ "WC_TREND_LIMIT=my_limit. limit=False: a maximum number of records, 'maxRecords', is retrieved from the start of the " \ "specified time period. limit=True: 'maxRecords' are retrieved from the end of the time period. Now, " \ - "a default, limit=False, is set." + "a default, limit = " + str(limitDefault) + ", is set." try: if args['limit'] is None or not args['limit']: if not settings['WC_TREND_LIMIT']: print(errorMessage) - #sys.exit(1) - limit = False + # default value: + limit = limitDefault else: limit = settings['WC_TREND_LIMIT'] else: limit = str(args['limit']) except KeyError: print(errorMessage) - #sys.exit(1) - limit = False - - - # maxRec ... - # Default-Werte siehe unten - + limit = limitDefault + maxRecDefault = 10 + errorMessage = "No parameter 'maxRec' specified. Provide one via '-m my_maxRec' or {..., 'maxRec':'my_maxRec', ...} or " \ + "WC_TREND_MAXREC=my_maxRec. If possible a maximum number of records, 'maxRec', is retrieved. Now, " \ + "a default, maxRec = " + str(maxRecDefault) + ", is set." + try: + #if args['maxRec'] is None or not args['maxRec']: + if args['maxRec'] is None: + if not settings['WC_TREND_MAXREC']: + print(errorMessage) + maxRec = maxRecDefault + else: + maxRec = settings['WC_TREND_MAXREC'] + else: + maxRec = str(args['maxRec']) + except KeyError: + print(errorMessage) + maxRec = maxRecDefault #################################################################################################################### ### Connect to the webCTRL server @@ -152,7 +175,7 @@ def main(args): #################################################################################################################### try: - trendData = client.service.getTrendData(node, sTime, eTime, limit, args['maxRec']) + trendData = client.service.getTrendData(node, sTime, eTime, limit, maxRec) except suds.WebFault as fault: print fault sys.exit(1) @@ -173,24 +196,27 @@ def main(args): sys.exit(1) parser = argparse.ArgumentParser() - parser.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') - parser.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') - parser.add_argument('--node', '-n', type=str, default=None, + parser._action_groups.pop() + required = parser.add_argument_group('required arguments') + optional = parser.add_argument_group('optional arguments (can also be specified via SETTINGS file)') + required.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') + required.add_argument('--settingsFile', '-f', type=str, default=None, help='File name of settings containing WC_* variables') + required.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + optional.add_argument('--url', '-url', type=str, default=None, help="URL of the webctrl server like 'http(s)://webctrl.de'.") + optional.add_argument('--node', '-n', type=str, default=None, help='Path to the point or node whose children you want to retrieve. Start querying at the lowest level with "-n /trees/geographic"') - #parser.add_argument('-url', type=str, default='https://webctrl.rz-berlin.mpg.de', - # help="URL of the WebCTRL server as e.g. http://google.de") - parser.add_argument('--sTime', '-s', type=str, default=None, + optional.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, + optional.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', action='store_true', default=None, + optional.add_argument('--limit', '-l', action='store_true', default=None, help='If specified maxRecords are retrieved from the start. If not specified maxRecords are retrieved 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.') + optional.add_argument('--maxRec', '-m', type=int, default=None, + help="Maximum number of records desired. Use a number >0 to limit records; use '-m 0' to retrieve unlimited records.") args = parser.parse_args() # Get the password if it hasn't been passed as argument - if args.password is None: + if args.password is None or not args.password: args.password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') # Convert the argparse.Namespace to a dictionary via vars(args) diff --git a/wc_getValue.py b/wc_getValue.py index c885023..c61adc8 100644 --- a/wc_getValue.py +++ b/wc_getValue.py @@ -41,7 +41,7 @@ def main(args): sys.exit(1) # The password cannot be given via environment variable - errorMessage = "No password specified. Provide one via '-p my_password' or {..., 'password':'my_password', ...}" + errorMessage = "No password specified. Provide one via {..., 'password':'my_password', ...}" try: if args['password'] is None or not args['password']: print(errorMessage) @@ -52,31 +52,38 @@ def main(args): print(errorMessage) sys.exit(1) - errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node" + nodeDefault = '/trees/geographic' + errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node. " \ + "Using a default now: '" + nodeDefault + "'" try: if args['node'] is None or not args['node']: if not settings['WC_NODE']: print(errorMessage) - sys.exit(1) + node = nodeDefault else: node = settings['WC_NODE'] else: node = str(args['node']) except KeyError: print(errorMessage) - sys.exit(1) + node = nodeDefault - errorMessage = "No URL specified. Provide one via WC_URL=my_url" - url = settings['WC_URL'] + urlDefault = 'https://webctrl.rz-berlin.mpg.de' + errorMessage = "No URL specified. Provide one via '-url my_url' or {..., 'url':'my_url', ...} or WC_URL=my_url. " \ + "Using a default now: '" + urlDefault + "'" try: - if not url: - print(errorMessage) - sys.exit(1) + if args['url'] is None or not args['url']: + if not settings['WC_URL']: + print(errorMessage) + url = urlDefault + else: + url = settings['WC_URL'] else: - wsdlFile = url + '/_common/webservices/Eval?wsdl' + url = str(args['url']) except KeyError: print(errorMessage) - sys.exit(1) + url = urlDefault + wsdlFile = url + '/_common/webservices/Eval?wsdl' #################################################################################################################### ### Connect to the webCTRL server @@ -124,13 +131,14 @@ def main(args): optional = parser.add_argument_group('optional arguments (can also be specified via SETTINGS file)') required.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') required.add_argument('--settingsFile', '-f', type=str, default=None, help='File name of settings containing WC_* variables') - optional.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + required.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + optional.add_argument('--url', '-url', type=str, default=None, help="URL of the webctrl server like 'http(s)://webctrl.de'.") optional.add_argument('--node', '-n', type=str, default=None, help='Path to the point or node whose children you want to retrieve. Start querying at the lowest level with "-n /trees/geographic"') args = parser.parse_args() # Get the password if it hasn't been passed as argument - if args.password is None: + if args.password is None or not args.password: args.password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') # Convert the argparse.Namespace to a dictionary via vars(args) diff --git a/wc_monitor.py b/wc_monitor.py index aa642ad..e24182d 100644 --- a/wc_monitor.py +++ b/wc_monitor.py @@ -43,7 +43,7 @@ def main(args): sys.exit(1) # The password cannot be given via environment variable - errorMessage = "No password specified. Provide one via '-p my_password' or {..., 'password':'my_password', ...}" + errorMessage = "No password specified. Provide one via {..., 'password':'my_password', ...}" try: if args['password'] is None or not args['password']: print(errorMessage) @@ -54,31 +54,38 @@ def main(args): print(errorMessage) sys.exit(1) - errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node" + nodeDefault = '/trees/geographic' + errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node. " \ + "Using a default now: '" + nodeDefault + "'" try: if args['node'] is None or not args['node']: if not settings['WC_NODE']: print(errorMessage) - sys.exit(1) + node = nodeDefault else: node = settings['WC_NODE'] else: node = str(args['node']) except KeyError: print(errorMessage) - sys.exit(1) + node = nodeDefault - errorMessage = "No URL specified. Provide one via WC_URL=my_url" - url = settings['WC_URL'] + urlDefault = 'https://webctrl.rz-berlin.mpg.de' + errorMessage = "No URL specified. Provide one via '-url my_url' or {..., 'url':'my_url', ...} or WC_URL=my_url. " \ + "Using a default now: '" + urlDefault + "'" try: - if not url: - print(errorMessage) - sys.exit(1) + if args['url'] is None or not args['url']: + if not settings['WC_URL']: + print(errorMessage) + url = urlDefault + else: + url = settings['WC_URL'] else: - wsdlFile = url + '/_common/webservices/Eval?wsdl' + url = str(args['url']) except KeyError: print(errorMessage) - sys.exit(1) + url = urlDefault + wsdlFile = url + '/_common/webservices/Eval?wsdl' #################################################################################################################### ### Connect to the webCTRL server @@ -137,13 +144,14 @@ def main(args): optional = parser.add_argument_group('optional arguments (can also be specified via SETTINGS file)') required.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') required.add_argument('--settingsFile', '-f', type=str, default=None, help='File name of settings containing WC_* variables') - optional.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + required.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + optional.add_argument('--url', '-url', type=str, default=None, help="URL of the webctrl server like 'http(s)://webctrl.de'.") optional.add_argument('--node', '-n', type=str, default=None, help='Path to the point or node whose children you want to retrieve. Start querying at the lowest level with "-n /trees/geographic"') args = parser.parse_args() # Get the password if it hasn't been passed as argument - if args.password is None: + if args.password is None or not args.password: args.password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') # Convert the argparse.Namespace to a dictionary via vars(args) diff --git a/wc_query.py b/wc_query.py index a5ecada..41c6d60 100644 --- a/wc_query.py +++ b/wc_query.py @@ -41,7 +41,7 @@ def main(args): sys.exit(1) # The password cannot be given via environment variable - errorMessage = "No password specified. Provide one via '-p my_password' or {..., 'password':'my_password', ...}" + errorMessage = "No password specified. Provide one via {..., 'password':'my_password', ...}" try: if args['password'] is None or not args['password']: print(errorMessage) @@ -52,31 +52,38 @@ def main(args): print(errorMessage) sys.exit(1) - errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node" + nodeDefault = '/trees/geographic' + errorMessage = "No node specified. Provide one via '-n my_node' or {..., 'node':'my_node', ...} or WC_NODE=my_node. " \ + "Using a default now: '" + nodeDefault + "'" try: if args['node'] is None or not args['node']: if not settings['WC_NODE']: print(errorMessage) - sys.exit(1) + node = nodeDefault else: node = settings['WC_NODE'] else: node = str(args['node']) except KeyError: print(errorMessage) - sys.exit(1) + node = nodeDefault - errorMessage = "No URL specified. Provide one via WC_URL=my_url" - url = settings['WC_URL'] + urlDefault = 'https://webctrl.rz-berlin.mpg.de' + errorMessage = "No URL specified. Provide one via '-url my_url' or {..., 'url':'my_url', ...} or WC_URL=my_url. " \ + "Using a default now: '" + urlDefault + "'" try: - if not url: - print(errorMessage) - sys.exit(1) + if args['url'] is None or not args['url']: + if not settings['WC_URL']: + print(errorMessage) + url = urlDefault + else: + url = settings['WC_URL'] else: - wsdlFile = url + '/_common/webservices/Eval?wsdl' + url = str(args['url']) except KeyError: print(errorMessage) - sys.exit(1) + url = urlDefault + wsdlFile = url + '/_common/webservices/Eval?wsdl' #################################################################################################################### ### Connect to the webCTRL server @@ -119,13 +126,14 @@ def main(args): optional = parser.add_argument_group('optional arguments (can also be specified via SETTINGS file)') required.add_argument('--password', '-p', type=str, default=None, help='Password for the login to the WebCTRL server') required.add_argument('--settingsFile', '-f', type=str, default=None, help='File name of settings containing WC_* variables') - optional.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + required.add_argument('--username', '-u', type=str, default=None, help='Username for the login to the WebCTRL server') + optional.add_argument('--url', '-url', type=str, default=None, help="URL of the webctrl server like 'http(s)://webctrl.de'.") optional.add_argument('--node', '-n', type=str, default=None, help='Path to the point or node whose children you want to retrieve. Start querying at the lowest level with "-n /trees/geographic"') args = parser.parse_args() # Get the password if it hasn't been passed as argument - if args.password is None: + if args.password is None or not args.password: args.password = getpass.getpass('No password specified via -p. Please enter your WebCTRL login password: ') # Convert the argparse.Namespace to a dictionary via vars(args)