Skip to content

Commit 561dea6

Browse files
.
1 parent d90f07a commit 561dea6

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

.bumpversion.cfg

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[bumpversion]
22
commit = True
33
tag = True
4-
current_version = 0.1.8
4+
current_version = 0.2.0
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
6-
serialize =
6+
serialize =
77
{major}.{minor}.{patch}-{release}
88
{major}.{minor}.{patch}
99

1010
[bumpversion:file:threebot_worker/__init__.py]
11-

threebot_worker/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
__version__ = '0.1.8'
4+
__version__ = '0.2.0'

threebot_worker/threebot-worker

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import os
55
import sys
66
import subprocess
77
import zmq
8-
import ConfigParser
8+
try:
9+
import configparser
10+
except ImportError:
11+
import configparser as ConfigParser
912
import logging
1013

1114
import threebot_crypto
@@ -27,15 +30,15 @@ LOGFILE = os.path.join(BASEDIR, '3bot.log')
2730
LOGLEVEL = 'ERROR'
2831

2932

30-
Config = ConfigParser.ConfigParser()
33+
Config = configparser.ConfigParser()
3134

3235
if os.path.isfile(CONFIGFILE):
3336
Config.read(CONFIGFILE)
3437
else:
35-
print "No configfile found in: '%s'" % CONFIGFILE
36-
print "----"
37-
print "Creating basic configfile in '%s'" % CONFIGFILE
38-
print "----"
38+
print("No configfile found in: '%s'" % CONFIGFILE)
39+
print("----")
40+
print("Creating basic configfile in '%s'" % CONFIGFILE)
41+
print("----")
3942

4043
os.makedirs(BASEDIR)
4144
cfgfile = open(CONFIGFILE, 'w')
@@ -44,10 +47,10 @@ else:
4447
Config.add_section('3bot-settings')
4548
Config.set('3bot-settings', 'BOT_ENDPOINT', '*')
4649

47-
port = raw_input('Enter PORT: ')
50+
port = input('Enter PORT: ')
4851
Config.set('3bot-settings', 'PORT', port)
4952

50-
sec_key = raw_input('Enter SECRET_KEY: ')
53+
sec_key = input('Enter SECRET_KEY: ')
5154
Config.set('3bot-settings', 'SECRET_KEY', sec_key)
5255

5356
Config.write(cfgfile)
@@ -59,31 +62,31 @@ try:
5962
BOT = Config.get('3bot-settings', 'BOT_ENDPOINT')
6063
PORT = Config.get('3bot-settings', 'PORT')
6164
except:
62-
print "Invalid config file in: '%s'. Could not find BOT or PORT declaration" % CONFIGFILE
63-
print "You can find a basic config file in the documentation."
65+
print("Invalid config file in: '%s'. Could not find BOT or PORT declaration" % CONFIGFILE)
66+
print("You can find a basic config file in the documentation.")
6467
sys.exit(2)
6568

6669
try:
6770
SECRET_KEY = Config.get('3bot-settings', 'SECRET_KEY')
6871
except:
69-
print "Invalid config file in: '%s'. Could not find SECRET_KEY declaration" % CONFIGFILE
70-
print "You can find a basic config file in the documentation."
72+
print("Invalid config file in: '%s'. Could not find SECRET_KEY declaration" % CONFIGFILE)
73+
print("You can find a basic config file in the documentation.")
7174
sys.exit(2)
7275

7376
try:
7477
DRY_RUN = Config.getboolean('3bot-settings', 'DRY_RUN')
75-
except ConfigParser.NoOptionError:
78+
except configparser.NoOptionError:
7679
DRY_RUN = False
7780

7881

7982
try:
8083
LOGFILE = Config.get('3bot-settings', 'LOGFILE')
81-
except ConfigParser.NoOptionError:
84+
except configparser.NoOptionError:
8285
pass
8386

8487
try:
8588
LOGLEVEL = Config.get('3bot-settings', 'LOGLEVEL')
86-
except ConfigParser.NoOptionError:
89+
except configparser.NoOptionError:
8790
pass
8891

8992
if LOGLEVEL == 'DEBUG':
@@ -112,10 +115,8 @@ def write_script(directory, script, body):
112115
with open(task_path, 'w+') as task_file:
113116
task_file.write(body.encode('utf8').replace('\r\n', '\n'))
114117
logging.info("Saving new Script file at: %s" % task_path)
115-
116118
# change permission
117-
os.chmod(task_path, 0755)
118-
119+
os.chmod(task_path, 0o755)
119120
return task_path
120121

121122

@@ -162,7 +163,7 @@ def run_command(request):
162163
callable = " && ".join(script_bits)
163164
else:
164165
callable = script_bits[0]
165-
166+
166167
if DRY_RUN:
167168
# dumping path to task script to stdout instead of executing it, allows to 'cat' later on the target node
168169
response = {'stdout': callable, 'stderr': '', 'exit_code': 0}
@@ -176,31 +177,31 @@ def run_command(request):
176177

177178
try:
178179
t_stdout = p.stdout.read()
179-
except AttributeError, e:
180+
except AttributeError as e:
180181
logging.info(e)
181182

182183
try:
183184
t_stderr = p.stderr.read()
184-
except AttributeError, e:
185+
except AttributeError as e:
185186
logging.info(e)
186187

187188
response = {'stdout': t_stdout, 'stderr': t_stderr, 'exit_code': p.wait()}
188189
del p
189-
190+
190191
return response
191192

192193
if sys.argv[1] in ['restart', 'start', 'status', ]:
193-
print '---'
194-
print 'BASEDIR: %s' % str(BASEDIR)
195-
print 'CONFIGFILE: %s' % str(CONFIGFILE)
196-
print 'SCRIPTDIR: %s' % str(SCRIPTDIR)
197-
print 'ENDPOINT: %s' % str(BOT)
198-
print 'PORT: %s' % str(PORT)
199-
print 'LOGFILE: %s' % str(LOGFILE)
200-
print 'LOGLEVEL: %s' % str(LOGLEVEL)
201-
print 'PIDFILE: %s' % str(PIDFILE)
202-
print 'DRY_RUN: %s' % str(DRY_RUN)
203-
print '---'
194+
print('---')
195+
print('BASEDIR: %s' % str(BASEDIR))
196+
print('CONFIGFILE: %s' % str(CONFIGFILE))
197+
print('SCRIPTDIR: %s' % str(SCRIPTDIR))
198+
print('ENDPOINT: %s' % str(BOT))
199+
print('PORT: %s' % str(PORT))
200+
print('LOGFILE: %s' % str(LOGFILE))
201+
print('LOGLEVEL: %s' % str(LOGLEVEL))
202+
print('PIDFILE: %s' % str(PIDFILE))
203+
print('DRY_RUN: %s' % str(DRY_RUN))
204+
print('---')
204205

205206

206207
class WorkerDeamon(Daemon):
@@ -252,9 +253,9 @@ if __name__ == "__main__":
252253
elif 'status' == sys.argv[1]:
253254
daemon.status()
254255
else:
255-
print "Unknown command"
256+
print("Unknown command")
256257
sys.exit(2)
257258
sys.exit(0)
258259
else:
259-
print "usage: %s start|stop|restart|status" % sys.argv[0]
260+
print("usage: %s start|stop|restart|status" % sys.argv[0])
260261
sys.exit(2)

0 commit comments

Comments
 (0)