added new plugin: automount
This commit is contained in:
parent
f1f1c05226
commit
6ab39e3ffb
4 changed files with 125 additions and 0 deletions
38
plugins/volume_automount/lang/en.hdf
Normal file
38
plugins/volume_automount/lang/en.hdf
Normal file
|
@ -0,0 +1,38 @@
|
|||
Name = Automatic activation
|
||||
Link = Automatic activation
|
||||
|
||||
Title {
|
||||
AutoMountVolume = Activate during startup
|
||||
}
|
||||
|
||||
|
||||
Button {
|
||||
AutoMountOn = Enable automatic activation
|
||||
AutoMountOff = Disable automatic activation
|
||||
}
|
||||
|
||||
|
||||
Text {
|
||||
AutoIsOn = Currently automatic activation is enabled
|
||||
AutoIsOff = Currently automatic activation is disabled
|
||||
}
|
||||
|
||||
|
||||
SuccessMessage {
|
||||
AutoMountEnabled {
|
||||
Title = Automatic activation enabled
|
||||
Text = This volume will get activated during startup
|
||||
}
|
||||
|
||||
AutoMountDisabled {
|
||||
Title = Automatic activation disabled
|
||||
Text = This volume will not get activated during startup
|
||||
}
|
||||
}
|
||||
|
||||
AdviceMessage {
|
||||
NoAutoMountForEncryptedVolumes {
|
||||
Text = Automatic activation is not possible for encrypted volumes.
|
||||
}
|
||||
}
|
||||
|
11
plugins/volume_automount/unittests.py
Normal file
11
plugins/volume_automount/unittests.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
import WebInterfaceTestClass
|
||||
|
||||
class unittests(WebInterfaceTestClass.WebInterfaceTestClass):
|
||||
|
||||
def test_read_form(self):
|
||||
url = self.URL + "volume_automount?weblang=en&device=%2Fdev%2Floop1"
|
||||
self.register_auth(url)
|
||||
self.cmd.go(url)
|
||||
self.cmd.find('automatic')
|
||||
self.cmd.find('startup')
|
||||
|
21
plugins/volume_automount/volume_automount.cs
Normal file
21
plugins/volume_automount/volume_automount.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?cs # $Id$ ?>
|
||||
|
||||
<h3><?cs var:html_escape(Lang.Plugins.volume_automount.Title.AutoMountVolume) ?></h3>
|
||||
|
||||
<?cs if:!Data.CurrentDisk.encryption ?>
|
||||
<p><?cs call:print_form_header("automount", "volume_automount") ?>
|
||||
<input type="hidden" name="device" value="<?cs var:html_escape(Data.CurrentDisk.device) ?>" />
|
||||
<?cs if:Data.Plugins.volume_automount.automount_setting ?>
|
||||
<?cs var:html_escape(Lang.Plugins.volume_automount.Text.AutoIsOn) ?>
|
||||
<input type="hidden" name="action" value="disable" />
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.volume_automount.Button.AutoMountOff) ?></button>
|
||||
<?cs else ?>
|
||||
<?cs var:html_escape(Lang.Plugins.volume_automount.Text.AutoIsOff) ?>
|
||||
<input type="hidden" name="action" value="enable" />
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.volume_automount.Button.AutoMountOn) ?></button>
|
||||
<?cs /if ?>
|
||||
</form></p>
|
||||
<?cs else ?>
|
||||
<?cs call:hint("Plugins.volume_automount.NoAutoMountForEncryptedVolumes") ?>
|
||||
<?cs /if ?>
|
||||
|
55
plugins/volume_automount/volume_automount.py
Normal file
55
plugins/volume_automount/volume_automount.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
import CryptoBoxPlugin
|
||||
from CryptoBoxExceptions import *
|
||||
|
||||
|
||||
class volume_automount(CryptoBoxPlugin.CryptoBoxPlugin):
|
||||
|
||||
pluginCapabilities = [ "volume" ]
|
||||
pluginVisibility = [ "properties" ]
|
||||
requestAuth = False
|
||||
rank = 80
|
||||
|
||||
trueString = "yes"
|
||||
falseString = "no"
|
||||
|
||||
|
||||
def doAction(self, action=None):
|
||||
container = self.cbox.getContainer(self.device)
|
||||
if action is None:
|
||||
pass
|
||||
elif action == "enable":
|
||||
container.attributes["automount"] = self.trueString
|
||||
self.hdf["Data.Success"] = "Plugins.volume_automount.AutoMountEnabled"
|
||||
self.cbox.log.info("volume_automount: enabled for device '%s'" % self.device)
|
||||
self.cbox.prefs.volumesDB.write()
|
||||
elif action == "disable":
|
||||
container.attributes["automount"] = self.falseString
|
||||
self.hdf["Data.Success"] = "Plugins.volume_automount.AutoMountDisabled"
|
||||
self.cbox.log.info("volume_automount: disabled for device '%s'" % self.device)
|
||||
self.cbox.prefs.volumesDB.write()
|
||||
else:
|
||||
self.cbox.log.info("volume_automount: invalid action (%s)" % str(action))
|
||||
self.__prepareHDF()
|
||||
return "volume_automount"
|
||||
|
||||
|
||||
def getStatus(self):
|
||||
return str(self.__isAutoMount())
|
||||
|
||||
|
||||
def __prepareHDF(self):
|
||||
if self.__isAutoMount():
|
||||
self.hdf[self.hdf_prefix + "automount_setting"] = "1"
|
||||
else:
|
||||
self.hdf[self.hdf_prefix + "automount_setting"] = "0"
|
||||
|
||||
|
||||
def __isAutoMount(self):
|
||||
container = self.cbox.getContainer(self.device)
|
||||
if not container:
|
||||
return False
|
||||
if container.attributes.has_key("automount"):
|
||||
return container.attributes["automount"] == self.trueString
|
||||
else:
|
||||
return False
|
||||
|
Loading…
Reference in a new issue