当前位置: 首页>>代码示例>>Python>>正文


Python GLIUtility.is_file方法代码示例

本文整理汇总了Python中GLIUtility.is_file方法的典型用法代码示例。如果您正苦于以下问题:Python GLIUtility.is_file方法的具体用法?Python GLIUtility.is_file怎么用?Python GLIUtility.is_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GLIUtility的用法示例。


在下文中一共展示了GLIUtility.is_file方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_best_version_vdb_chroot

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import is_file [as 别名]
	def get_best_version_vdb_chroot(self, package):
		if package.startswith('='):
			package = package[1:]
			if GLIUtility.is_file(self._chroot_dir + "/var/db/pkg/" + package):
				return package
			else:
				return ""
		else:
			return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip()
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:11,代码来源:GLIPortage.py

示例2: _partition_resize_step

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import is_file [as 别名]
	def _partition_resize_step(self, parted_disk, device, oldparts, newparts):
		for oldpart in oldparts:
			tmppart_old = oldparts[oldpart]
			devnode = tmppart_old['devnode']
			newminor = self._find_existing_in_new(oldpart, newparts)
			if not newminor or not newparts[newminor]['resized']:
				continue
			tmppart_new = newparts[newminor]
			type = tmppart_new['type']
			start = tmppart_new['start']
			end = start + (long(tmppart['mb']) * MEGABYTE / 512) - 1
			total_sectors = end - start + 1
			total_bytes = long(total_sectors) * 512
			# Make sure calculated end sector doesn't overlap start sector of next partition
			nextminor = self._find_next_partition(newminor, newparts)
			if nextminor:
				if newparts[nextminor]['start'] and end >= newparts[nextminor]['start']:
					self._logger.log("  End sector for growing partition overlaps with start of next partition...fixing")
					end = newparts[nextminor]['start'] - 1
			# sleep a bit first
			time.sleep(3)
			# now sleep until it exists
			while not GLIUtility.is_file(device + str(minor)):
				self._logger.log("Waiting for device node " + devnode + " to exist before resizing")
				time.sleep(1)
			# one bit of extra sleep is needed, as there is a blip still
			time.sleep(3)
			if type in ("ext2", "ext3"):
				ret = GLIUtility.spawn("resize2fs " + devnode + " " + str(total_sectors) + "s", logfile=self._compile_logfile, append_log=True)
				if not GLIUtility.exitsuccess(ret): # Resize error
					raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize ext2/3 filesystem on " + devnode)
			elif type == "ntfs":
				ret = GLIUtility.spawn("yes | ntfsresize -v --size " + str(total_bytes) + " " + devnode, logfile=self._compile_logfile, append_log=True)
				if not GLIUtility.exitsuccess(ret): # Resize error
					raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize NTFS filesystem on " + devnode)
			elif type in ("linux-swap", "fat32", "fat16"):
				parted_fs = parted_disk.get_partition(part).geom.file_system_open()
				resize_constraint = parted_fs.get_resize_constraint()
				if total_sectors < resize_constraint.min_size or start != resize_constraint.start_range.start:
					raise GLIException("PartitionError", 'fatal', 'partition', "New size specified for " + device + str(minor) + " is not within allowed boundaries (blame parted)")
				new_geom = resize_constraint.start_range.duplicate()
				new_geom.set_start(start)
				new_geom.set_end(end)
				try:
					parted_fs.resize(new_geom)
				except:
					raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize " + device + str(minor))
			self._logger.log("  Deleting old minor " + str(oldpart) + " to be recreated in 3rd pass")
			self._delete_partition(parted_disk, oldpart)
		parted_disk.delete_all()
		parted_disk.commit()
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:53,代码来源:x86ArchitectureTemplate.py

示例3: _map_device_to_grub_device

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import is_file [as 别名]
	def _map_device_to_grub_device(self, device):
		file_name = self._chroot_dir + "/boot/grub/glidevice.map"
		#If we can't find it, make it.  If we STILL can't find it. die.
		if not GLIUtility.is_file(file_name):
			exitstatus1 = GLIUtility.spawn("echo quit | "+ self._chroot_dir+"/sbin/grub --batch --no-floppy --device-map="+file_name, logfile=self._compile_logfile, append_log=True)
		if not GLIUtility.is_file(file_name):
			raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error making the new device map.")
		"""
		read the device map.  sample looks like this:
		(fd0)   /dev/floppy/0
		(hd0)   /dev/sda
		(hd1)   /dev/hda
		(hd2)   /dev/hdb
		"""
		
		# Search for the key
		f = open(file_name)  #open the device map
		file = f.readlines()
		f.close()	
		for i in range(len(file)):
			if file[i][6:-1] == device:
				return file[i][1:4]
		raise GLIException("BootloaderError", 'fatal', '_map_device_to_grub_device', "ERROR, could not map"+device+" to anything in the device map")
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:25,代码来源:x86ArchitectureTemplate.py

示例4: copy_pkg_to_chroot

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import is_file [as 别名]
	def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False):
		symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/', 
		             '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/',
		             '/etc/gconf': '/usr/livecd/gconf/' }

		tmpdir = "/var/tmp/portage"
		image_dir = tmpdir + "/" + package.split("/")[1] + "/image"
		root_cmd = ""
		tmp_chroot_dir = self._chroot_dir
		portage_tmpdir = "/var/tmp/portage"
		vdb_dir = "/var/db/pkg/"
		if use_root:
			root_cmd = "ROOT=" + self._chroot_dir
			tmp_chroot_dir = ""
			portage_tmpdir = self._chroot_dir + "/var/tmp/portage"
			vdb_dir = self._chroot_dir + "/var/db/pkg/"

		# Create /tmp, /var/tmp, and /var/lib/portage with proper permissions
		oldumask = os.umask(0)
		if not os.path.exists(self._chroot_dir + "/tmp"):
			if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /tmp doesn't exist in chroot...creating with proper permissions")
			try:
				os.mkdir(self._chroot_dir + "/tmp", 01777)
			except:
				raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /tmp in chroot")
		if not os.path.exists(self._chroot_dir + "/var/tmp"):
			if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/tmp doesn't exist in chroot...creating with proper permissions")
			try:
				os.mkdir(self._chroot_dir + "/var", 0755)
			except:
				pass
			try:
				os.mkdir(self._chroot_dir + "/var/tmp", 01777)
			except:
				raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/tmp in chroot")
		if not os.path.exists(self._chroot_dir + "/var/lib/portage"):
			if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/lib/portage doesn't exist in chroot...creating with proper permissions")
			try:
				os.mkdir(self._chroot_dir + "/var/lib", 0755)
			except:
				pass
			try:
				os.mkdir(self._chroot_dir + "/var/lib/portage", 02750)
			except:
				raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/lib/portage in chroot")
		os.umask(oldumask)

		# Check to see if package is actually in vdb
		if not GLIUtility.is_file("/var/db/pkg/" + package):
			if ignore_missing:
				if self._debug:
					self._logger.log("DEBUG: copy_pkg_to_chroot(): package " + package + " does not have a vdb entry but ignore_missing=True...ignoring error")
				return
			else:
				raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)

		# Copy the vdb entry for the package from the LiveCD to the chroot
		if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package)
		if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + "/var/db/pkg/" + package + " && cp -a /var/db/pkg/" + package + "/* " + self._chroot_dir + "/var/db/pkg/" + package, logfile=self._compile_logfile, append_log=True)):
			raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)

		# Create the image dir in the chroot
		if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'")
		if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
			raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)

		# Create list of files for tar to work with from CONTENTS file in vdb entry
		entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
		if not entries:
			if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup")
		else:
#			if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
			try:
				tarfiles = open("/tmp/tarfilelist", "w")
				for entry in entries:
					parts = entry.split(" ")
#					# Hack for symlink crappiness
#					for symlink in symlinks:
#						if parts[0].startswith(symlink):
#							parts[0] = symlinks[symlink] + parts[0][len(symlink):]
					tarfiles.write(parts[0] + "\n")
				tarfiles.close()
			except:
				raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)

			# Use tar to transfer files into IMAGE directory
			if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp'")
			if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp", logfile=self._compile_logfile, append_log=True)):
				raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)

			# Fix mode, uid, and gid of directories
#			if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running find " + self._chroot_dir + image_dir + " -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'")
#			dirlist = GLIUtility.spawn("find " + self._chroot_dir + image_dir + " -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'", return_output=True)[1].strip().split("\n")
#			if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): found the following directories: " + str(dirlist))
#			if not dirlist or dirlist[0] == "":
#				raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!")
#			for dir in dirlist:
#				dirstat = os.stat(dir)
#				if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): setting mode " + str(dirstat[0]) + " and uid/gid " + str(dirstat[4]) + "/" + str(dirstat[5]) + " for directory " + self._chroot_dir + image_dir + dir)
#				os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5])
#.........这里部分代码省略.........
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:103,代码来源:GLIPortage.py

示例5: usage

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import is_file [as 别名]
		elif arg == "-g" or arg == "--grp":
			mode = "grp"
		elif arg == "-s" or arg == "--stage3":
			mode = "stage3"
		elif arg == "-h" or arg == "--help":
			usage(progname)
			sys.exit(0)
		elif arg[0] == "-":
			usage(progname)
			sys.exit(1)
		else:
			grp_packages.append(arg)

	gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
	if mode == "stage3":
		if not GLIUtility.is_file("/usr/livecd/systempkgs.txt"):
			print "Required file /usr/livecd/systempkgs.txt does not exist!"
			sys.exit(1)
		try:
			syspkgs = open("/usr/livecd/systempkgs.txt", "r")
			systempkgs = syspkgs.readlines()
			syspkgs.close()
		except:
			print "Could not open /usr/livecd/systempkgs.txt!"
			sys.exit(1)

		# Pre-create /lib (and possible /lib32 and /lib64)
		if os.path.islink("/lib") and os.readlink("/lib") == "lib64":
			if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")):
				print "Could not precreate /lib64 dir and /lib -> /lib64 symlink"
				sys.exit(1)
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:33,代码来源:GLIPortage.py

示例6: detect_devices

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import is_file [as 别名]
def detect_devices():
	devices = []
	
	# Make sure sysfs exists
	# TODO: rewrite for 2.4 support
	if not os.path.exists("/sys/bus"):
		raise GLIException("GLIStorageDeviceError", 'fatal', 'detect_devices', "no sysfs found (you MUST use a kernel >2.6)")
	# Make sure /proc/partitions exists
	if not os.path.exists("/proc/partitions"):
		raise GLIException("GLIStorageDeviceError", 'fatal', 'detect_devices', "/proc/partitions does not exist! Please make sure procfs is in your kernel and mounted!")
	
	# Load /proc/partitions into the variable 'partitions'
	partitions = []
	for line in open("/proc/partitions"):
		tmpparts = line.split()
		if len(tmpparts) < 4 or not tmpparts[0].isdigit() or not tmpparts[1].isdigit():
			continue
		
		# Get the major, minor and device name
		major = int(tmpparts[0])
		minor = int(tmpparts[1])
		device = "/dev/" + tmpparts[3]
		
		# If there is no /dev/'device_name', then scan
		# all the devices in /dev to try and find a
		# devices with the same major and minor		
		if not os.path.exists(device):
			device = None
			for path, dirs, files in os.walk("/dev"):
				for d_file in files:
					full_file = os.path.join(path, d_file)
					if not os.path.exists(full_file):
						continue
					statres = os.stat(full_file)
					fmaj = os.major(statres.st_rdev)
					fmin = os.minor(statres.st_rdev)
					if fmaj == major and fmin == minor:
						device = full_file
						break
			if not device:
				continue
			
		partitions.append(( major, minor, device ))
	
	# Scan sysfs for the devices of type 'x'
	# 'x' being a member of the list below:
	# Compaq cards.../sys/block/{cciss,ida}!cXdX/dev
	for dev_glob in ("/sys/bus/ide/devices/*/block*/dev", "/sys/bus/scsi/devices/*/block*/dev", "/sys/block/cciss*/dev", "/sys/block/ida*/dev"):
		sysfs_devices = glob(dev_glob)
		if not sysfs_devices: continue
		for sysfs_device in sysfs_devices:
			# Get the major and minor info
			try:
				major, minor = open(sysfs_device).read().split(":")
				major = int(major)
				minor = int(minor)
			except:
				raise GLIException("GLIStorageDeviceError", 'fatal', 'detect_devices', "invalid major/minor in " + sysfs_device)
			
			# Find a device listed in /proc/partitions
			# that has the same minor and major as our
			# current block device.
			for record in partitions:
				if major == record[0] and minor == record[1]:
					devices.append(record[2])

	# For testing the partitioning code
	if GLIUtility.is_file("/tmp/disk.img"):
		devices.append("/tmp/disk.img")

	# We have assembled the list of devices, so return it
	return devices
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:74,代码来源:GLIStorageDevice.py

示例7: not_working

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import is_file [as 别名]
	print "\tset_users              set up the users"
	print "\tetc_portage            set up the files in /etc/portage"
	print "\tinstall_packages       install required packages"
	print "\tunmount                unmount all filesystems"

def not_working():
	print "This is a placeholder. This function does nothing right now."

if len(sys.argv) < 3:
	usage()
	sys.exit(1)

progname = sys.argv.pop(0)
xmlfile = sys.argv.pop(0)

if not GLIUtility.is_file(xmlfile):
	print "The XML file '" + xmlfile + "' cannot be accessed.\n"
	usage()
	sys.exit(1)

client_profile = GLIClientConfiguration.ClientConfiguration()
client_profile.set_root_mount_point(None, "/mnt/gentoo", None)
install_profile = GLIInstallProfile.InstallProfile()
install_profile.parse(xmlfile)

template =  __import__('templates' + '/' + 'x86ArchitectureTemplate')
archtemplate = getattr(template, 'x86ArchitectureTemplate')(client_profile, install_profile, False)

#archtemplate = GLIArchitectureTemplate.ArchitectureTemplate(install_profile=install_profile)

operations = {
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:33,代码来源:install.py

示例8: __init__

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import is_file [as 别名]
	def __init__(self, controller):
		GLIScreen.GLIScreen.__init__(self, controller)

		self.has_systempkgs = GLIUtility.is_file("/usr/livecd/systempkgs.txt")

		vert = gtk.VBox(False, 0)
		vert.set_border_width(10)

		content_str = """Here, you will select which stage you would like to start your install from.
Each option has a brief description beside it.
"""
		content_label = gtk.Label(content_str)
		vert.pack_start(content_label, expand=False, fill=False, padding=0)            
		self.radio_stages[1] = gtk.RadioButton(None, "Stage 1")
		self.radio_stages[1].set_name("1")
		self.radio_stages[1].connect("toggled", self.stage_selected, "1")
		self.radio_stages[1].set_size_request(100, -1)
		hbox = gtk.HBox(False, 0)
		hbox.pack_start(self.radio_stages[1], expand=False, fill=False, padding=5)
		tmplabel = gtk.Label("The entire system will be compiled from scratch with your CHOST and CFLAGS settings")
		tmplabel.set_line_wrap(True)
		hbox.pack_start(tmplabel, expand=False, fill=False, padding=20)
		vert.pack_start(hbox, expand=False, fill=False, padding=10)
		self.radio_stages[2] = gtk.RadioButton(self.radio_stages[1], "Stage 2")
		self.radio_stages[2].set_name("2")
		self.radio_stages[2].connect("toggled", self.stage_selected, "2")
		self.radio_stages[2].set_size_request(100, -1)
		hbox = gtk.HBox(False, 0)
		hbox.pack_start(self.radio_stages[2], expand=False, fill=False, padding=5)
		tmplabel = gtk.Label("Most of the system will be compiled with your CHOST and CFLAGS settings. Don't use this option unless you have a good reason")
		tmplabel.set_line_wrap(True)
		hbox.pack_start(tmplabel, expand=False, fill=False, padding=20)
		vert.pack_start(hbox, expand=False, fill=False, padding=10)

		self.radio_stages[3] = gtk.RadioButton(self.radio_stages[1], "Stage 3")
		self.radio_stages[3].set_name("3")
		self.radio_stages[3].connect("toggled", self.stage_selected, "3")
		self.radio_stages[3].set_size_request(100, -1)
		hbox = gtk.HBox(False, 0)
		hbox.pack_start(self.radio_stages[3], expand=False, fill=False, padding=5)
		tmplabel = gtk.Label("The base system will be installed using precompiled packages. You can recompile later with your custom settings if you choose. This is the fastest option")
		tmplabel.set_line_wrap(True)
		hbox.pack_start(tmplabel, expand=False, fill=False, padding=20)
		vert.pack_start(hbox, expand=False, fill=False, padding=10)

		self.check_grp = gtk.CheckButton("GRP Install")
		self.check_grp.set_sensitive(False)
		self.check_grp.set_size_request(100, -1)
		hbox = gtk.HBox(False, 0)
		hbox.pack_start(self.check_grp, expand=False, fill=False, padding=5)
		tmplabel = gtk.Label("Any extra packages installed (beyond the stage3) will be installed using binaries from the LiveCD that you are installing from")
		tmplabel.set_line_wrap(True)
		hbox.pack_start(tmplabel, expand=False, fill=False, padding=20)
		vert.pack_start(hbox, expand=False, fill=False, padding=10)

		self.check_dynamic = gtk.CheckButton("Dynamic")
		self.check_dynamic.set_sensitive(False)
		self.check_dynamic.connect("toggled", self.dynamic_checked)
		self.check_dynamic.set_size_request(100, -1)
		if not self.has_systempkgs:
			self.check_dynamic.set_sensitive(False)
		hbox = gtk.HBox(False, 0)
		hbox.pack_start(self.check_dynamic, expand=False, fill=False, padding=5)
		tmplabel = gtk.Label("The stage3 will be generated from the packages on the LiveCD")
		tmplabel.set_line_wrap(True)
		hbox.pack_start(tmplabel, expand=False, fill=False, padding=20)
		vert.pack_start(hbox, expand=False, fill=False, padding=10)

		hbox = gtk.HBox(False, 0)
		hbox.pack_start(gtk.Label("Stage tarball URI:"), expand=False, fill=False, padding=5)
		self.entry_stage_tarball_uri = gtk.Entry()
		self.entry_stage_tarball_uri.set_width_chars(50)
		hbox.pack_start(self.entry_stage_tarball_uri, expand=False, fill=False, padding=10)
		self.browse_uri = gtk.Button(" ... ")
		self.browse_uri.connect("clicked", self.browse_uri_clicked)
		hbox.pack_start(self.browse_uri, expand=False, fill=False, padding=5)
		vert.pack_end(hbox, expand=False, fill=False, padding=0)

		self.add_content(vert)
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:81,代码来源:Stage.py


注:本文中的GLIUtility.is_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。