coding style improvements according to pylint
This commit is contained in:
parent
759b5bcf16
commit
5019afd334
9 changed files with 64 additions and 45 deletions
|
@ -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):
|
||||
|
|
|
@ -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()])
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
__revision__ = "$Id"
|
||||
|
||||
|
||||
#TODO: add netmask and gateway
|
||||
|
||||
## necessary: otherwise CryptoBoxRootActions.py will refuse to execute this script
|
||||
PLUGIN_TYPE = "cryptobox"
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 += "<fieldset><legend><?cs var:html_escape(Lang.Plugins.%s.Link) ?></legend><?cs include:'%s' ?></fieldset>" \
|
||||
#load_string += "<fieldset><?cs include:'%s' ?></fieldset>" \
|
||||
load_string += "<?cs include:'%s' ?>" \
|
||||
% plfname
|
||||
load_string += "<?cs include:'%s' ?>" % 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue