Skip to content

Commit 0f3eb04

Browse files
authored
Merge pull request #703 from hugovk/rm-2.6
Drop support for EOL Python 2.6
2 parents 8638391 + 87e0168 commit 0f3eb04

File tree

104 files changed

+256
-303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+256
-303
lines changed

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ sudo: false
33

44
language: python
55
python:
6-
- "2.6"
76
- "2.7"
87

98
cache:
@@ -16,7 +15,6 @@ install:
1615
- pip install -r .travis.requirements.txt
1716
- pip install pep8==1.5.7
1817
- pip install coveralls
19-
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2; fi
2018

2119
# command to run tests, e.g. python setup.py test
2220
script:
@@ -44,7 +42,3 @@ notifications:
4442
addons:
4543
apt_packages:
4644
- libsensors4
47-
48-
branches:
49-
only:
50-
- master

Vagrantfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8888
c.vm.provision "shell", inline: "sudo mkdir /var/log/diamond"
8989
c.vm.provision "shell", inline: "sudo ln -s /vagrant/conf/vagrant /etc/diamond"
9090
c.vm.provision "shell", inline: "sudo ln -s /vagrant/bin/diamond /usr/bin/diamond"
91-
c.vm.provision "shell", inline: "sudo ln -s /vagrant/src/diamond /usr/lib/python2.6/site-packages/diamond"
91+
c.vm.provision "shell", inline: "sudo ln -s /vagrant/src/diamond /usr/lib/python2.7/site-packages/diamond"
9292
c.vm.provision "shell", inline: "sudo ln -s /vagrant/bin/init.d/diamond /etc/init.d/diamond"
9393

9494
# Start diamond

bin/diamond

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# coding=utf-8
33

4+
from __future__ import print_function
45
import os
56
import sys
67
import configobj
@@ -110,27 +111,27 @@ def main():
110111
gid = -1
111112

112113
if options.version:
113-
print "Diamond version %s" % (get_diamond_version())
114+
print("Diamond version %s" % (get_diamond_version()))
114115
sys.exit(0)
115116

116117
# Initialize Config
117118
options.configfile = os.path.abspath(options.configfile)
118119
if os.path.exists(options.configfile):
119120
config = configobj.ConfigObj(options.configfile)
120121
else:
121-
print >> sys.stderr, "ERROR: Config file: %s does not exist." % (
122-
options.configfile)
122+
print("ERROR: Config file: %s does not exist." % (
123+
options.configfile), file=sys.stderr)
123124
parser.print_help(sys.stderr)
124125
sys.exit(1)
125126

126127
# Initialize Logging
127128
log = setup_logging(options.configfile, options.log_stdout)
128129

129130
# Pass the exit up stream rather then handle it as an general exception
130-
except SystemExit, e:
131+
except SystemExit as e:
131132
raise SystemExit
132133

133-
except Exception, e:
134+
except Exception as e:
134135
import traceback
135136
sys.stderr.write("Unhandled exception: %s" % str(e))
136137
sys.stderr.write("traceback: %s" % traceback.format_exc())
@@ -159,11 +160,11 @@ def main():
159160
# Pid is not real
160161
os.unlink(options.pidfile)
161162
pid = None
162-
print >> sys.stderr, (
163-
"WARN: Bogus pid file was found. I deleted it.")
163+
print("WARN: Bogus pid file was found. I deleted it.",
164+
file=sys.stderr)
164165
else:
165-
print >> sys.stderr, (
166-
"ERROR: Pidfile exists. Server already running?")
166+
print("ERROR: Pidfile exists. Server already running?",
167+
file=sys.stderr)
167168
sys.exit(1)
168169

169170
# Get final GIDs
@@ -186,8 +187,8 @@ def main():
186187
pid = str(os.getpid())
187188
try:
188189
pf = file(options.pidfile, 'w+')
189-
except IOError, e:
190-
print >> sys.stderr, "Failed to write PID file: %s" % (e)
190+
except IOError as e:
191+
print("Failed to write PID file: %s" % (e), file=sys.stderr)
191192
sys.exit(1)
192193
pf.write("%s\n" % pid)
193194
pf.close()
@@ -201,14 +202,7 @@ def main():
201202
try:
202203
if gid != -1 and uid != -1:
203204
# Manually set the groups since they aren't set by default
204-
205-
# Python 2.7+
206-
if hasattr(os, 'initgroups'):
207-
os.initgroups(user, gid)
208-
# Python 2.6
209-
else:
210-
os.setgroups([e.gr_gid for e in grp.getgrall()
211-
if user in e.gr_mem] + [gid])
205+
os.initgroups(user, gid)
212206

213207
if gid != -1 and os.getgid() != gid:
214208
# Set GID
@@ -218,8 +212,9 @@ def main():
218212
# Set UID
219213
os.setuid(uid)
220214

221-
except Exception, e:
222-
print >> sys.stderr, "ERROR: Failed to set UID/GID. %s" % (e)
215+
except Exception as e:
216+
print("ERROR: Failed to set UID/GID. %s" % (e),
217+
file=sys.stderr)
223218
sys.exit(1)
224219

225220
# Log
@@ -243,8 +238,8 @@ def main():
243238
if pid > 0:
244239
# Exit first paren
245240
sys.exit(0)
246-
except OSError, e:
247-
print >> sys.stderr, "Failed to fork process." % (e)
241+
except OSError as e:
242+
print("Failed to fork process." % (e), file=sys.stderr)
248243
sys.exit(1)
249244
# Decouple from parent environmen
250245
os.setsid()
@@ -255,8 +250,8 @@ def main():
255250
if pid > 0:
256251
# Exit second paren
257252
sys.exit(0)
258-
except OSError, e:
259-
print >> sys.stderr, "Failed to fork process." % (e)
253+
except OSError as e:
254+
print("Failed to fork process." % (e), file=sys.stderr)
260255
sys.exit(1)
261256
# Close file descriptors so that we can detach
262257
sys.stdout.close()
@@ -276,7 +271,7 @@ def main():
276271
pid = str(os.getpid())
277272
try:
278273
pf = file(options.pidfile, 'w+')
279-
except IOError, e:
274+
except IOError as e:
280275
log.error("Failed to write child PID file: %s" % (e))
281276
sys.exit(1)
282277
pf.write("%s\n" % pid)
@@ -311,7 +306,7 @@ def main():
311306
# join() on each of them. This guarantees that the
312307
# SyncManager is terminated last (implicitly as a result of
313308
# us exiting).
314-
child_debug = "Terminating and joining on: {0} ({1})"
309+
child_debug = "Terminating and joining on: {} ({})"
315310
log.debug(child_debug.format(child.name, child.pid))
316311
child.terminate()
317312
child.join()
@@ -324,10 +319,10 @@ def main():
324319
server.run()
325320

326321
# Pass the exit up stream rather then handle it as an general exception
327-
except SystemExit, e:
322+
except SystemExit as e:
328323
raise SystemExit
329324

330-
except Exception, e:
325+
except Exception as e:
331326
import traceback
332327
log.error("Unhandled exception: %s" % str(e))
333328
log.error("traceback: %s" % traceback.format_exc())

bin/diamond-setup

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
##########################################################################
33

4+
from __future__ import print_function
45
import os
56
import sys
67
import optparse
@@ -63,10 +64,10 @@ def getCollectors(path):
6364
break
6465
except TypeError:
6566
continue
66-
# print "Imported module: %s %s" % (modname, cls.__name__)
67+
# print("Imported module: %s %s" % (modname, cls.__name__))
6768
except Exception:
68-
print "Failed to import module: %s. %s" % (
69-
modname, traceback.format_exc())
69+
print("Failed to import module: %s. %s" % (
70+
modname, traceback.format_exc()))
7071
collectors[modname] = False
7172
continue
7273

@@ -133,9 +134,9 @@ def configureKey(key):
133134
except NotImplementedError:
134135
return
135136

136-
print "\n"
137+
print("\n")
137138
if key in default_conf_help:
138-
print default_conf_help[key]
139+
print(default_conf_help[key])
139140
val = raw_input(key + ' [' + user_val + ']: ')
140141

141142
# Empty user input? Default to current value
@@ -177,18 +178,18 @@ if __name__ == "__main__":
177178
if os.path.exists(options.configfile):
178179
config = ConfigObj(os.path.abspath(options.configfile))
179180
else:
180-
print >> sys.stderr, "ERROR: Config file: %s does not exist." % (
181-
options.configfile)
182-
print >> sys.stderr, ("Please run python config.py -c"
183-
+ " /path/to/diamond.conf")
181+
print("ERROR: Config file: %s does not exist." % (
182+
options.configfile), file=sys.stderr)
183+
print("Please run python config.py -c /path/to/diamond.conf",
184+
file=sys.stderr)
184185
parser.print_help(sys.stderr)
185186
sys.exit(1)
186187

187188
if not options.dump:
188-
print ''
189-
print 'I will be over writing files in'
190-
print config['server']['collectors_config_path']
191-
print 'Please type yes to continue'
189+
print('')
190+
print('I will be over writing files in')
191+
print(config['server']['collectors_config_path'])
192+
print('Please type yes to continue')
192193

193194
val = raw_input('Are you sure? ')
194195
if val != 'yes':
@@ -225,7 +226,7 @@ if __name__ == "__main__":
225226
obj = cls(config=config, handlers={})
226227

227228
if options.dump:
228-
print collector + " " + str(obj.config)
229+
print(collector + " " + str(obj.config))
229230
continue
230231

231232
default_conf = obj.get_default_config()
@@ -241,11 +242,11 @@ if __name__ == "__main__":
241242
config_keys['instance_prefix'] = False
242243
config_keys['interval'] = False
243244

244-
print "*" * 60
245-
print "\n\t\tNow configuring " + collector
246-
print collectors[collector].__doc__
245+
print("*" * 60)
246+
print("\n\t\tNow configuring " + collector)
247+
print(collectors[collector].__doc__)
247248

248-
print "(%s)" % collector
249+
print("(%s)" % collector)
249250
configureKey('enabled')
250251

251252
if boolCheck(config_file['enabled']):
@@ -256,12 +257,12 @@ if __name__ == "__main__":
256257

257258
config_file.write()
258259

259-
except IOError, (errno, strerror):
260-
print "I/O error({0}): {1}".format(errno, strerror)
260+
except IOError as (errno, strerror):
261+
print("I/O error({}): {}".format(errno, strerror))
261262
except KeyboardInterrupt:
262-
print
263+
print()
263264
sys.exit()
264265
except:
265266
continue
266267
if not foundcollector:
267-
print "Collector not found."
268+
print("Collector not found.")

build_doc.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# coding=utf-8
33
##########################################################################
44

5+
from __future__ import print_function
56
import configobj
67
import optparse
78
import os
@@ -56,8 +57,8 @@ def getCollectors(path):
5657
if cls.__name__ not in collectors:
5758
collectors[cls.__name__] = module
5859
except Exception:
59-
print "Failed to import module: %s. %s" % (
60-
modname, traceback.format_exc())
60+
print("Failed to import module: %s. %s" % (
61+
modname, traceback.format_exc()))
6162
collectors[modname] = False
6263

6364
elif os.path.isdir(cPath):
@@ -91,8 +92,8 @@ def getHandlers(path, name=None):
9192
if cls.__name__ not in handlers:
9293
handlers[cls.__name__] = module
9394
except Exception:
94-
print "Failed to import module: %s. %s" % (
95-
modname, traceback.format_exc())
95+
print("Failed to import module: %s. %s" % (
96+
modname, traceback.format_exc()))
9697
handlers[modname] = False
9798

9899
elif os.path.isdir(cPath):
@@ -110,7 +111,7 @@ def writeDocString(docFile, name, doc):
110111
docFile.write("%s\n" % (name))
111112
docFile.write("=====\n")
112113
if doc is None:
113-
print "No __doc__ string for %s!" % name
114+
print("No __doc__ string for %s!" % name)
114115
docFile.write("%s\n" % doc)
115116

116117

@@ -150,7 +151,7 @@ def writeDoc(items, type_name, doc_path):
150151
if item.startswith('Test'):
151152
continue
152153

153-
print "Processing %s..." % (item)
154+
print("Processing %s..." % (item))
154155

155156
if not hasattr(items[item], item):
156157
continue
@@ -172,13 +173,11 @@ def writeDoc(items, type_name, doc_path):
172173
default_options = obj.get_default_config()
173174
if type_name is "Handler":
174175
os.remove(tmpfile[1])
175-
except Exception, e:
176-
print "Caught Exception %s" % e
176+
except Exception as e:
177+
print("Caught Exception {}".format(e))
177178

178179
docFile = open(os.path.join(doc_path, item + ".md"), 'w')
179180

180-
enabled = ''
181-
182181
writeDocHeader(docFile)
183182
writeDocString(docFile, item, items[item].__doc__)
184183
writeDocOptionsHeader(docFile)
@@ -228,10 +227,10 @@ def writeDoc(items, type_name, doc_path):
228227
if os.path.exists(options.configfile):
229228
config = configobj.ConfigObj(os.path.abspath(options.configfile))
230229
else:
231-
print >> sys.stderr, "ERROR: Config file: %s does not exist." % (
232-
options.configfile)
233-
print >> sys.stderr, ("Please run python config.py -c " +
234-
"/path/to/diamond.conf")
230+
print("ERROR: Config file: %s does not exist." % (
231+
options.configfile), file=sys.stderr)
232+
print(("Please run python config.py -c /path/to/diamond.conf"),
233+
file=sys.stderr)
235234
parser.print_help(sys.stderr)
236235
sys.exit(1)
237236

docs/Getting-Started/Installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
### Core
55

66
- CentOS or Ubuntu
7-
- Python 2.6+
7+
- Python 2.7
88
- python-configobj
99
- python-setuptools
1010
- make

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def pkgPath(root, path, rpath="/"):
150150
packages=['diamond', 'diamond.handler', 'diamond.utils'],
151151
scripts=['bin/diamond', 'bin/diamond-setup'],
152152
data_files=data_files,
153+
python_requires='==2.7',
153154
install_requires=install_requires,
154155
classifiers=[
155156
'Programming Language :: Python',

src/collectors/amavis/amavis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def collect(self):
8989
if metric in ('count', 'time'):
9090
mtype = 'COUNTER'
9191
precision = 0
92-
self.publish("{0}.{1}".format(name, metric),
92+
self.publish("{}.{}".format(name, metric),
9393
value, metric_type=mtype,
9494
precision=precision)
9595

src/collectors/beanstalkd/beanstalkd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _get_stats(self):
5151
try:
5252
connection = beanstalkc.Connection(self.config['host'],
5353
int(self.config['port']))
54-
except beanstalkc.BeanstalkcException, e:
54+
except beanstalkc.BeanstalkcException as e:
5555
self.log.error("Couldn't connect to beanstalkd: %s", e)
5656
return {}
5757

0 commit comments

Comments
 (0)