From a1a738a698795046bffadec79bb4bf28e53b26a2 Mon Sep 17 00:00:00 2001 From: "Philippe O. Wagner" Date: Wed, 24 Jun 2020 10:44:52 +0200 Subject: [PATCH 1/9] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index ff24a5f..29fb380 100644 --- a/setup.py +++ b/setup.py @@ -15,11 +15,11 @@ def long_description(): setup( name="threebot-worker", version=app.__version__, - description="Worker scripts for the 3bot plattform", + description="Worker scripts for the 3bot plattform.", long_description=long_description(), author='arteria GmbH', author_email="admin@arteria.ch", - maintainer_email="renner@arteria.ch", + maintainer_email="admin@arteria.ch", url="https://github.com/3bot/3bot-worker", packages=find_packages(), include_package_data=True, From 34b19dcdf2d86ecdbca5fb5b5282f64b2f7e5153 Mon Sep 17 00:00:00 2001 From: arteria GmbH Date: Wed, 24 Jun 2020 11:39:04 +0200 Subject: [PATCH 2/9] =?UTF-8?q?Bump=20version:=200.1.7=20=E2=86=92=200.1.8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- threebot_worker/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threebot_worker/__init__.py b/threebot_worker/__init__.py index 4a7d320..ff43c60 100644 --- a/threebot_worker/__init__.py +++ b/threebot_worker/__init__.py @@ -1,4 +1,4 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -__version__ = '0.1.6' +__version__ = '0.1.8' From d90f07aad1ef288c51b2bae065bce7f1236853f1 Mon Sep 17 00:00:00 2001 From: arteria GmbH Date: Wed, 24 Jun 2020 11:40:01 +0200 Subject: [PATCH 3/9] . --- .bumpversion.cfg | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 0000000..25a62d0 --- /dev/null +++ b/.bumpversion.cfg @@ -0,0 +1,11 @@ +[bumpversion] +commit = True +tag = True +current_version = 0.1.8 +parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+))? +serialize = + {major}.{minor}.{patch}-{release} + {major}.{minor}.{patch} + +[bumpversion:file:threebot_worker/__init__.py] + From 561dea6ed4da6f75823025a1fd26360ca2bcb864 Mon Sep 17 00:00:00 2001 From: "Philippe O. Wagner" Date: Wed, 16 Sep 2020 10:36:09 +0200 Subject: [PATCH 4/9] . --- .bumpversion.cfg | 5 +-- threebot_worker/__init__.py | 2 +- threebot_worker/threebot-worker | 71 +++++++++++++++++---------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 25a62d0..62b2d16 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,11 +1,10 @@ [bumpversion] commit = True tag = True -current_version = 0.1.8 +current_version = 0.2.0 parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+))? -serialize = +serialize = {major}.{minor}.{patch}-{release} {major}.{minor}.{patch} [bumpversion:file:threebot_worker/__init__.py] - diff --git a/threebot_worker/__init__.py b/threebot_worker/__init__.py index ff43c60..a55e329 100644 --- a/threebot_worker/__init__.py +++ b/threebot_worker/__init__.py @@ -1,4 +1,4 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -__version__ = '0.1.8' +__version__ = '0.2.0' diff --git a/threebot_worker/threebot-worker b/threebot_worker/threebot-worker index 8edd415..9b5b86a 100755 --- a/threebot_worker/threebot-worker +++ b/threebot_worker/threebot-worker @@ -5,7 +5,10 @@ import os import sys import subprocess import zmq -import ConfigParser +try: + import configparser +except ImportError: + import configparser as ConfigParser import logging import threebot_crypto @@ -27,15 +30,15 @@ LOGFILE = os.path.join(BASEDIR, '3bot.log') LOGLEVEL = 'ERROR' -Config = ConfigParser.ConfigParser() +Config = configparser.ConfigParser() if os.path.isfile(CONFIGFILE): Config.read(CONFIGFILE) else: - print "No configfile found in: '%s'" % CONFIGFILE - print "----" - print "Creating basic configfile in '%s'" % CONFIGFILE - print "----" + print("No configfile found in: '%s'" % CONFIGFILE) + print("----") + print("Creating basic configfile in '%s'" % CONFIGFILE) + print("----") os.makedirs(BASEDIR) cfgfile = open(CONFIGFILE, 'w') @@ -44,10 +47,10 @@ else: Config.add_section('3bot-settings') Config.set('3bot-settings', 'BOT_ENDPOINT', '*') - port = raw_input('Enter PORT: ') + port = input('Enter PORT: ') Config.set('3bot-settings', 'PORT', port) - sec_key = raw_input('Enter SECRET_KEY: ') + sec_key = input('Enter SECRET_KEY: ') Config.set('3bot-settings', 'SECRET_KEY', sec_key) Config.write(cfgfile) @@ -59,31 +62,31 @@ try: BOT = Config.get('3bot-settings', 'BOT_ENDPOINT') PORT = Config.get('3bot-settings', 'PORT') except: - print "Invalid config file in: '%s'. Could not find BOT or PORT declaration" % CONFIGFILE - print "You can find a basic config file in the documentation." + print("Invalid config file in: '%s'. Could not find BOT or PORT declaration" % CONFIGFILE) + print("You can find a basic config file in the documentation.") sys.exit(2) try: SECRET_KEY = Config.get('3bot-settings', 'SECRET_KEY') except: - print "Invalid config file in: '%s'. Could not find SECRET_KEY declaration" % CONFIGFILE - print "You can find a basic config file in the documentation." + print("Invalid config file in: '%s'. Could not find SECRET_KEY declaration" % CONFIGFILE) + print("You can find a basic config file in the documentation.") sys.exit(2) try: DRY_RUN = Config.getboolean('3bot-settings', 'DRY_RUN') -except ConfigParser.NoOptionError: +except configparser.NoOptionError: DRY_RUN = False try: LOGFILE = Config.get('3bot-settings', 'LOGFILE') -except ConfigParser.NoOptionError: +except configparser.NoOptionError: pass try: LOGLEVEL = Config.get('3bot-settings', 'LOGLEVEL') -except ConfigParser.NoOptionError: +except configparser.NoOptionError: pass if LOGLEVEL == 'DEBUG': @@ -112,10 +115,8 @@ def write_script(directory, script, body): with open(task_path, 'w+') as task_file: task_file.write(body.encode('utf8').replace('\r\n', '\n')) logging.info("Saving new Script file at: %s" % task_path) - # change permission - os.chmod(task_path, 0755) - + os.chmod(task_path, 0o755) return task_path @@ -162,7 +163,7 @@ def run_command(request): callable = " && ".join(script_bits) else: callable = script_bits[0] - + if DRY_RUN: # dumping path to task script to stdout instead of executing it, allows to 'cat' later on the target node response = {'stdout': callable, 'stderr': '', 'exit_code': 0} @@ -176,31 +177,31 @@ def run_command(request): try: t_stdout = p.stdout.read() - except AttributeError, e: + except AttributeError as e: logging.info(e) try: t_stderr = p.stderr.read() - except AttributeError, e: + except AttributeError as e: logging.info(e) response = {'stdout': t_stdout, 'stderr': t_stderr, 'exit_code': p.wait()} del p - + return response if sys.argv[1] in ['restart', 'start', 'status', ]: - print '---' - print 'BASEDIR: %s' % str(BASEDIR) - print 'CONFIGFILE: %s' % str(CONFIGFILE) - print 'SCRIPTDIR: %s' % str(SCRIPTDIR) - print 'ENDPOINT: %s' % str(BOT) - print 'PORT: %s' % str(PORT) - print 'LOGFILE: %s' % str(LOGFILE) - print 'LOGLEVEL: %s' % str(LOGLEVEL) - print 'PIDFILE: %s' % str(PIDFILE) - print 'DRY_RUN: %s' % str(DRY_RUN) - print '---' + print('---') + print('BASEDIR: %s' % str(BASEDIR)) + print('CONFIGFILE: %s' % str(CONFIGFILE)) + print('SCRIPTDIR: %s' % str(SCRIPTDIR)) + print('ENDPOINT: %s' % str(BOT)) + print('PORT: %s' % str(PORT)) + print('LOGFILE: %s' % str(LOGFILE)) + print('LOGLEVEL: %s' % str(LOGLEVEL)) + print('PIDFILE: %s' % str(PIDFILE)) + print('DRY_RUN: %s' % str(DRY_RUN)) + print('---') class WorkerDeamon(Daemon): @@ -252,9 +253,9 @@ if __name__ == "__main__": elif 'status' == sys.argv[1]: daemon.status() else: - print "Unknown command" + print("Unknown command") sys.exit(2) sys.exit(0) else: - print "usage: %s start|stop|restart|status" % sys.argv[0] + print("usage: %s start|stop|restart|status" % sys.argv[0]) sys.exit(2) From 6b86e339ebb1bfe03b72449ef1dcdb23bfea104b Mon Sep 17 00:00:00 2001 From: "Philippe O. Wagner" Date: Wed, 16 Sep 2020 10:41:10 +0200 Subject: [PATCH 5/9] . --- threebot_worker/daemon.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/threebot_worker/daemon.py b/threebot_worker/daemon.py index 342cad1..aac4d42 100644 --- a/threebot_worker/daemon.py +++ b/threebot_worker/daemon.py @@ -58,9 +58,12 @@ def daemonize(self): # redirect standard file descriptors sys.stdout.flush() sys.stderr.flush() - si = file(self.stdin, 'r') - so = file(self.stdout, 'a+') - se = file(self.stderr, 'a+', 0) + #si = file(self.stdin, 'r') + #so = file(self.stdout, 'a+') + #se = file(self.stderr, 'a+', 0) + si = open(self.stdin, 'r') + so = open(self.stdout, 'a+') + se = open(self.stderr, 'a+') os.dup2(si.fileno(), sys.stdin.fileno()) os.dup2(so.fileno(), sys.stdout.fileno()) os.dup2(se.fileno(), sys.stderr.fileno()) @@ -68,7 +71,8 @@ def daemonize(self): # write pidfile atexit.register(self.delpid) pid = str(os.getpid()) - file(self.pidfile, 'w+').write("%s\n" % pid) + #file(self.pidfile, 'w+').write("%s\n" % pid) + open(self.pidfile, 'w+').write("%s\n" % pid) def delpid(self): os.remove(self.pidfile) @@ -101,7 +105,8 @@ def stop(self): """ # Get the pid from the pidfile try: - pf = file(self.pidfile, 'r') + #pf = file(self.pidfile, 'r') + pf = open(self.pidfile, 'r') pid = int(pf.read().strip()) pf.close() except IOError: @@ -135,7 +140,8 @@ def restart(self): def status(self): try: - pf = file(self.pidfile, 'r') + #pf = file(self.pidfile, 'r') + pf = open(self.pidfile, 'r') pid = int(pf.read().strip()) pf.close() except IOError: From 9fe01d364e6886d75bb49c0eb1bc56284fde6674 Mon Sep 17 00:00:00 2001 From: "Philippe O. Wagner" Date: Wed, 16 Sep 2020 10:42:30 +0200 Subject: [PATCH 6/9] . --- threebot_worker/daemon.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/threebot_worker/daemon.py b/threebot_worker/daemon.py index aac4d42..a3895e0 100644 --- a/threebot_worker/daemon.py +++ b/threebot_worker/daemon.py @@ -83,7 +83,8 @@ def start(self): """ # Check for a pidfile to see if the daemon already runs try: - pf = file(self.pidfile, 'r') + #pf = file(self.pidfile, 'r') + pf = open(self.pidfile, 'r') pid = int(pf.read().strip()) pf.close() except IOError: From 67c350e2f3b371be46a8ee82ee9dc53402e24673 Mon Sep 17 00:00:00 2001 From: "Philippe O. Wagner" Date: Wed, 16 Sep 2020 10:57:33 +0200 Subject: [PATCH 7/9] . --- threebot_worker/threebot-worker | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/threebot_worker/threebot-worker b/threebot_worker/threebot-worker index 9b5b86a..7f05704 100755 --- a/threebot_worker/threebot-worker +++ b/threebot_worker/threebot-worker @@ -5,10 +5,7 @@ import os import sys import subprocess import zmq -try: - import configparser -except ImportError: - import configparser as ConfigParser +import configparser import logging import threebot_crypto @@ -210,13 +207,13 @@ class WorkerDeamon(Daemon): def run(self): logging.info("Starting the 3bot worker listening on %s:%s" % (BOT, PORT)) - context = zmq.Context(1) server = context.socket(zmq.REP) server.bind("%s://%s:%s" % (PROTOCOL, BOT, PORT)) while True: request = server.recv(FLAGS) + print (request) request = threebot_crypto.decrypt(request, SECRET_KEY) logging.info("Received request") if request: From 5c14b6906da07f4e37d7daefd5464590a3ccbb8c Mon Sep 17 00:00:00 2001 From: "Philippe O. Wagner" Date: Wed, 16 Sep 2020 11:09:13 +0200 Subject: [PATCH 8/9] . --- threebot_worker/threebot-worker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threebot_worker/threebot-worker b/threebot_worker/threebot-worker index 7f05704..c38d719 100755 --- a/threebot_worker/threebot-worker +++ b/threebot_worker/threebot-worker @@ -64,7 +64,7 @@ except: sys.exit(2) try: - SECRET_KEY = Config.get('3bot-settings', 'SECRET_KEY') + SECRET_KEY = Config.get('3bot-settings', 'SECRET_KEY').encode('utf-8') except: print("Invalid config file in: '%s'. Could not find SECRET_KEY declaration" % CONFIGFILE) print("You can find a basic config file in the documentation.") From 5ceb732bdeaece665acd64a5d14dec9d7236f1a2 Mon Sep 17 00:00:00 2001 From: "Philippe O. Wagner" Date: Wed, 16 Sep 2020 11:24:32 +0200 Subject: [PATCH 9/9] . --- threebot_worker/threebot-worker | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/threebot_worker/threebot-worker b/threebot_worker/threebot-worker index c38d719..66d441b 100755 --- a/threebot_worker/threebot-worker +++ b/threebot_worker/threebot-worker @@ -64,7 +64,7 @@ except: sys.exit(2) try: - SECRET_KEY = Config.get('3bot-settings', 'SECRET_KEY').encode('utf-8') + SECRET_KEY = Config.get('3bot-settings', 'SECRET_KEY') except: print("Invalid config file in: '%s'. Could not find SECRET_KEY declaration" % CONFIGFILE) print("You can find a basic config file in the documentation.") @@ -170,8 +170,7 @@ def run_command(request): p = subprocess.Popen(callable, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) logging.info("Executing Script file at: %s" % task_path) t_stdout = "" - t_stderr = "" - + t_stderr = "" try: t_stdout = p.stdout.read() except AttributeError as e: