From 22f647bf9b80a812a13394da9d8b6692fd3c7080 Mon Sep 17 00:00:00 2001 From: Gunther Hagleitner <hagleitn@yahoo.com> Date: Wed, 8 Feb 2012 00:44:13 -0800 Subject: [PATCH] pylint cleanup --- devstack/components/swift.py | 12 +++++++----- devstack/progs/actions.py | 16 +++++----------- devstack/shell.py | 3 +-- pylintrc | 2 +- stack | 9 ++++----- utils/extract_json.py | 17 ++++++++++------- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/devstack/components/swift.py b/devstack/components/swift.py index ad1deca8..652f7ca3 100644 --- a/devstack/components/swift.py +++ b/devstack/components/swift.py @@ -34,6 +34,8 @@ SYSLOG_CONF = 'rsyslog.conf' SWIFT_MAKERINGS = 'swift-remakerings' SWIFT_STARTMAIN = 'swift-startmain' SWIFT_INIT = 'swift-init' +SWIFT_IMG = 'drives/images/swift.img' +DEVICE_PATH = 'drives/sdb1' CONFIGS = [SWIFT_CONF, PROXY_SERVER_CONF, ACCOUNT_SERVER_CONF, CONTAINER_SERVER_CONF, OBJECT_SERVER_CONF, RSYNC_CONF, SYSLOG_CONF, SWIFT_MAKERINGS, SWIFT_STARTMAIN] @@ -56,7 +58,7 @@ class SwiftUninstaller(comp.PythonUninstallComponent): self.datadir = sh.joinpths(self.appdir, self.cfg.get('swift', 'data_location')) def pre_uninstall(self): - sh.umount(sh.joinpths(self.datadir, 'drives/sdb1')) + sh.umount(sh.joinpths(self.datadir, DEVICE_PATH)) sh.replace_in_file('/etc/default/rsync', 'RSYNC_ENABLE=true', 'RSYNC_ENABLE=false', @@ -74,6 +76,10 @@ class SwiftInstaller(comp.PythonInstallComponent): self.bindir = sh.joinpths(self.appdir, BIN_DIR) self.datadir = sh.joinpths(self.appdir, self.cfg.get('swift', 'data_location')) self.logdir = sh.joinpths(self.datadir, 'logs') + self.startmain_file = sh.joinpths(self.bindir, SWIFT_STARTMAIN) + self.makerings_file = sh.joinpths(self.bindir, SWIFT_MAKERINGS) + self.fs_dev = sh.joinpths(self.datadir, DEVICE_PATH) + self.fs_image = sh.joinpths(self.datadir, SWIFT_IMG) self.auth_server = 'keystone' def _get_download_locations(self): @@ -116,13 +122,11 @@ class SwiftInstaller(comp.PythonInstallComponent): } def __create_data_location(self): - self.fs_image = sh.joinpths(self.datadir, 'drives/images/swift.img') sh.create_loopback_file(fname=self.fs_image, size=int(self.cfg.get('swift', 'loopback_disk_size')), fs_type='xfs') self.tracewriter.file_touched(self.fs_image) - self.fs_dev = sh.joinpths(self.datadir, 'drives/sdb1/') sh.mount_loopback_file(self.fs_image, self.fs_dev, 'xfs') sh.chown_r(self.fs_dev, sh.geteuid(), sh.getegid()) @@ -165,13 +169,11 @@ class SwiftInstaller(comp.PythonInstallComponent): '/etc/rsyslog.d/10-swift.conf') def __setup_binaries(self): - self.makerings_file = sh.joinpths(self.bindir, SWIFT_MAKERINGS) sh.move(sh.joinpths(self.cfgdir, SWIFT_MAKERINGS), self.makerings_file) sh.chmod(self.makerings_file, 777) self.tracewriter.file_touched(self.makerings_file) - self.startmain_file = sh.joinpths(self.bindir, SWIFT_STARTMAIN) sh.move(sh.joinpths(self.cfgdir, SWIFT_STARTMAIN), self.startmain_file) sh.chmod(self.startmain_file, 777) diff --git a/devstack/progs/actions.py b/devstack/progs/actions.py index 6dbe1069..c6aa4bf4 100644 --- a/devstack/progs/actions.py +++ b/devstack/progs/actions.py @@ -114,7 +114,7 @@ def _pre_run(action_name, root_dir, pkg_manager, config, component_order, instan _gen_localrc(config, rc_fn) -def _post_run(action_name, root_dir, pkg_manager, config, components, time_taken, results): +def _post_run(action_name, root_dir, config, components, time_taken, results): LOG.info("It took (%s) to complete action [%s]" % (common.format_secs_taken(time_taken), action_name)) if results: LOG.info('Check [%s] for traces of what happened.' % ", ".join(results)) @@ -161,16 +161,10 @@ def _print_cfgs(config_obj, action): LOG.info("Passwords:") map_print(passwords_gotten) if full_cfgs: - #TODO - #better way to do this?? (ie a list difference?) - filtered_mp = dict() - for key in full_cfgs.keys(): - if key in passwords_gotten: - continue - filtered_mp[key] = full_cfgs.get(key) - if filtered_mp: + filtered = {k: v for k, v in full_cfgs.items() if k not in passwords_gotten} + if filtered: LOG.info("Configs:") - map_print(filtered_mp) + map_print(filtered) if db_dsns: LOG.info("Data source names:") map_print(db_dsns) @@ -347,7 +341,7 @@ def _run_components(action_name, component_order, components, distro, root_dir, _uninstall(component, instance, force) end_time = time.time() #any post run actions go now - _post_run(action_name, root_dir=root_dir, pkg_manager=pkg_manager, + _post_run(action_name, root_dir=root_dir, config=config, components=components.keys(), time_taken=(end_time - start_time), results=results) diff --git a/devstack/shell.py b/devstack/shell.py index c28260ce..6a4fe549 100644 --- a/devstack/shell.py +++ b/devstack/shell.py @@ -377,8 +377,7 @@ def getuid(username): def gethomedir(): - #TODO will just using os.path.expanduser("~") work?? - return pwd.getpwuid(geteuid()).pw_dir + return os.path.expanduser("~") def getgid(groupname): diff --git a/pylintrc b/pylintrc index 2457a37b..a7447a19 100644 --- a/pylintrc +++ b/pylintrc @@ -13,7 +13,7 @@ # W0511: TODOs in code comments are fine. # W0613: Unused argument '??' should be ok (they are useful sometimes to know intention of variable) # W0622: Redefining id is fine. -disable=C0111,W0142,W0622,C0301,R0902,R0201,R0914,W0613,R0912 +disable=C0111,W0142,W0622,C0301,R0902,R0201,R0914,W0613,R0912,R0801 [Basic] diff --git a/stack b/stack index b1682c6c..6b6f9f1e 100755 --- a/stack +++ b/stack @@ -24,13 +24,12 @@ import sys import traceback #this needs to happen immediately (or thats what it seems) -log_fn = os.getenv('LOG_FILE') -if(log_fn == None): - log_fn = os.path.normpath(os.path.join("conf", 'logging.ini')) -logging.config.fileConfig(log_fn) +LOG_FN = os.getenv('LOG_FILE') +if(LOG_FN == None): + LOG_FN = os.path.normpath(os.path.join("conf", 'logging.ini')) +logging.config.fileConfig(LOG_FN) from devstack import opts -from devstack import settings from devstack import shell as sh from devstack import utils diff --git a/utils/extract_json.py b/utils/extract_json.py index a2df6764..784b2cce 100644 --- a/utils/extract_json.py +++ b/utils/extract_json.py @@ -3,13 +3,8 @@ import os import sys -if __name__ == "__main__": - me = os.path.basename(sys.argv[0]) - if len(sys.argv) == 1: - print("%s filename filename filename..." % (me)) - sys.exit(0) - fn = sys.argv[1] - with open(fn, "r") as f: +def clean_file(name): + with open(name, "r") as f: contents = f.read() lines = contents.splitlines() cleaned_up = list() @@ -22,4 +17,12 @@ if __name__ == "__main__": data = json.loads(cleaned_lines) output = json.dumps(data, indent=4, sort_keys=True) print(output) + + +if __name__ == "__main__": + ME = os.path.basename(sys.argv[0]) + if len(sys.argv) == 1: + print("%s filename filename filename..." % (ME)) + sys.exit(0) + clean_file(sys.argv[1]) sys.exit(0)