i writing small script lists connected hard disks on machine. need disk identifier(disk0), not partition id(disk0s1, disk0s2, etc.) how can iterate through array contains diskid , partitionid , remove partitionid entries? here's i'm trying far:
import os alldrives = os.listdir("/dev/") parseddrives = [] def parsealldrives(): parseddrives = [] matching = [] drivename in alldrives: if 'disk' in drivename: parseddrives.append(drivename) else: continue itemname in parseddrives: if len(parseddrives) != 0: if 'rdisk' in itemname: parseddrives.remove(itemname) else: continue else: continue #### problem starts: ##### # iterate through possible partition identifiers in range(5): #create string partitionid systempostfix = 's' + str(i) matching.append(filter(lambda x: systempostfix in x, parseddrives)) match in matching: if match in parseddrives: parseddrives.remove(match) print("found mactch , removed it") print("matched: %s" % matching) print(parseddrives) parsealldrives()
that last bit recent thing i've tried. open going different route.
try beginning with
alldrives = os.listdir("/dev/") disks = [drive drive in alldrives if ('disk' in drive)]
then, given disks id's 5-chars length
short_disks = [disk[:6] disk in disks] unique_short_disks = list(set(short_disks))
Comments
Post a Comment