diff --git a/bin/run-graphite-devel-server.py b/bin/run-graphite-devel-server.py index ced6c4bda..79f2851e1 100755 --- a/bin/run-graphite-devel-server.py +++ b/bin/run-graphite-devel-server.py @@ -25,10 +25,10 @@ if options.libs: libdir = os.path.expanduser(options.libs) - print 'Adding %s to your PYTHONPATH' % libdir + print('Adding %s to your PYTHONPATH' % libdir) os.environ['PYTHONPATH'] = libdir + ':' + os.environ.get('PYTHONPATH','') -print "Running Graphite from %s under django development server\n" % graphite_root +print("Running Graphite from %s under django development server\n" % graphite_root) command = [ 'django-admin.py', @@ -41,6 +41,6 @@ if options.noreload: command.append('--noreload') -print ' '.join(command) +print(' '.join(command)) management.execute_from_command_line(command) diff --git a/check-dependencies.py b/check-dependencies.py index aa6f613c2..78cbacc1e 100755 --- a/check-dependencies.py +++ b/check-dependencies.py @@ -2,12 +2,10 @@ import sys -# Simple python version test -major,minor = sys.version_info[:2] -py_version = sys.version.split()[0] -if major != 2 or minor < 7: +if sys.version_info <= (2,7): # SystemExit defaults to returning 1 when printing a string to stderr - raise SystemExit("You are using python %s, but version 2.7 or greater is required" % py_version) + raise SystemExit("You are using python %s, but version 2.7 or greater is " + "required" % sys.version_info) required = 0 optional = 0 @@ -36,7 +34,7 @@ try: import cairo except ImportError: - sys.stderr.write("[REQUIRED] Unable to import the 'cairo' module, do you have pycairo installed for python %s?\n" % py_version) + sys.stderr.write("[REQUIRED] Unable to import the 'cairo' module, do you have pycairo installed for python %s?\n" % sys.version_info.major) cairo = None required += 1 @@ -66,7 +64,7 @@ try: import django except ImportError: - sys.stderr.write("[REQUIRED] Unable to import the 'django' module, do you have Django installed for python %s?\n" % py_version) + sys.stderr.write("[REQUIRED] Unable to import the 'django' module, do you have Django installed for python %s?\n" % sys.version_info.major) django = None required += 1 @@ -75,7 +73,7 @@ try: import pytz except ImportError: - sys.stderr.write("[REQUIRED] Unable to import the 'pytz' module, do you have pytz module installed for python %s?\n" % py_version) + sys.stderr.write("[REQUIRED] Unable to import the 'pytz' module, do you have pytz module installed for python %s?\n" % sys.version_info.major) required += 1 @@ -83,7 +81,7 @@ try: import pyparsing except ImportError: - sys.stderr.write("[REQUIRED] Unable to import the 'pyparsing' module, do you have pyparsing module installed for python %s?\n" % py_version) + sys.stderr.write("[REQUIRED] Unable to import the 'pyparsing' module, do you have pyparsing module installed for python %s?\n" % sys.version_info.major) required += 1 @@ -91,7 +89,7 @@ try: import tagging except ImportError: - sys.stderr.write("[REQUIRED] Unable to import the 'tagging' module, do you have django-tagging installed for python %s?\n" % py_version) + sys.stderr.write("[REQUIRED] Unable to import the 'tagging' module, do you have django-tagging installed for python %s?\n" % sys.version_info.major) required += 1 @@ -104,7 +102,7 @@ try: import memcache except ImportError: - sys.stderr.write("[OPTIONAL] Unable to import the 'memcache' module, do you have python-memcached installed for python %s? This feature is not required but greatly improves performance.\n" % py_version) + sys.stderr.write("[OPTIONAL] Unable to import the 'memcache' module, do you have python-memcached installed for python %s? This feature is not required but greatly improves performance.\n" % sys.version_info.major) optional += 1 @@ -112,7 +110,7 @@ try: import ldap except ImportError: - sys.stderr.write("[OPTIONAL] Unable to import the 'ldap' module, do you have python-ldap installed for python %s? Without python-ldap, you will not be able to use LDAP authentication in the graphite webapp.\n" % py_version) + sys.stderr.write("[OPTIONAL] Unable to import the 'ldap' module, do you have python-ldap installed for python %s? Without python-ldap, you will not be able to use LDAP authentication in the graphite webapp.\n" % sys.version_info.major) optional += 1 @@ -151,10 +149,10 @@ if optional: sys.stderr.write("%d optional dependencies not met. Please consider the optional items before proceeding.\n" % optional) else: - print "All optional dependencies are met." + print("All optional dependencies are met.") if required: sys.stderr.write("%d necessary dependencies not met. Graphite will not function until these dependencies are fulfilled.\n" % required) sys.exit(1) else: - print "All necessary dependencies are met." + print("All necessary dependencies are met.") diff --git a/contrib/demo-collector.py b/contrib/demo-collector.py index c996e8dea..6f9541c6d 100755 --- a/contrib/demo-collector.py +++ b/contrib/demo-collector.py @@ -19,7 +19,7 @@ def connect(self): try: self.s.connect((self.hostname, self.port)) except IOError, e: - print "connect: ", e + print("connect: ", e) return def disconnect(self): self.s.close() def send(self, data): @@ -166,7 +166,7 @@ def main(): data = host.get_all() for datum in data: metric = "system.%s.%s" % (hostname, datum) - if "-debug" in argv: print metric + if "-debug" in argv: print(metric) graphite.send(metric) sleep(DELAY) diff --git a/contrib/memcache_whisper.py b/contrib/memcache_whisper.py index 3a4535ab2..5d14d6320 100644 --- a/contrib/memcache_whisper.py +++ b/contrib/memcache_whisper.py @@ -110,7 +110,7 @@ def read(self,bytes): return file.read(self,bytes) def debug(message): - print 'DEBUG :: %s' % message + print('DEBUG :: %s' % message) __timingBlocks = {} diff --git a/contrib/test_aggregator_rules.py b/contrib/test_aggregator_rules.py index 2e52df71a..58d9065b6 100644 --- a/contrib/test_aggregator_rules.py +++ b/contrib/test_aggregator_rules.py @@ -12,9 +12,9 @@ ### Basic usage if len(sys.argv) != 3: - print "Usage: %s 'aggregator rule' 'line item'" % (__file__) - print "\nSample invocation: %s %s %s" % \ - (__file__, "'...sum.all (10) = sum ..<>.sum.'", 'stats.prod.js.ktime_sum.sum.host2' ) + print("Usage: %s 'aggregator rule' 'line item'" % (__file__)) + print("\nSample invocation: %s %s %s" % \ + (__file__, "'...sum.all (10) = sum ..<>.sum.'", 'stats.prod.js.ktime_sum.sum.host2' )) sys.exit(42) ### cli arguments @@ -26,18 +26,18 @@ rule = rm.parse_definition( raw_rule ) ### rule/parsed rule -print "Raw rule: %s" % raw_rule -print "Parsed rule: %s" % rule.regex.pattern +print("Raw rule: %s" % raw_rule) +print("Parsed rule: %s" % rule.regex.pattern) -print "\n======\n" +print("\n======\n") ### run the parse match = rule.regex.match( raw_metric ) -print "Raw metric: %s" % raw_metric +print("Raw metric: %s" % raw_metric) if match: - print "Match dict: %s" % match.groupdict() - print "Result: %s" % rule.output_template % match.groupdict() + print("Match dict: %s" % match.groupdict()) + print("Result: %s" % rule.output_template % match.groupdict()) else: - print "ERROR: NO MATCH" + print("ERROR: NO MATCH") diff --git a/examples/example-client.py b/examples/example-client.py index f2f3a4242..044b0e6dc 100644 --- a/examples/example-client.py +++ b/examples/example-client.py @@ -43,7 +43,7 @@ def get_loadavg(): try: sock.connect( (CARBON_SERVER,CARBON_PORT) ) except: - print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT } + print("Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT }) sys.exit(1) while True: @@ -55,9 +55,9 @@ def get_loadavg(): lines.append("system.loadavg_5min %s %d" % (loadavg[1],now)) lines.append("system.loadavg_15min %s %d" % (loadavg[2],now)) message = '\n'.join(lines) + '\n' #all lines must end in a newline - print "sending message\n" - print '-' * 80 - print message - print + print("sending message\n") + print('-' * 80) + print(message) + print() sock.sendall(message) time.sleep(delay)