From 5019afd33436f1c4259d45574587515d01d82183 Mon Sep 17 00:00:00 2001 From: lars Date: Thu, 8 Feb 2007 02:17:18 +0000 Subject: [PATCH] coding style improvements according to pylint --- plugins/logs/logs.py | 3 +- plugins/network/network.py | 19 +++++++---- plugins/network/root_action.py | 2 -- plugins/plugin_manager/plugin_manager.py | 1 - plugins/plugin_manager/unittests.py | 36 +++++++++++--------- plugins/volume_chpasswd/volume_chpasswd.py | 7 ++-- plugins/volume_format_fs/volume_format_fs.py | 18 ++++++---- plugins/volume_mount/volume_mount.py | 18 ++++++---- plugins/volume_props/volume_props.py | 5 +-- 9 files changed, 64 insertions(+), 45 deletions(-) diff --git a/plugins/logs/logs.py b/plugins/logs/logs.py index 3560c0f..6b61a03 100644 --- a/plugins/logs/logs.py +++ b/plugins/logs/logs.py @@ -84,7 +84,8 @@ class logs(cryptobox.plugins.base.CryptoBoxPlugin): if log_file is None: return "" else: - return cherrypy.lib.cptools.serveFile(log_file, disposition="attachment", name="cryptobox_logfile.txt") + return cherrypy.lib.cptools.serveFile(log_file, + disposition="attachment", name="cryptobox_logfile.txt") def get_status(self): diff --git a/plugins/network/network.py b/plugins/network/network.py index 25be06c..434faaa 100644 --- a/plugins/network/network.py +++ b/plugins/network/network.py @@ -48,7 +48,8 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): request_auth = True rank = 30 - def do_action(self, store=None, redirected="", ip1="", ip2="", ip3="", ip4="", nm1="", nm2="", nm3="", nm4=""): + def do_action(self, store=None, redirected="", ip1="", ip2="", ip3="", ip4="", + nm1="", nm2="", nm3="", nm4=""): """Show a form containing the current IP - change it if requested. """ ## if we were redirected, then we should display the default page @@ -59,7 +60,8 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): ## check possible actions if store is None: ## no action was requested -> just show the form - self.cbox.log.debug("network plugin: show form (interface %s)" % self.__get_interface()) + self.cbox.log.debug("network plugin: show form (interface %s)" \ + % self.__get_interface()) self.__prepare_form_data() return "form_network" ## change of ip address and/or netmask requested @@ -196,8 +198,11 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): self.hdf[self.hdf_prefix + "gw.oc4"] = oc4 - def __get_current_ip(self, type="ip"): + def __get_current_ip(self, address_type="ip"): """Retrieve the current IP. + + TODO: do not use "address_type" for ip and netmask, but return both in + two tuples """ import re ## get the current IP of the network interface @@ -210,7 +215,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): (stdout, stderr) = proc.communicate() if proc.returncode != 0: return (0, 0, 0, 0) - if type == "ip": + if address_type == "ip": ## this regex matches the four numbers of the IP match = re.search(r'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', stdout) if match: @@ -218,9 +223,11 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): return tuple([int(e) for e in match.groups()]) else: return (0, 0, 0, 0) - elif type == "nm": + elif address_type == "nm": ## this greps the netmask - match = re.search(r'inet [\w]+:.*Mask:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', stdout) + match = re.search( + r'inet [\w]+:.*Mask:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', + stdout) if match: ## use the previously matched numbers return tuple([int(e) for e in match.groups()]) diff --git a/plugins/network/root_action.py b/plugins/network/root_action.py index 01492ef..28e2839 100755 --- a/plugins/network/root_action.py +++ b/plugins/network/root_action.py @@ -22,8 +22,6 @@ __revision__ = "$Id" -#TODO: add netmask and gateway - ## necessary: otherwise CryptoBoxRootActions.py will refuse to execute this script PLUGIN_TYPE = "cryptobox" diff --git a/plugins/plugin_manager/plugin_manager.py b/plugins/plugin_manager/plugin_manager.py index e3f6f92..09327bd 100644 --- a/plugins/plugin_manager/plugin_manager.py +++ b/plugins/plugin_manager/plugin_manager.py @@ -88,7 +88,6 @@ class plugin_manager(cryptobox.plugins.base.CryptoBoxPlugin): def __distribute_ranks(self): """evenly distribute the 'rank' values according to the current order of the list""" - pl_conf = self.cbox.prefs.plugin_conf dist = 100 / (len(self.plugins) - 1) for (index, pl) in enumerate(self.plugins): pl.set_rank(dist*index) diff --git a/plugins/plugin_manager/unittests.py b/plugins/plugin_manager/unittests.py index 3207fd5..83eb994 100644 --- a/plugins/plugin_manager/unittests.py +++ b/plugins/plugin_manager/unittests.py @@ -22,6 +22,8 @@ __revision__ = "$Id" from cryptobox.tests.base import WebInterfaceTestClass +COMMON_STRING = 'Volume plugins' + class unittests(WebInterfaceTestClass): def test_read_form(self): @@ -30,7 +32,7 @@ class unittests(WebInterfaceTestClass): url = self.url + "plugin_manager?weblang=en" self.register_auth(url) self.cmd.go(url) - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) def test_set_options(self): @@ -40,25 +42,25 @@ class unittests(WebInterfaceTestClass): url = self.url + "plugin_manager" self.register_auth(url) self.cmd.go(url + r"?plugin_name=t/-!") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?plugin_name=foobar") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?plugin_name=disks&action=up") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?plugin_name=disks&action=down") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?store=1&dis/ks_listed") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?store=1&disks_listed&disks_visible_menu") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?store=1&disks_listed&disks_visible_menu=1&disks_rank=50") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?store=1&disks_listed&disks_visible_menu=1&disks_rank=x") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?store=1&disks_listed&disks_visible_menu=1&disks_auth=1") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?store=1&disks_listed&disks_visible_menu=1&disks_rank=50&disks_auth=1") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) def test_move_up(self): @@ -68,11 +70,11 @@ class unittests(WebInterfaceTestClass): url = self.url + "plugin_manager" self.register_auth(url) self.cmd.go(url + r"?plugin_name=disks&action=up") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?store=1&disks_listed&disks_visible_menu=1&disks_rank=0") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?plugin_name=disks&action=up") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) def test_move_down(self): @@ -82,9 +84,9 @@ class unittests(WebInterfaceTestClass): url = self.url + "plugin_manager" self.register_auth(url) self.cmd.go(url + r"?plugin_name=disks&action=down") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?store=1&disks_listed&disks_visible_menu=1&disks_rank=100") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) self.cmd.go(url + r"?plugin_name=disks&action=down") - self.cmd.find('Plugin Manager') + self.cmd.find(COMMON_STRING) diff --git a/plugins/volume_chpasswd/volume_chpasswd.py b/plugins/volume_chpasswd/volume_chpasswd.py index 521aefd..2fb4505 100644 --- a/plugins/volume_chpasswd/volume_chpasswd.py +++ b/plugins/volume_chpasswd/volume_chpasswd.py @@ -73,11 +73,14 @@ class volume_chpasswd(cryptobox.plugins.base.CryptoBoxPlugin): try: self.container.change_password(old_pw, new_pw) except CBInvalidType, err_msg: - self.cbox.log.info("plugin 'volume_chpasswd' - cannot change passphrase for non-encrypted container (%s): %s" % (self.device, err_msg)) + self.cbox.log.info("plugin 'volume_chpasswd' - cannot change " \ + + "passphrase for non-encrypted container (%s): %s" \ + % (self.device, err_msg)) except CBVolumeIsActive: self.hdf["Data.Warning"] = "VolumeMayNotBeMounted" except CBChangePasswordError, err_msg: - self.cbox.log.warn("plugin 'volume_chpasswd' - cannot change password for device (%s): %s" % (self.device, err_msg)) + self.cbox.log.warn("plugin 'volume_chpasswd' - cannot change " \ + + "password for device (%s): %s" % (self.device, err_msg)) self.hdf["Data.Warning"] = "Plugins.volume_chpasswd.PasswordChange" else: self.hdf["Data.Success"] = "Plugins.volume_chpasswd.PasswordChange" diff --git a/plugins/volume_format_fs/volume_format_fs.py b/plugins/volume_format_fs/volume_format_fs.py index d9df1fd..cb67603 100644 --- a/plugins/volume_format_fs/volume_format_fs.py +++ b/plugins/volume_format_fs/volume_format_fs.py @@ -38,7 +38,8 @@ class volume_format_fs(cryptobox.plugins.base.CryptoBoxPlugin): rank = 60 - def do_action(self, store=None, fs_type="windows", container_type="luks", crypto_password=None, crypto_password2=None, confirm=None): + def do_action(self, store=None, fs_type="windows", container_type="luks", + crypto_password=None, crypto_password2=None, confirm=None): container = self.cbox.get_container(self.device) ## exit immediately if the device is not writeable if not container.is_writeable(): @@ -57,7 +58,8 @@ class volume_format_fs(cryptobox.plugins.base.CryptoBoxPlugin): self.hdf[self.hdf_prefix + "fs_types." + t] = t if store == "step1": if not confirm: - self.cbox.log.info("Missing confirmation for formatting of filesystem: %s" % self.device) + self.cbox.log.info("Missing confirmation for formatting of " + \ + "filesystem: %s" % self.device) self.hdf["Data.Warning"] = "Plugins.volume_format_fs.FormatNotConfirmed" return "volume_format" if container_type == "luks": @@ -66,9 +68,11 @@ class volume_format_fs(cryptobox.plugins.base.CryptoBoxPlugin): return self.__format_plain(FSTYPES[fs_type]) elif store == "step2": if container_type == "luks": - return self.__format_luks(FSTYPES[fs_type], crypto_password, crypto_password2) + return self.__format_luks(FSTYPES[fs_type], + crypto_password, crypto_password2) else: - self.cbox.log.info("Invalid input value for 'container_type': %s" % container_type) + self.cbox.log.info("Invalid input value for 'container_type': %s" \ + % container_type) return "volume_format" elif store: self.cbox.log.info("Invalid input value for 'store': %s" % store) @@ -104,11 +108,13 @@ class volume_format_fs(cryptobox.plugins.base.CryptoBoxPlugin): def __format_luks(self, fs_type, pw, pw2): if not pw: self.hdf["Data.Warning"] = "EmptyPassword" - self.cbox.log.info("No crypto password was supplied for initialization of device '%s'" % self.device) + self.cbox.log.info("No crypto password was supplied for initialization " \ + + "of device '%s'" % self.device) return "volume_format" if pw != pw2: self.hdf["Data.Warning"] = "DifferentPasswords" - self.cbox.log.info("The crypto password was not repeated correctly for initialization of device '%s'" % self.device) + self.cbox.log.info("The crypto password was not repeated correctly for " \ + + "initialization of device '%s'" % self.device) return "volume_format" container = self.cbox.get_container(self.device) try: diff --git a/plugins/volume_mount/volume_mount.py b/plugins/volume_mount/volume_mount.py index 99a9fe0..12f89c5 100644 --- a/plugins/volume_mount/volume_mount.py +++ b/plugins/volume_mount/volume_mount.py @@ -73,11 +73,13 @@ class volume_mount(cryptobox.plugins.base.CryptoBoxPlugin): self.container.mount() except CBMountError, err_msg: self.hdf["Data.Warning"] = "Plugins.volume_mount.MountFailed" - self.cbox.log.warn("failed to mount the device (%s): %s" % (self.device, err_msg)) + self.cbox.log.warn("failed to mount the device (%s): %s" \ + % (self.device, err_msg)) return "volume_status" except CBContainerError, err_msg: self.hdf["Data.Warning"] = "Plugins.volume_mount.MountFailed" - self.cbox.log.warn("failed to mount the device (%s): %s" % (self.device, err_msg)) + self.cbox.log.warn("failed to mount the device (%s): %s" \ + % (self.device, err_msg)) return "volume_status" self.cbox.log.info("successfully mounted the volume: %s" % self.device) self.hdf["Data.Success"] = "Plugins.volume_mount.MountDone" @@ -95,17 +97,20 @@ class volume_mount(cryptobox.plugins.base.CryptoBoxPlugin): return "volume_status" if not pw: self.hdf["Data.Warning"] = "EmptyPassword" - self.cbox.log.info("no password was supplied for mounting of device: '%s'" % self.device) + self.cbox.log.info("no password was supplied for mounting of device: '%s'" \ + % self.device) return "volume_status" try: self.container.mount(pw) except CBMountError, err_msg: self.hdf["Data.Warning"] = "Plugins.volume_mount.MountCryptoFailed" - self.cbox.log.warn("failed to mount the device (%s): %s" % (self.device, err_msg)) + self.cbox.log.warn("failed to mount the device (%s): %s" \ + % (self.device, err_msg)) return "volume_status" except CBContainerError, err_msg: self.hdf["Data.Warning"] = "Plugins.volume_mount.MountCryptoFailed" - self.cbox.log.warn("failed to mount the device (%s): %s" % (self.device, err_msg)) + self.cbox.log.warn("failed to mount the device (%s): %s" \ + % (self.device, err_msg)) return "volume_status" self.cbox.log.info("successfully mounted the volume: %s" % self.device) self.hdf["Data.Success"] = "Plugins.volume_mount.MountDone" @@ -121,7 +126,8 @@ class volume_mount(cryptobox.plugins.base.CryptoBoxPlugin): self.container.umount() except CBUmountError, err_msg: self.hdf["Data.Warning"] = "UmountFailed" - self.cbox.log.warn("could not umount the volume (%s): %s" % (self.device, err_msg)) + self.cbox.log.warn("could not umount the volume (%s): %s" \ + % (self.device, err_msg)) return "volume_status" self.cbox.log.info("successfully unmounted the container: %s" % self.device) self.hdf["Data.Success"] = "Plugins.volume_mount.UmountDone" diff --git a/plugins/volume_props/volume_props.py b/plugins/volume_props/volume_props.py index b79b760..ae0eb5b 100644 --- a/plugins/volume_props/volume_props.py +++ b/plugins/volume_props/volume_props.py @@ -52,10 +52,7 @@ class volume_props(cryptobox.plugins.base.CryptoBoxPlugin): continue p.device = self.device plfname = os.path.join(p.plugin_dir, str(p.do_action(**args)) + ".cs") - #load_string += "
" \ - #load_string += "
" \ - load_string += "" \ - % plfname + load_string += "" % plfname ## this is a little bit ugly: as it is not possible, to load cs files via ## 'linclude' (see clearsilver doc) if they use previously defined macros ## (see clearsilver mailing list thread