summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Mueller <dirk@dmllr.de>2013-06-23 20:31:46 +0200
committerDirk Mueller <dirk@dmllr.de>2013-07-07 15:18:52 +0200
commit88a2e86fb3bc514cfcd5646213847af3e691652a (patch)
tree4ed258ab4adec44717c0b0d83b92c4250ac884a0
parent5be592b55c465b5e0fb5327b105bfd46e582cdab (diff)
downloadoslo-88a2e86fb3bc514cfcd5646213847af3e691652a.zip
oslo-88a2e86fb3bc514cfcd5646213847af3e691652a.tar.gz
oslo-88a2e86fb3bc514cfcd5646213847af3e691652a.tar.xz
Use print operator in function style
This is compatible with Python 3.x and works with any Python version >= 2.6. Change-Id: I6d8afdc5135cb01e6096f4d25b4ca632fe1e75cd
-rwxr-xr-xopenstack/common/config/generator.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/openstack/common/config/generator.py b/openstack/common/config/generator.py
index 0dd7c97..404a09a 100755
--- a/openstack/common/config/generator.py
+++ b/openstack/common/config/generator.py
@@ -18,8 +18,11 @@
#
# @author: Zhongyue Luo, SINA Corporation.
#
+
"""Extracts OpenStack config option info from module(s)."""
+from __future__ import print_function
+
import imp
import os
import re
@@ -97,7 +100,7 @@ def generate(srcfiles):
for group, opts in opts_by_group.items():
print_group_opts(group, opts)
- print "# Total option count: %d" % OPTION_COUNT
+ print("# Total option count: %d" % OPTION_COUNT)
def _import_module(mod_str):
@@ -161,18 +164,18 @@ def _list_opts(obj):
def print_group_opts(group, opts_by_module):
- print "[%s]" % group
- print
+ print("[%s]" % group)
+ print('')
global OPTION_COUNT
for mod, opts in opts_by_module:
OPTION_COUNT += len(opts)
- print '#'
- print '# Options defined in %s' % mod
- print '#'
- print
+ print('#')
+ print('# Options defined in %s' % mod)
+ print('#')
+ print('')
for opt in opts:
_print_opt(opt)
- print
+ print('')
def _get_my_ip():
@@ -218,33 +221,33 @@ def _print_opt(opt):
sys.stderr.write("%s\n" % str(err))
sys.exit(1)
opt_help += ' (' + OPT_TYPES[opt_type] + ')'
- print '#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH))
+ print('#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH)))
try:
if opt_default is None:
- print '#%s=<None>' % opt_name
+ print('#%s=<None>' % opt_name)
elif opt_type == STROPT:
assert(isinstance(opt_default, basestring))
- print '#%s=%s' % (opt_name, _sanitize_default(opt_default))
+ print('#%s=%s' % (opt_name, _sanitize_default(opt_default)))
elif opt_type == BOOLOPT:
assert(isinstance(opt_default, bool))
- print '#%s=%s' % (opt_name, str(opt_default).lower())
+ print('#%s=%s' % (opt_name, str(opt_default).lower()))
elif opt_type == INTOPT:
assert(isinstance(opt_default, int) and
not isinstance(opt_default, bool))
- print '#%s=%s' % (opt_name, opt_default)
+ print('#%s=%s' % (opt_name, opt_default))
elif opt_type == FLOATOPT:
assert(isinstance(opt_default, float))
- print '#%s=%s' % (opt_name, opt_default)
+ print('#%s=%s' % (opt_name, opt_default))
elif opt_type == LISTOPT:
assert(isinstance(opt_default, list))
- print '#%s=%s' % (opt_name, ','.join(opt_default))
+ print('#%s=%s' % (opt_name, ','.join(opt_default)))
elif opt_type == MULTISTROPT:
assert(isinstance(opt_default, list))
if not opt_default:
opt_default = ['']
for default in opt_default:
- print '#%s=%s' % (opt_name, default)
- print
+ print('#%s=%s' % (opt_name, default))
+ print('')
except Exception:
sys.stderr.write('Error in option "%s"\n' % opt_name)
sys.exit(1)
@@ -252,7 +255,7 @@ def _print_opt(opt):
def main():
if len(sys.argv) < 2:
- print "usage: %s [srcfile]...\n" % sys.argv[0]
+ print("usage: %s [srcfile]...\n" % sys.argv[0])
sys.exit(0)
generate(sys.argv[1:])