Re: python (parted) question

2003-09-08 Thread Paul Telford

[ Please CC replies, I'm not subscribed to either list ]
[ d-python: this is a restatement of my previous question. Hope its ]
[ clearer this time. ]

I posed this question several days ago and received no response.  mdz
(correctly) nudged me with a cluestick by telling me that perhaps I should
be more specific in describing my problem.  So here goes... I'm no python
hacker, so maybe I'm missing something obvious.

I have attached part of a script (python_parted).  It is intended to
partition a disk drive.  I have edited out much of the script before and
after the problem section (such as reading in config files, etc) so that
the size is manageable, if you want the complete script refer to the
'autoinstall' package in Debian unstable.  (I believe the included section
completely describes the problem.)  I have also attached the partition.py
module which is loaded by this script.  All other modules should be
standard... available from either the python or python-parted packages 
in
Debian unstable.

My problem occurs at line 101 of python_parted, that reads:
drvnewpart = drvdisk.get_partition(drvpartnum)

The get_partition function is defined by the parted module, and always
returns 'None' when I call it.  I have stepped through line-by-line and
every other value appears to be correct up to that point.

get_partition is as follows:

def get_partition(self, num):
"""Returns the partition numbered num.
"""

r = _parted.disk_get_partition(self._o, num)
if r:
return Partition(self, None, None, None, None, r)
else:
return None



and the corresponding C call which accesses libparted:

static PyObject *
disk_get_partition(PyObject *self, PyObject *args)
{
PyPartedObject *o;
int num;

if (!PyArg_ParseTuple(args, "Oi", &o, &num))
return NULL;

return PyPartedObject_new("PedPartition",
  ped_disk_get_partition((PedDisk *)o->obj,
 num));
}



This same code worked with libparted1.4, and broke at the 1.6 upgrade.  
I'm not sure if the problem is in libparted, python-parted, or user-error.  
I'm perfectly willing to accept the latter, but I hope to find a solution 
anyway.  :)

Is anyone else out there even using python-parted?  There doesn't seem to 
be much info about it...


Thanks,


--
Paul Telford | 1024D/431B38BA | [EMAIL PROTECTED] | [EMAIL PROTECTED]
   C903 0E85 9AF5 1B80 6A5F  F169 D7E9 4363 431B 38BA





#!/usr/bin/python -i

import sys
import os
import popen2
import stat
import traceback
import signal
import string
import time
import copy
import parted

# Arch-specific modules
import partition

try:

drvlist = []
parted.init()
parted.device_probe_all()

print "Examining drives..."
try:
   drvinstlist = [parted.get_devices()[0]]
except:
   print "No available drives found!"
   killsystem()

bootdrv = ""

for drv in drvinstlist:
if not bootdrv:
bootdrv = drv.get_path()

drvdisk = drv.disk_open()
if drvdisk is not None:
partlist = drvdisk.get_part_list()
isdata = 0
for part in partlist:
if part.get_type() != parted.PARTITION_FREESPACE:
isdata = 1

drvdisk.close()

# Partition and format drive.
for drv in drvinstlist:
print "Partitioning drive %s..." % drv.get_path()

drvobj = partition.Partition(drv)
drvsectors = drv.get_length()
drvobj.create_partition_table()

partabssect = 0
# for reference, partcfg at this point looks like:
# [['ext2', '80%', '/', ['primary']], ['swap', '256M', 'swap', 
['primary']]]
for partinfo in partcfg:
if partinfo[2] == "/":
rootpart = partinfo
partsizetype = string.upper(partinfo[1][-1])
if partsizetype == "M":
partsize = string.atoi(partinfo[1][:-1])
partsect = int(float(partsize) * 1024 * 1024 / 
parted.SECTOR_SIZE)
partabssect = partabssect + partsect
elif partsizetype != "%":
raise RuntimeError, "invalid partition size specifier"
partremsect = drvsectors - partabssect - curpartend

for (partfs, partsizestr, partmount, parthints) in partcfg:
print "Creating %s partition for %s..." % (partfs, partmount)
partsizetype = string.upper(partsizestr[-1])
partsize = string.atoi(partsizestr[:-1])

if partfs == "swap":
partfs = "linux-swap"
partfstype = parted.file_system_type_get(partfs)

if partsizetype == "%":

Re: python (parted) question

2003-09-08 Thread Andrew Clausen
On Mon, Sep 08, 2003 at 03:40:47PM -0700, Paul Telford wrote:
> I posed this question several days ago and received no response.  mdz
> (correctly) nudged me with a cluestick by telling me that perhaps I should
> be more specific in describing my problem.  So here goes... I'm no python
> hacker, so maybe I'm missing something obvious.

I never received your email.

> This same code worked with libparted1.4, and broke at the 1.6 upgrade.  
> I'm not sure if the problem is in libparted, python-parted, or user-error.  
> I'm perfectly willing to accept the latter, but I hope to find a solution 
> anyway.  :)

1.6 is not compatible with 1.4.  Where did you get python-parted for
libparted 1.6?

The names of the PedDisk constructor changed, to reflect changes in the
semantics.

Cheers,
Andrew