Fix bug of change partition id on device which has one partition.

netsetup
Mike Hiretsky 14 years ago
parent 07d40c7ddd
commit 3bd8e2838c

Binary file not shown.

@ -881,6 +881,7 @@ class PartitionDistributive(Distributive):
def changeSystemID(self,dev,systemid):
parentDir = path.split(dev)[0]
reDeviceSplit = re.compile("^(.*/)?(.*?)(\d+)$")
def detectDeviceForPartition(dev):
"""Detect parent device for partition by /sys/block (sysfs)"""
device = map(lambda x:filter(lambda x:x in dev,
@ -894,12 +895,27 @@ class PartitionDistributive(Distributive):
os.walk(path.join('/sys/block',x)),[]), device)
if parentdevices:
return parentdevices[0]
return dev[:-1]
res = reDeviceSplit.search(dev)
if res:
return res.groups()[1]
raise DistributiveError(_("Can not determine parent device for %s")%dev)
deviceName = detectDeviceForPartition(dev)
pipe = Popen(["/sbin/fdisk",
path.join('/dev',detectDeviceForPartition(dev))],
path.join('/dev',deviceName)],
stdin=PIPE, stdout=PIPE,stderr=PIPE)
pipe.stdin.write("t\n%s\n%s\nw\n"%(dev[-1],systemid))
if len(filter(lambda x: deviceName in x and deviceName != x,
os.listdir('/dev'))) > 1:
numPart = reDeviceSplit.search(dev)
if numPart:
numPart = numPart.groups()[-1]
else:
pipe.stdin.close()
raise DistributiveError(
_("Can not determine partition number for %s")%dev)
pipe.stdin.write("t\n%s\n%s\nw\n"%(numPart,systemid))
else:
pipe.stdin.write("t\n%s\nw\n"%systemid)
pipe.stdin.close()
pipe.wait()

Loading…
Cancel
Save