本文整理汇总了Python中GLIUtility类的典型用法代码示例。如果您正苦于以下问题:Python GLIUtility类的具体用法?Python GLIUtility怎么用?Python GLIUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GLIUtility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _partition_format_step
def _partition_format_step(self, parted_disk, device, newparts):
for part in newparts:
newpart = newparts[part]
devnode = newpart['devnode']
# This little hack is necessary because parted sucks goat nuts
if newparts.get_disklabel() == "mac" and newpart['type'] == "free":
self._delete_partition(parted_disk, newpart)
continue
if newpart['format'] and newpart['type'] not in ('extended', 'free'):
# devnode = device + str(int(part))
if self._debug: self._logger.log("_partition_format_step(): devnode is %s in formatting code" % devnode)
# if you need a special command and
# some base options, place it here.
format_cmds = { 'linux-swap': "mkswap", 'fat16': "mkfs.vfat -F 16", 'fat32': "mkfs.vfat -F 32",
'ntfs': "mkntfs", 'xfs': "mkfs.xfs -f", 'jfs': "mkfs.jfs -f",
'reiserfs': "mkfs.reiserfs -f", 'ext2': "mkfs.ext2", 'ext3': "mkfs.ext3"
}
if newpart['type'] in format_cmds:
cmdname = format_cmds[newpart['type']]
else: # this should catch everything else
raise GLIException("PartitionFormatError", 'fatal', '_partition_format_step', "Unknown partition type " + newpart['type'])
# sleep a bit first
time.sleep(1)
for tries in range(10):
cmd = "%s %s %s" % (cmdname, newpart['mkfsopts'], devnode)
self._logger.log(" Formatting partition %s as %s with: %s" % (str(part),newpart['type'],cmd))
ret = GLIUtility.spawn(cmd, logfile=self._compile_logfile, append_log=True)
if not GLIUtility.exitsuccess(ret):
self._logger.log("Try %d failed formatting partition %s...waiting 5 seconds" % (tries+1, devnode))
time.sleep(5)
else:
break
else:
raise GLIException("PartitionFormatError", 'fatal', '_partition_format_step', "Could not create %s filesystem on %s" % (newpart['type'], devnode))
示例2: host_browse_clicked
def host_browse_clicked(self, button):
hostdlg = gtk.Dialog("Browse mirror list", self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
hbox = gtk.HBox(False)
hbox.set_border_width(10)
hbox.pack_start(gtk.Label("Mirror:"), expand=False, fill=False, padding=0)
host_combo = gtk.combo_box_new_text()
if self.uritypes[self.uritype.get_active()] == "http":
mirrors = GLIUtility.list_mirrors(http=True, ftp=False, rsync=False)
elif self.uritypes[self.uritype.get_active()] == "ftp":
mirrors = GLIUtility.list_mirrors(http=False, ftp=True, rsync=False)
else:
msgdlg = gtk.MessageDialog(parent=self, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=_("There are no known mirrors for this URI type."))
msgdlg.run()
msgdlg.destroy()
return
for mirror in mirrors:
host_combo.append_text(mirror[1])
host_combo.set_active(0)
hbox.pack_start(host_combo, expand=False, fill=True, padding=15)
hbox.show_all()
hostdlg.vbox.pack_start(hbox)
resp = hostdlg.run()
if resp == gtk.RESPONSE_ACCEPT:
mirror = mirrors[host_combo.get_active()][0]
if not mirror.endswith("/"):
mirror += "/"
self.uri = mirror
self.update_from_uri()
hostdlg.destroy()
示例3: activate
def activate(self):
self.controller.SHOW_BUTTON_EXIT = True
self.controller.SHOW_BUTTON_HELP = True
self.controller.SHOW_BUTTON_BACK = True
self.controller.SHOW_BUTTON_FORWARD = True
self.controller.SHOW_BUTTON_FINISH = False
if self.controller.install_profile.get_dynamic_stage3():
self.entry_portage_snapshot_uri.set_text(GLIUtility.get_cd_snapshot_uri())
self.radio_syncs["snapshot"].set_active(True)
self.active_selection = "snapshot"
for radio in self.radio_syncs:
self.radio_syncs[radio].set_sensitive(False)
self.entry_portage_snapshot_uri.set_sensitive(False)
self.browse_uri.set_sensitive(False)
else:
for radio in self.radio_syncs:
self.radio_syncs[radio].set_sensitive(True)
self.entry_portage_snapshot_uri.set_sensitive(True)
self.browse_uri.set_sensitive(True)
self.active_selection = self.controller.install_profile.get_portage_tree_sync_type() or "sync"
self.radio_syncs[self.active_selection].set_active(True)
self.stage_selected(self.radio_syncs[self.active_selection], self.active_selection)
self.entry_portage_snapshot_uri.set_text(self.controller.install_profile.get_portage_tree_snapshot_uri())
if not self.entry_portage_snapshot_uri.get_text():
self.entry_portage_snapshot_uri.set_text(GLIUtility.get_cd_snapshot_uri())
示例4: get_deps
def get_deps(self, pkgs):
pkglist = []
if isinstance(pkgs, str):
pkgs = pkgs.split()
for pkg in pkgs:
if not pkg: continue
if self._debug: self._logger.log("get_deps(): pkg is " + pkg)
if not self._grp_install or not self.get_best_version_vdb(pkg):
if self._debug: self._logger.log("get_deps(): grabbing compile deps")
tmppkglist = GLIUtility.spawn("emerge -p " + pkg + r" 2>/dev/null | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].strip().split("\n")
else:
if self._debug: self._logger.log("get_deps(): grabbing binary deps")
# The runtimedeps.py script generates a package install order that is *very* different from emerge itself
# tmppkglist = GLIUtility.spawn("python ../../runtimedeps.py " + self._chroot_dir + " " + pkg, return_output=True)[1].strip().split("\n")
tmppkglist = []
for tmppkg in GLIUtility.spawn("emerge -p " + pkg + r" 2>/dev/null | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].strip().split("\n"):
if self._debug: self._logger.log("get_deps(): looking at " + tmppkg)
if self.get_best_version_vdb("=" + tmppkg):
if self._debug: self._logger.log("get_deps(): package " + tmppkg + " in host vdb...adding to tmppkglist")
tmppkglist.append(tmppkg)
if self._debug: self._logger.log("get_deps(): deplist for " + pkg + ": " + str(tmppkglist))
for tmppkg in tmppkglist:
if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist")
if not tmppkg in pkglist and not self.get_best_version_vdb_chroot("=" + tmppkg):
if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist")
pkglist.append(tmppkg)
if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist))
return pkglist
示例5: add_pkg_to_world
def add_pkg_to_world(self, package):
if package.find("/") == -1:
package = self.get_best_version_vdb_chroot(package)
if not package: return False
expr = re.compile('^=?(.+?/.+?)(-\d.+)?$')
res = expr.match(package)
if res:
GLIUtility.spawn("echo " + res.group(1) + " >> " + self._chroot_dir + "/var/lib/portage/world")
示例6: start_portmap
def start_portmap(self):
if self._configuration.get_verbose(): self._logger.log("DEBUG: beginning of start_portmap()")
status = GLIUtility.spawn('/etc/init.d/portmap start') #, display_on_tty8=True)
if not GLIUtility.exitsuccess(status):
self._logger.log("ERROR! : Could not start the portmap service!")
# raise GLIException("PortmapError", 'warning', 'start_portmap', "Could not start the portmap service!")
else:
self._logger.log("Portmap started.")
示例7: _configure_lilo
def _configure_lilo(self):
self.build_mode = self._install_profile.get_kernel_build_method()
self._gather_lilo_drive_info()
root = self._chroot_dir
file_name3 = root + "/boot/kernel_name"
root = self._chroot_dir
exitstatus0 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name3)
if (exitstatus0 != 0):
raise GLIException("BootloaderError", 'fatal', '_configure_lilo', "Could not list kernels in /boot or no kernels found.")
if self.build_mode == "genkernel" or self._install_profile.get_kernel_source_pkg() == "livecd-kernel":
exitstatus1 = GLIUtility.spawn("ls "+root+"/boot/init* >> "+file_name3)
if (exitstatus1 != 0):
raise GLIException("BootloaderError", 'fatal', '_configure_lilo', "Could not list initrds in /boot")
g = open(file_name3)
kernel_name = g.readlines()
g.close()
if not kernel_name[0]:
raise GLIException("BootloaderError", 'fatal', '_configure_lilo',"Error: We have no kernel in /boot to put in the grub.conf file!")
kernel_name = map(string.strip, kernel_name)
kernel_name[0] = kernel_name[0].split(root)[1]
kernel_name[1] = kernel_name[1].split(root)[1]
if self._install_profile.get_bootloader_kernel_args(): bootloader_kernel_args = self._install_profile.get_bootloader_kernel_args()
else: bootloader_kernel_args = ""
#-------------------------------------------------------------
#time to build the lilo.conf
newliloconf = ""
if self._install_profile.get_boot_loader_mbr():
newliloconf += "boot="+self.mbr_device+" # Install LILO in the MBR \n"
else:
newliloconf += "boot="+self.boot_device+self.boot_minor+" # Install LILO in the MBR \n"
newliloconf += "prompt # Give the user the chance to select another section\n"
newliloconf += "timeout=50 # Wait 5 (five) seconds before booting the default section\n"
newliloconf += "default=gentoo # When the timeout has passed, boot the \"gentoo\" section\n"
newliloconf += "# Only if you use framebuffer. Otherwise remove the following line:\n"
if not self._install_profile.get_kernel_bootsplash():
newliloconf += "#"
newliloconf += "vga=788 # Framebuffer setting. Adjust to your own will\n"
newliloconf += "image=/boot"+kernel_name[0][5:]+" \n"
newliloconf += " label=gentoo \n read-only \n"
if self.build_mode != "genkernel" and self._install_profile.get_kernel_source_pkg() != "livecd-kernel":
newliloconf += " root="+self.root_device+self.root_minor+" \n"
if bootloader_kernel_args:
newliloconf += " append=\""+bootloader_kernel_args+"\" \n"
else:
newliloconf += " root=/dev/ram0 \n"
newliloconf += " append=\"init=/linuxrc ramdisk=8192 real_root="+self.root_device+self.root_minor + " " + bootloader_kernel_args + "\" \n"
newliloconf += " initrd=/boot"+kernel_name[1][5:] + "\n\n"
newliloconf = self._lilo_add_windows(newliloconf)
#now make the lilo.conf file
file_name = root + "/etc/lilo.conf"
try:
shutil.move(file_name, file_name + ".OLDdefault")
except:
pass
f = open(file_name, 'w')
f.writelines(newliloconf)
f.close()
self._logger.log("Lilo installed and configured. Not run yet.")
示例8: enable_ssh
def enable_ssh(self):
if self._configuration.get_verbose(): self._logger.log("DEBUG: beginning of enable_ssh()")
if self._configuration.get_enable_ssh():
status = GLIUtility.spawn("/etc/init.d/sshd start")
if not GLIUtility.exitsuccess(status):
self._logger.log("ERROR! : Could not start the SSH daemon!")
# raise GLIException("SSHError", 'warning','enable_ssh',"Could not start SSH daemon!")
else:
self._logger.log("SSH Started.")
示例9: get_best_version_vdb_chroot
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()
示例10: set_root_passwd
def set_root_passwd(self):
self._logger.log("Setting root password.")
if self._configuration.get_root_passwd() != "":
# The password specified in the configuration is encrypted.
status = GLIUtility.spawn("echo 'root:" + self._configuration.get_root_passwd() + "' | chpasswd -e")
if not GLIUtility.exitsuccess(status):
self._logger.log("ERROR! : Could not set the root password on the livecd environment!")
# raise GLIException("PasswordError", 'warning', 'set_root_passwd', "Could not set the root password!")
else:
self._logger.log("Livecd root password set.")
示例11: _partition_resize_step
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()
示例12: get_treeview_data
def get_treeview_data(self):
data = []
treeiter = self.treedata.get_iter_first()
while treeiter !=None:
user = self.treedata.get_value(treeiter,1)
passwd = self.treedata.get_value(treeiter,0)
# if the user was loaded from a profile, do NOT
# hash the password, but carry it through
if user not in self.users_from_profile:
pass_hash = GLIUtility.hash_password(passwd)
else:
pass_hash = passwd
groups = self.treedata.get_value(treeiter,2)
shell = self.treedata.get_value(treeiter,3)
homedir = self.treedata.get_value(treeiter,4)
userid = self.treedata.get_value(treeiter,5)
comment = self.treedata.get_value(treeiter,6)
try:
group_tuple = tuple(groups.split(","))
except:
# must be only 1 group
group_tuple = (groups)
data.append([user,pass_hash,group_tuple,shell,homedir,userid,comment])
treeiter = self.treedata.iter_next(treeiter)
return data
示例13: load_kernel_modules
def load_kernel_modules(self):
if self._configuration.get_verbose(): self._logger.log("DEBUG: beginning of load_kernel_modules()")
modules = self._configuration.get_kernel_modules()
if self._configuration.get_verbose(): self._logger.log("DEBUG: load_kernel_modules(): modules are " + str(modules))
for module in modules:
try:
if self._configuration.get_verbose(): self._logger.log("DEBUG: load_kernel_modules(): trying to load module " + module)
ret = GLIUtility.spawn('modprobe ' + module)
if not GLIUtility.exitsuccess(ret):
self._logger.log("ERROR! : Could not load module: "+module)
# raise GLIException("KernelModuleError", 'warning', 'load_kernel_modules', 'Could not load module: ' + module)
else:
self._logger.log('kernel module: ' + module + ' loaded.')
except KernelModuleError, error:
self.output(error)
self._logger.log(error.get_error_level() + '! ' + error.get_error_msg())
示例14: deactivate
def deactivate(self):
if not self.check_dynamic.get_active():
if not self.entry_stage_tarball_uri.get_text():
msgdlg = gtk.MessageDialog(parent=self.controller.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="You did not enter a stage tarball URI. You cannot complete an installation until you set this value. Continue?")
resp = msgdlg.run()
msgdlg.destroy()
if resp == gtk.RESPONSE_NO:
return False
elif not GLIUtility.validate_uri(self.entry_stage_tarball_uri.get_text()):
msgdlg = gtk.MessageDialog(parent=self.controller.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="The stage tarball URI you entered does not exist. You cannot complete an installation until this value is a valid. Continue?")
resp = msgdlg.run()
msgdlg.destroy()
if resp == gtk.RESPONSE_NO:
return False
elif self.active_selection == 3 and self.check_grp.get_active() and self.has_systempkgs:
msgdlg = gtk.MessageDialog(parent=self.controller.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="When doing a GRP install, it is recommended to use the Dynamic option instead of selecting your own tarball. Continue?")
resp = msgdlg.run()
msgdlg.destroy()
if resp == gtk.RESPONSE_NO:
return False
self.controller.install_profile.set_install_stage(None, self.active_selection, None)
if self.active_selection == 3:
self.controller.install_profile.set_grp_install(None, self.check_grp.get_active(), None)
self.controller.install_profile.set_dynamic_stage3(None, self.check_dynamic.get_active(), None)
else:
self.controller.install_profile.set_grp_install(None, False, None)
try: self.controller.install_profile.set_stage_tarball_uri(None, self.entry_stage_tarball_uri.get_text(), None)
except: pass
return True
示例15: _setup_lilo
def _setup_lilo(self):
#-------------------------------------------------------------
#OK, now that the file is built. Install lilo.
exitstatus = GLIUtility.spawn("/sbin/lilo",chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)
if exitstatus != 0:
raise GLIException("LiloInstallError", 'fatal', '_setup_lilo', "Running lilo failed!")
self._logger.log("Bootloader: lilo has been run/installed!")