Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 592
Py3k add support for running the same codebase on python2.6/2.7 and 3.3+#259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c79867b652331e6909cab88610844f7ace9451f4d71b5ea974aba7e6d37d44780338fb289553dad04027f4fd5acad53be5494eb697a9e91e86dd2865842b2b1011b1700b1b09453fca5e45cc5fe7c68fa7c70c384f1793d678960a77066b52c263aaFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #!/usr/bin/env python | ||
| ################################################################################ | ||
| from __future__ import print_function | ||
| import os | ||
| import sys | ||
| @@ -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 | ||
| @@ -77,7 +78,7 @@ def getCollectors(path): | ||
| def typeToString(key): | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any of these This is covered in | ||
| if isinstance(obj.config[key], basestring): | ||
| if isinstance(obj.config[key], str): | ||
| user_val = obj.config[key] | ||
| elif isinstance(obj.config[key], bool): | ||
| user_val = str(obj.config[key]) | ||
| @@ -94,15 +95,15 @@ def typeToString(key): | ||
| def stringToType(key, val): | ||
| if type(obj.config[key]) is type(val): | ||
| config_file[key] = val | ||
| elif isinstance(obj.config[key], basestring): | ||
| elif isinstance(obj.config[key], str): | ||
| if val.lower() == 'false': | ||
| config_file[key] = False | ||
| elif val.lower() == 'true': | ||
| config_file[key] = True | ||
| else: | ||
| config_file[key] = val | ||
| elif isinstance(obj.config[key], bool): | ||
| if isinstance(val, basestring): | ||
| if isinstance(val, str): | ||
| config_file[key] = str_to_bool(val) | ||
| else: | ||
| config_file[key] = bool(val) | ||
| @@ -116,7 +117,7 @@ def stringToType(key, val): | ||
| def boolCheck(val): | ||
| if isinstance(val, basestring): | ||
| if isinstance(val, str): | ||
| return str_to_bool(val) | ||
| elif isinstance(val, bool): | ||
| return val | ||
| @@ -133,9 +134,9 @@ def configureKey(key): | ||
| except NotImplementedError: | ||
| return | ||
| print"\n" | ||
| print("\n") | ||
| if key in default_conf_help: | ||
| printdefault_conf_help[key] | ||
| print(default_conf_help[key]) | ||
| val = raw_input(key + ' [' + user_val + ']: ') | ||
| # Empty user input? Default to current value | ||
| @@ -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' | ||
| printconfig['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': | ||
| @@ -225,7 +226,7 @@ if __name__ == "__main__": | ||
| obj = cls(config=config, handlers={}) | ||
| if options.dump: | ||
| printcollector + " " + str(obj.config) | ||
| print(collector + " " + str(obj.config)) | ||
| continue | ||
| default_conf = obj.get_default_config() | ||
| @@ -241,8 +242,8 @@ if __name__ == "__main__": | ||
| config_keys['instance_prefix'] = False | ||
| config_keys['interval'] = False | ||
| print"\n\t\tNow configuring " + collector | ||
| printcollectors[collector].__doc__ | ||
| print("\n\t\tNow configuring " + collector) | ||
| print(collectors[collector].__doc__) | ||
| configureKey('enabled') | ||
| @@ -254,12 +255,12 @@ if __name__ == "__main__": | ||
| config_file.write() | ||
| except IOError, (errno, strerror): | ||
| print"I/O error({0}): {1}".format(errno, strerror) | ||
| except IOError as err: | ||
| print("I/O error({0}): {1}".format(err.errno, err.strerror)) | ||
| except KeyboardInterrupt: | ||
| print("") | ||
| sys.exit() | ||
| except: | ||
| continue | ||
| if not foundcollector: | ||
| print"Collector not found." | ||
| print("Collector not found.") | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you were using this for testing, but I'd rather us default any
PYTHONtopython2, or at least justpythonand let the environment gods use whichever is default.