Skip to content

Commit

Permalink
Merge pull request python-diamond#703 from hugovk/rm-2.6
Browse files Browse the repository at this point in the history
Drop support for EOL Python 2.6
  • Loading branch information
josegonzalez authored Mar 15, 2018
2 parents 8638391 + 87e0168 commit 0f3eb04
Show file tree
Hide file tree
Showing 104 changed files with 256 additions and 303 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ sudo: false

language: python
python:
- "2.6"
- "2.7"

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

# command to run tests, e.g. python setup.py test
script:
Expand Down Expand Up @@ -44,7 +42,3 @@ notifications:
addons:
apt_packages:
- libsensors4

branches:
only:
- master
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
c.vm.provision "shell", inline: "sudo mkdir /var/log/diamond"
c.vm.provision "shell", inline: "sudo ln -s /vagrant/conf/vagrant /etc/diamond"
c.vm.provision "shell", inline: "sudo ln -s /vagrant/bin/diamond /usr/bin/diamond"
c.vm.provision "shell", inline: "sudo ln -s /vagrant/src/diamond /usr/lib/python2.6/site-packages/diamond"
c.vm.provision "shell", inline: "sudo ln -s /vagrant/src/diamond /usr/lib/python2.7/site-packages/diamond"
c.vm.provision "shell", inline: "sudo ln -s /vagrant/bin/init.d/diamond /etc/init.d/diamond"

# Start diamond
Expand Down
53 changes: 24 additions & 29 deletions bin/diamond
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# coding=utf-8

from __future__ import print_function
import os
import sys
import configobj
Expand Down Expand Up @@ -110,27 +111,27 @@ def main():
gid = -1

if options.version:
print "Diamond version %s" % (get_diamond_version())
print("Diamond version %s" % (get_diamond_version()))
sys.exit(0)

# Initialize Config
options.configfile = os.path.abspath(options.configfile)
if os.path.exists(options.configfile):
config = configobj.ConfigObj(options.configfile)
else:
print >> sys.stderr, "ERROR: Config file: %s does not exist." % (
options.configfile)
print("ERROR: Config file: %s does not exist." % (
options.configfile), file=sys.stderr)
parser.print_help(sys.stderr)
sys.exit(1)

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

# Pass the exit up stream rather then handle it as an general exception
except SystemExit, e:
except SystemExit as e:
raise SystemExit

except Exception, e:
except Exception as e:
import traceback
sys.stderr.write("Unhandled exception: %s" % str(e))
sys.stderr.write("traceback: %s" % traceback.format_exc())
Expand Down Expand Up @@ -159,11 +160,11 @@ def main():
# Pid is not real
os.unlink(options.pidfile)
pid = None
print >> sys.stderr, (
"WARN: Bogus pid file was found. I deleted it.")
print("WARN: Bogus pid file was found. I deleted it.",
file=sys.stderr)
else:
print >> sys.stderr, (
"ERROR: Pidfile exists. Server already running?")
print("ERROR: Pidfile exists. Server already running?",
file=sys.stderr)
sys.exit(1)

# Get final GIDs
Expand All @@ -186,8 +187,8 @@ def main():
pid = str(os.getpid())
try:
pf = file(options.pidfile, 'w+')
except IOError, e:
print >> sys.stderr, "Failed to write PID file: %s" % (e)
except IOError as e:
print("Failed to write PID file: %s" % (e), file=sys.stderr)
sys.exit(1)
pf.write("%s\n" % pid)
pf.close()
Expand All @@ -201,14 +202,7 @@ def main():
try:
if gid != -1 and uid != -1:
# Manually set the groups since they aren't set by default

# Python 2.7+
if hasattr(os, 'initgroups'):
os.initgroups(user, gid)
# Python 2.6
else:
os.setgroups([e.gr_gid for e in grp.getgrall()
if user in e.gr_mem] + [gid])
os.initgroups(user, gid)

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

except Exception, e:
print >> sys.stderr, "ERROR: Failed to set UID/GID. %s" % (e)
except Exception as e:
print("ERROR: Failed to set UID/GID. %s" % (e),
file=sys.stderr)
sys.exit(1)

# Log
Expand All @@ -243,8 +238,8 @@ def main():
if pid > 0:
# Exit first paren
sys.exit(0)
except OSError, e:
print >> sys.stderr, "Failed to fork process." % (e)
except OSError as e:
print("Failed to fork process." % (e), file=sys.stderr)
sys.exit(1)
# Decouple from parent environmen
os.setsid()
Expand All @@ -255,8 +250,8 @@ def main():
if pid > 0:
# Exit second paren
sys.exit(0)
except OSError, e:
print >> sys.stderr, "Failed to fork process." % (e)
except OSError as e:
print("Failed to fork process." % (e), file=sys.stderr)
sys.exit(1)
# Close file descriptors so that we can detach
sys.stdout.close()
Expand All @@ -276,7 +271,7 @@ def main():
pid = str(os.getpid())
try:
pf = file(options.pidfile, 'w+')
except IOError, e:
except IOError as e:
log.error("Failed to write child PID file: %s" % (e))
sys.exit(1)
pf.write("%s\n" % pid)
Expand Down Expand Up @@ -311,7 +306,7 @@ def main():
# join() on each of them. This guarantees that the
# SyncManager is terminated last (implicitly as a result of
# us exiting).
child_debug = "Terminating and joining on: {0} ({1})"
child_debug = "Terminating and joining on: {} ({})"
log.debug(child_debug.format(child.name, child.pid))
child.terminate()
child.join()
Expand All @@ -324,10 +319,10 @@ def main():
server.run()

# Pass the exit up stream rather then handle it as an general exception
except SystemExit, e:
except SystemExit as e:
raise SystemExit

except Exception, e:
except Exception as e:
import traceback
log.error("Unhandled exception: %s" % str(e))
log.error("traceback: %s" % traceback.format_exc())
Expand Down
45 changes: 23 additions & 22 deletions bin/diamond-setup
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
##########################################################################

from __future__ import print_function
import os
import sys
import optparse
Expand Down Expand Up @@ -63,10 +64,10 @@ def getCollectors(path):
break
except TypeError:
continue
# print "Imported module: %s %s" % (modname, cls.__name__)
# print("Imported module: %s %s" % (modname, cls.__name__))
except Exception:
print "Failed to import module: %s. %s" % (
modname, traceback.format_exc())
print("Failed to import module: %s. %s" % (
modname, traceback.format_exc()))
collectors[modname] = False
continue

Expand Down Expand Up @@ -133,9 +134,9 @@ def configureKey(key):
except NotImplementedError:
return

print "\n"
print("\n")
if key in default_conf_help:
print default_conf_help[key]
print(default_conf_help[key])
val = raw_input(key + ' [' + user_val + ']: ')

# Empty user input? Default to current value
Expand Down Expand Up @@ -177,18 +178,18 @@ if __name__ == "__main__":
if os.path.exists(options.configfile):
config = ConfigObj(os.path.abspath(options.configfile))
else:
print >> sys.stderr, "ERROR: Config file: %s does not exist." % (
options.configfile)
print >> sys.stderr, ("Please run python config.py -c"
+ " /path/to/diamond.conf")
print("ERROR: Config file: %s does not exist." % (
options.configfile), file=sys.stderr)
print("Please run python config.py -c /path/to/diamond.conf",
file=sys.stderr)
parser.print_help(sys.stderr)
sys.exit(1)

if not options.dump:
print ''
print 'I will be over writing files in'
print config['server']['collectors_config_path']
print 'Please type yes to continue'
print('')
print('I will be over writing files in')
print(config['server']['collectors_config_path'])
print('Please type yes to continue')

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

if options.dump:
print collector + " " + str(obj.config)
print(collector + " " + str(obj.config))
continue

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

print "*" * 60
print "\n\t\tNow configuring " + collector
print collectors[collector].__doc__
print("*" * 60)
print("\n\t\tNow configuring " + collector)
print(collectors[collector].__doc__)

print "(%s)" % collector
print("(%s)" % collector)
configureKey('enabled')

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

config_file.write()

except IOError, (errno, strerror):
print "I/O error({0}): {1}".format(errno, strerror)
except IOError as (errno, strerror):
print("I/O error({}): {}".format(errno, strerror))
except KeyboardInterrupt:
print
print()
sys.exit()
except:
continue
if not foundcollector:
print "Collector not found."
print("Collector not found.")
27 changes: 13 additions & 14 deletions build_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# coding=utf-8
##########################################################################

from __future__ import print_function
import configobj
import optparse
import os
Expand Down Expand Up @@ -56,8 +57,8 @@ def getCollectors(path):
if cls.__name__ not in collectors:
collectors[cls.__name__] = module
except Exception:
print "Failed to import module: %s. %s" % (
modname, traceback.format_exc())
print("Failed to import module: %s. %s" % (
modname, traceback.format_exc()))
collectors[modname] = False

elif os.path.isdir(cPath):
Expand Down Expand Up @@ -91,8 +92,8 @@ def getHandlers(path, name=None):
if cls.__name__ not in handlers:
handlers[cls.__name__] = module
except Exception:
print "Failed to import module: %s. %s" % (
modname, traceback.format_exc())
print("Failed to import module: %s. %s" % (
modname, traceback.format_exc()))
handlers[modname] = False

elif os.path.isdir(cPath):
Expand All @@ -110,7 +111,7 @@ def writeDocString(docFile, name, doc):
docFile.write("%s\n" % (name))
docFile.write("=====\n")
if doc is None:
print "No __doc__ string for %s!" % name
print("No __doc__ string for %s!" % name)
docFile.write("%s\n" % doc)


Expand Down Expand Up @@ -150,7 +151,7 @@ def writeDoc(items, type_name, doc_path):
if item.startswith('Test'):
continue

print "Processing %s..." % (item)
print("Processing %s..." % (item))

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

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

enabled = ''

writeDocHeader(docFile)
writeDocString(docFile, item, items[item].__doc__)
writeDocOptionsHeader(docFile)
Expand Down Expand Up @@ -228,10 +227,10 @@ def writeDoc(items, type_name, doc_path):
if os.path.exists(options.configfile):
config = configobj.ConfigObj(os.path.abspath(options.configfile))
else:
print >> sys.stderr, "ERROR: Config file: %s does not exist." % (
options.configfile)
print >> sys.stderr, ("Please run python config.py -c " +
"/path/to/diamond.conf")
print("ERROR: Config file: %s does not exist." % (
options.configfile), file=sys.stderr)
print(("Please run python config.py -c /path/to/diamond.conf"),
file=sys.stderr)
parser.print_help(sys.stderr)
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion docs/Getting-Started/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
### Core

- CentOS or Ubuntu
- Python 2.6+
- Python 2.7
- python-configobj
- python-setuptools
- make
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def pkgPath(root, path, rpath="/"):
packages=['diamond', 'diamond.handler', 'diamond.utils'],
scripts=['bin/diamond', 'bin/diamond-setup'],
data_files=data_files,
python_requires='==2.7',
install_requires=install_requires,
classifiers=[
'Programming Language :: Python',
Expand Down
2 changes: 1 addition & 1 deletion src/collectors/amavis/amavis.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def collect(self):
if metric in ('count', 'time'):
mtype = 'COUNTER'
precision = 0
self.publish("{0}.{1}".format(name, metric),
self.publish("{}.{}".format(name, metric),
value, metric_type=mtype,
precision=precision)

Expand Down
2 changes: 1 addition & 1 deletion src/collectors/beanstalkd/beanstalkd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _get_stats(self):
try:
connection = beanstalkc.Connection(self.config['host'],
int(self.config['port']))
except beanstalkc.BeanstalkcException, e:
except beanstalkc.BeanstalkcException as e:
self.log.error("Couldn't connect to beanstalkd: %s", e)
return {}

Expand Down
Loading

0 comments on commit 0f3eb04

Please sign in to comment.