language namespace for plugins separated
plugin interface changed ("prepareForm" removed) plugins do not raise exceptions anymore first part of the partitioning plugin device-specific stuff moved to CryptoBoxTools
This commit is contained in:
parent
f2a7ceb61c
commit
de3280806f
26 changed files with 622 additions and 309 deletions
|
@ -0,0 +1,8 @@
|
|||
<?cs loop: x = #0, subcount(Data.Plugins.partition.Parts)-1, #1 ?>
|
||||
<input type="hidden" name="part<?cs var:x ?>_size" value="<?cs var:Data.Plugins.partition.Parts[x].Size ?>" />
|
||||
<input type="hidden" name="part<?cs var:x ?>_type" value="<?cs var:Data.Plugins.partition.Parts[x].Type ?>" /><?cs
|
||||
/loop ?>
|
||||
|
||||
<input type="hidden" name="block_device" value="<?cs var:html_escape(Data.Plugins.partition.Device) ?>" />
|
||||
|
||||
|
33
pythonrewrite/plugins/partition/lang/en.hdf
Normal file
33
pythonrewrite/plugins/partition/lang/en.hdf
Normal file
|
@ -0,0 +1,33 @@
|
|||
Name = Disk partitioning
|
||||
Link = Disk partitioning
|
||||
Rank = 80
|
||||
|
||||
Title.Partition = Disk partitions
|
||||
|
||||
Button {
|
||||
SelectDevice = Repartition disk
|
||||
AddPartition = Add another partition
|
||||
Back = Back
|
||||
SavePartitions = Save changes
|
||||
AbortPartitions = Cancel
|
||||
}
|
||||
|
||||
Text {
|
||||
FS {
|
||||
Type = Filesystem type
|
||||
Fat = FAT (Windows)
|
||||
Ext2 = Ext2
|
||||
Ext3 = Ext3
|
||||
Reiser = Reiser
|
||||
}
|
||||
Size = Size (MB)
|
||||
SelectDevice = Choose a disk for partitioning
|
||||
NoDevicesAvailable = No suitable disks found - please check your configuration and hardware setup.
|
||||
|
||||
|
||||
WarningMessage {
|
||||
InvalidInput {
|
||||
Title = Invalid input
|
||||
Text = You entered an invalid value.
|
||||
}
|
||||
}
|
132
pythonrewrite/plugins/partition/partition.py
Normal file
132
pythonrewrite/plugins/partition/partition.py
Normal file
|
@ -0,0 +1,132 @@
|
|||
import re
|
||||
import subprocess
|
||||
import imp
|
||||
import os
|
||||
import logging
|
||||
import CryptoBoxTools
|
||||
|
||||
PartTypes = {
|
||||
"linux" : "L",
|
||||
"windows" : "0xC"}
|
||||
|
||||
logger = logging.getLogger("CryptoBox")
|
||||
|
||||
def doAction(hdf, cbox, **args):
|
||||
try:
|
||||
step = args["step"]
|
||||
del args["step"]
|
||||
except KeyError:
|
||||
step = "select_device"
|
||||
if step == "add_partition":
|
||||
return __actionAddPartition(hdf, cbox, args)
|
||||
if step == "del_partition":
|
||||
return __actionDelPartition(hdf, cbox, args)
|
||||
elif step == "finish":
|
||||
return __actionFinish(hdf, cbox, args)
|
||||
else: # for "select_device" and for invalid targets
|
||||
return __actionSelectDevice(hdf, cbox, args)
|
||||
|
||||
|
||||
def getStatus(cbox):
|
||||
return "%d.%d.%d.%d" % __getCurrentIP(cbox)
|
||||
|
||||
|
||||
def __isDeviceValid(device, cbox):
|
||||
if not cbox.isDeviceAllowed(device):
|
||||
return False
|
||||
if not device in CryptoBoxTools.getParentBlockDevices():
|
||||
return False
|
||||
|
||||
|
||||
def __actionSelectDevice(hdf, cbox, args):
|
||||
block_devices = [e
|
||||
for e in CryptoBoxTools.getParentBlockDevices()
|
||||
if cbox.isDeviceAllowed(e)]
|
||||
counter = 0
|
||||
for a in block_devices:
|
||||
hdf["Data.Plugins.partition.BlockDevices.%d" % counter] = a
|
||||
cbox.log.debug("found a suitable block device: %s" % a)
|
||||
counter += 1
|
||||
return "select_device"
|
||||
|
||||
|
||||
def __actionAddPartition(hdf, cbox, args):
|
||||
try:
|
||||
device = args["block_device"]
|
||||
except KeyError:
|
||||
return __actionSelectDevice(hdf, cbox, args)
|
||||
#FIXME: the following check should obviuosly get reversed
|
||||
if __isDeviceValid(device, cbox): return __actionSelectDevice(hdf, cbox, args)
|
||||
size = __getDeviceSize(device)
|
||||
hdf["Data.Plugins.partition.Device"] = device
|
||||
hdf["Data.Plugins.partition.Device.Size"] = size
|
||||
parts = __getPartitionsFromArgs(args, size)
|
||||
__setPartitionData(hdf, parts, size)
|
||||
return "set_partitions"
|
||||
|
||||
|
||||
def __actionDelPartition(hdf, cbox, args):
|
||||
try:
|
||||
device = args["block_device"]
|
||||
except KeyError:
|
||||
return __actionSelectDevice(hdf, cbox, args)
|
||||
#FIXME: the following check should obviuosly get reversed
|
||||
if __isDeviceValid(device, cbox): return __actionSelectDevice(hdf, cbox, args)
|
||||
size = __getDeviceSize(device)
|
||||
hdf["Data.Plugins.partition.Device"] = device
|
||||
hdf["Data.Plugins.partition.Device.Size"] = size
|
||||
parts = __getPartitionsFromArgs(args, size)
|
||||
__setPartitionData(hdf, parts[:-1], size)
|
||||
return "set_partitions"
|
||||
|
||||
|
||||
def __setPartitionData(hdf, parts, size):
|
||||
availSize = size
|
||||
i = 0
|
||||
for part in parts:
|
||||
logger.debug(part)
|
||||
hdf["Data.Plugins.partition.Parts.%d.Size" % i] = part["size"]
|
||||
hdf["Data.Plugins.partition.Parts.%d.Type" % i] = part["type"]
|
||||
availSize -= part["size"]
|
||||
i += 1
|
||||
hdf["Data.Plugins.partition.availSize"] = availSize
|
||||
for t in PartTypes.keys():
|
||||
hdf["Data.Plugins.partition.Types.%s" % t] = t
|
||||
|
||||
|
||||
def __getPartitionsFromArgs(args, maxSize):
|
||||
parts = []
|
||||
done = False
|
||||
availSize = maxSize
|
||||
i = -1
|
||||
while not done:
|
||||
i += 1
|
||||
try:
|
||||
size = int(args["part%d_size" % i])
|
||||
partType = args["part%d_type" % i]
|
||||
if int(size) > availSize: continue
|
||||
if int(size) <= 0: continue
|
||||
if not partType in PartTypes.keys(): continue
|
||||
parts.append({"size":size, "type":partType})
|
||||
availSize -= size
|
||||
except TypeError:
|
||||
pass
|
||||
except KeyError:
|
||||
done = True
|
||||
return parts
|
||||
|
||||
|
||||
def __getDeviceSize(device):
|
||||
rdev = os.stat(device).st_rdev
|
||||
minor = os.minor(rdev)
|
||||
major = os.major(rdev)
|
||||
for f in file("/proc/partitions"):
|
||||
try:
|
||||
elements = f.split()
|
||||
if len(elements) != 4: continue
|
||||
if (int(elements[0]) == major) and (int(elements[1]) == minor):
|
||||
return int(elements[2])
|
||||
except ValueError:
|
||||
pass
|
||||
return 0
|
||||
|
33
pythonrewrite/plugins/partition/root_action.py
Executable file
33
pythonrewrite/plugins/partition/root_action.py
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python2.4
|
||||
|
||||
#TODO: add netmask and gateway
|
||||
|
||||
## necessary: otherwise CryptoBoxRootActions.py will refuse to execute this script
|
||||
PLUGIN_TYPE = "cryptobox"
|
||||
|
||||
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
|
||||
self_bin =sys.argv[0]
|
||||
|
||||
if len(args) > 1:
|
||||
sys.stderr.write("%s: too many arguments (%s)\n" % (self_bin, args))
|
||||
sys.exit(1)
|
||||
|
||||
if len(args) == 0:
|
||||
sys.stderr.write("%s: no argument supplied\n" % self_bin)
|
||||
sys.exit(1)
|
||||
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
args = [IFCONFIG_BIN, IFACE, args[0]])
|
||||
proc.communicate()
|
||||
sys.exit(proc.returncode)
|
||||
|
27
pythonrewrite/plugins/partition/select_device.cs
Normal file
27
pythonrewrite/plugins/partition/select_device.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?cs # $Id$ ?>
|
||||
|
||||
<h1><?cs var:html_escape(Lang.Plugins.partition.Title.Partition) ?></h1>
|
||||
|
||||
<?cs if:subcount(Data.Plugins.partition.BlockDevices) > 0 ?>
|
||||
|
||||
<?cs call:print_form_header("plugins/partition") ?>
|
||||
|
||||
<p><label for="block_device"><?cs var:html_escape(Lang.Plugins.partition.Text.SelectDevice) ?>: </label><br/>
|
||||
<select name="block_device" id="block_device" size="0">
|
||||
<?cs each:x = Data.Plugins.partition.BlockDevices
|
||||
?><option><?cs var:html_escape(x) ?></option>
|
||||
<?cs /each ?>
|
||||
</select></p>
|
||||
|
||||
<input type="hidden" name="step" value="add_partition" />
|
||||
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.partition.Button.SelectDevice) ?></button>
|
||||
|
||||
</form>
|
||||
|
||||
<?cs else ?>
|
||||
|
||||
<p><?cs var:html_escape(Lang.Plugins.partition.Text.NoDevicesAvailable) ?></p>
|
||||
|
||||
<?cs /if ?>
|
||||
|
37
pythonrewrite/plugins/partition/set_partitions.cs
Normal file
37
pythonrewrite/plugins/partition/set_partitions.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?cs # $Id$ ?>
|
||||
|
||||
<h1><?cs var:html_escape(Lang.Plugins.partition.Title.Partition) ?></h1>
|
||||
|
||||
<p> <?cs loop: x = #0, subcount(Data.Plugins.partition.Parts)-1, #1 ?>
|
||||
<p><?cs var:x ?> - <?cs var:Data.Plugins.partition.Parts[x].Size ?> - <?cs var:Data.Plugins.partition.Parts[x].Type ?></p><?cs
|
||||
/loop ?></p>
|
||||
|
||||
<?cs if:Data.Plugins.partition.availSize ?>
|
||||
<?cs call:print_form_header("plugins/partition") ?>
|
||||
<?cs include:Settings.PluginDir + "/partition/current_partition_info.cs" ?><?cs
|
||||
|
||||
# new partition input if space is available ?><?cs
|
||||
set: x = subcount(Data.Plugins.partition.Parts) ?>
|
||||
<p><?cs var:x ?> - <input type="text" name="part<?cs var:x ?>_size" value="<?cs var:Data.Plugins.partition.availSize ?>" /> - <select name="part<?cs var:x ?>_type" size="0"><?cs each: t = Data.Plugins.partition.Types ?><option><?cs var:t ?></option><?cs /each ?></select></p>
|
||||
|
||||
<input type="hidden" name="step" value="add_partition" />
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.partition.Button.AddPartition) ?></button>
|
||||
</form>
|
||||
<?cs /if ?>
|
||||
|
||||
<?cs if:subcount(Data.Plugins.partition.Parts) > 0 ?>
|
||||
<?cs call:print_form_header("plugins/partition") ?>
|
||||
<?cs include:Settings.PluginDir + "/partition/current_partition_info.cs" ?>
|
||||
<input type="hidden" name="step" value="del_partition" />
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.partition.Button.Back) ?></button>
|
||||
</form>
|
||||
<?cs /if ?>
|
||||
|
||||
<?cs if:subcount(Data.Plugins.partition.Parts) > 0 ?>
|
||||
<?cs call:print_form_header("plugins/partition") ?>
|
||||
<?cs include:Settings.PluginDir + "/partition/current_partition_info.cs" ?>
|
||||
<input type="hidden" name="step" value="finish" />
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.partition.Button.SavePartitions) ?></button>
|
||||
</form>
|
||||
<?cs /if ?>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue