Skip to content

Commit

Permalink
minor Python 3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr1212 authored and DanCech committed Dec 15, 2017
1 parent 4a27e48 commit 6b91f29
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 35 deletions.
6 changes: 3 additions & 3 deletions bin/run-graphite-devel-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -41,6 +41,6 @@
if options.noreload:
command.append('--noreload')

print ' '.join(command)
print(' '.join(command))

management.execute_from_command_line(command)
26 changes: 12 additions & 14 deletions check-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -75,23 +73,23 @@
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


# Test for pyparsing
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


# Test for django-tagging
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


Expand All @@ -104,15 +102,15 @@
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


# Test for python-ldap
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


Expand Down Expand Up @@ -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.")
4 changes: 2 additions & 2 deletions contrib/demo-collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion contrib/memcache_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
20 changes: 10 additions & 10 deletions contrib/test_aggregator_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__, "'<prefix>.<env>.<key>.sum.all (10) = sum <prefix>.<env>.<<key>>.sum.<node>'", 'stats.prod.js.ktime_sum.sum.host2' )
print("Usage: %s 'aggregator rule' 'line item'" % (__file__))
print("\nSample invocation: %s %s %s" % \
(__file__, "'<prefix>.<env>.<key>.sum.all (10) = sum <prefix>.<env>.<<key>>.sum.<node>'", 'stats.prod.js.ktime_sum.sum.host2' ))
sys.exit(42)

### cli arguments
Expand All @@ -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")
10 changes: 5 additions & 5 deletions examples/example-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

0 comments on commit 6b91f29

Please sign in to comment.