Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)
retrieve a list of all available containers

        def get_available_partitions():
	"retrieve a list of all available containers"
	ret_list = []
	try:
		## the following reads all lines of /proc/partitions and adds the mentioned devices
		fpart = open("/proc/partitions", "r")
		try:
			line = fpart.readline()
			while line:
				p_details = line.split()
				if (len(p_details) == 4):
					## the following code prevents double entries like /dev/hda and /dev/hda1
					(p_major, p_minor, p_size, p_device) = p_details
					## ignore lines with: invalid minor/major or extend partitions (size=1)
					if  re.search('^[0-9]*$', p_major) and \
							re.search('^[0-9]*$', p_minor) and (p_size != "1"):
						## for some parent devices we have to remove a 'p' (partition)
						## an example are partitionable mdadm raid devices (e.g. md1p1)
						p_parent = re.sub('p?[1-9]?[0-9]$', '', p_device)
						if p_parent == p_device:
							if [e for e in ret_list
									if re.search('^' + p_parent + 'p?[1-9]?[0-9]$', e)]:
								## major partition - its children are already in the list
								pass
							else:
								## major partition - but there are no children for now
								ret_list.append(p_device)
						else:
							## minor partition - remove parent if necessary
							if p_parent in ret_list:
								ret_list.remove(p_parent)
							ret_list.append(p_device)
				line = fpart.readline()
		finally:
			fpart.close()
		return [ get_absolute_devicename(e) for e in ret_list ]
	except IOError:
		LOGGER.warning("Could not read /proc/partitions")
		return []
        


src/c/r/cryptobox-server-0.3.0/src/cryptobox/core/main.py   cryptobox-server(Download)
		self.log.debug("rereading container list")
		self.__containers = []
		for device in cbxTools.get_available_partitions():
			if self.is_device_allowed(device) and not self.is_config_partition(device):
				self.__containers.append(cbxContainer.CryptoBoxContainer(device, self))