本文整理汇总了Python中utils.join_path函数的典型用法代码示例。如果您正苦于以下问题:Python join_path函数的具体用法?Python join_path怎么用?Python join_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了join_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show
def show(self, args):
"""
Display the help for requested service/api
Join the keywords inputs to return the help file
Example:
jcs compute help
This would point to help_topics/compute.txt
jcs compute describe-instances help
This would point to help_topic/describe-instances.txt
"""
help_file = self.help_dir
for arg in args:
if arg != 'help':
help_file = utils.join_path(help_file, arg)
else:
if help_file == self.help_dir:
# Display jcs help
help_file = utils.join_path(help_file, 'jcs')
help_file += '.txt'
# Handle errors like jcs compute help describe-instances
if 'help' != args[-1]:
raise IndexError()
self.process_help_file(help_file)
示例2: create_preseed
def create_preseed(self):
template_file = join_path(self.info.data_dir, "preseed." + self.info.distro.name)
if not os.path.exists(template_file):
template_file = join_path(self.info.data_dir, "preseed.lupin")
template = read_file(template_file)
partitioning = ""
partitioning += "d-i partman-auto/disk string LIDISK\n"
partitioning += "d-i partman-auto/method string loop\n"
partitioning += "d-i partman-auto-loop/partition string LIPARTITION\n"
partitioning += "d-i partman-auto-loop/recipe string \\\n"
disks_dir = unix_path(self.info.disks_dir) + "/"
if self.info.root_size_mb:
partitioning += (
" %s 3000 %s %s $default_filesystem method{ format } format{ } use_filesystem{ } $default_filesystem{ } mountpoint{ / } . \\\n"
% (disks_dir + "root.disk", self.info.root_size_mb, self.info.root_size_mb)
)
if self.info.swap_size_mb:
partitioning += " %s 100 %s %s linux-swap method{ swap } format{ } . \\\n" % (
disks_dir + "swap.disk",
self.info.swap_size_mb,
self.info.swap_size_mb,
)
if self.info.home_size_mb:
partitioning += (
" %s 100 %s %s $default_filesystem method{ format } format{ } use_filesystem{ } $default_filesystem{ } mountpoint{ /home } . \\\n"
% (disks_dir + "home.disk", self.info.home_size_mb, self.info.home_size_mb)
)
if self.info.usr_size_mb:
partitioning += (
" %s 100 %s %s $default_filesystem method{ format } format{ } use_filesystem{ } $default_filesystem{ } mountpoint{ /usr } . \\\n"
% (disks_dir + "usr.disk", self.info.usr_size_mb, self.info.usr_size_mb)
)
partitioning += "\n"
safe_host_username = self.info.host_username.replace(" ", "+")
user_directory = self.info.user_directory.replace("\\", "/")[2:]
host_os_name = "Windows XP Professional" # TBD
password = md5_password(self.info.password)
dic = dict(
timezone=self.info.timezone,
password=password,
user_full_name=self.info.user_full_name,
distro_packages=self.info.distro.packages,
host_username=self.info.host_username,
username=self.info.username,
partitioning=partitioning,
user_directory=user_directory,
safe_host_username=safe_host_username,
host_os_name=host_os_name,
)
content = template
for k, v in dic.items():
k = "$(%s)" % k
content = content.replace(k, v)
preseed_file = join_path(self.info.custominstall, "preseed.cfg")
write_file(preseed_file, content)
示例3: modify_grub_configuration
def modify_grub_configuration(self):
template_file = join_path(self.info.data_dir, 'grub.install.cfg')
template = read_file(template_file)
#if self.info.run_task == "cd_boot":
# isopath = ""
if self.info.iso_path:
isopath = unix_path(self.info.iso_path)
if self.info.target_drive.is_fat():
rootflags = "rootflags=sync"
else:
rootflags = "rootflags=syncio"
if self.info.run_task == "cd_boot":
title = "StartOS LiveCD"
elif self.info.flag:
title = "StartOS"
else:
title = "StartOS LiveCD"
if self.info.run_task == "cd_boot":
mode = ""
elif self.info.flag:
mode = "install-automatic"
else:
mode = ""
dic = dict(
title1 = "Completing the StartOS installation.",
title2 = "For more installation boot options, press `ESC' now...",
normal_mode_title = title,
kernel = unix_path(self.info.kernel),
iso_path = isopath,
install_mode = mode,
locale = self.info.locale,
keyboard_layout = self.info.keyboard_layout,
keyboard_variant = self.info.keyboard_variant,
rootflags = rootflags,
initrd = unix_path(self.info.initrd),
)
content = template
for k,v in dic.items():
k = "$(%s)" % k
log.debug("%s,%s" %(k,v))
content = content.replace(k, v)
#if self.info.run_task == "cd_boot":
# content = content.replace(" automatic-ubiquity", "")
# content = content.replace(" iso-scan/filename=", "")
grub_config_file = join_path(self.info.install_boot_dir, "grub", "grub.cfg")
log.debug("grub_config_file === %s" %grub_config_file)
write_file(grub_config_file, content)
示例4: create_diskimage_dirs
def create_diskimage_dirs(self, associated_task=None):
self.info.disks_dir = join_path(self.info.target_dir, "disks")
self.info.disks_boot_dir = join_path(self.info.disks_dir, "boot")
dirs = [
self.info.target_dir,
self.info.disks_dir,
self.info.disks_boot_dir,
join_path(self.info.disks_boot_dir, "grub"),
]
for d in dirs:
if not os.path.isdir(d):
log.debug("Creating dir %s" % d)
os.mkdir(d)
示例5: find_any_iso
def find_any_iso(self):
'''
look for USB keys with ISO or pre specified ISO
'''
#Use pre-specified ISO
if self.info.iso_path and os.path.exists(self.info.iso_path):
log.debug("Checking pre-specified ISO %s" % self.info.iso_path)
for distro in self.info.distros:
if distro.is_valid_iso(self.info.iso_path, self.info.check_arch):
self.info.cd_path = None
return self.info.iso_path, distro
#Search USB devices
log.debug("Searching ISOs on USB devices")
for path in self.get_usb_search_paths():
path = join_path(path, '*.iso')
isos = glob.glob(path)
#以修改时间排序
def my_cmp(E1,E2):
return -cmp(os.path.getmtime(E1),os.path.getmtime(E2))
isos.sort(my_cmp)
#在python2.4之后才支持以下语法
#isos.sort(key=lambda x: os.path.getmtime(x))
for iso in isos:
for distro in self.info.distros:
if distro.is_valid_iso(iso, self.info.check_arch):
return iso, distro
return None, None
示例6: copy_iso
def copy_iso(self, iso_path, associated_task):
if not iso_path:
return
iso_name = os.path.basename(iso_path)
dest = join_path(self.info.install_dir, "installation.iso")
check_iso = associated_task.add_subtask(
self.check_iso,
description = _("Checking installation files"))
if check_iso(iso_path):
if os.path.dirname(iso_path) == dest \
or os.path.dirname(iso_path) == self.info.backup_dir:
move_iso = associated_task.add_subtask(
shutil.move,
description = _("Copying installation files"))
log.debug("Moving %s > %s" % (iso_path, dest))
move_iso(iso_path, dest)
else:
copy_iso = associated_task.add_subtask(
copy_file,
description = _("Copying installation files"))
log.debug("Copying %s > %s" % (iso_path, dest))
copy_iso(iso_path, dest)
self.info.cd_path = None
self.info.iso_path = dest
return True
示例7: use_cd
def use_cd(self, associated_task):
if self.cd_path:
extract_iso = associated_task.add_subtask(
copy_file,
description = _("Extracting files from %s") % self.cd_path)
self.info.iso_path = join_path(self.info.install_dir, "installation.iso")
try:
extract_iso(self.cd_path, self.info.iso_path)
except Exception, err:
log.error(err)
self.info.cd_path = None
self.info.iso_path = None
return False
self.info.cd_path = self.cd_path
#This will often fail before release as the CD might not match the latest daily ISO
check_iso = associated_task.add_subtask(
self.check_iso,
description = _("Checking installation files"))
if not check_iso(self.info.iso_path):
subversion = self.info.cd_distro.get_info(self.info.cd_path)[2]
if subversion.lower() in ("alpha", "beta", "release candidate"):
log.error("CD check failed, but ignoring because CD is %s" % subversion)
else:
self.info.cd_path = None
self.info.iso_path = None
return False
return True
示例8: check_cd
def check_cd(self, cd_path, associated_task=None):
associated_task.description = _("Checking CD %s") % cd_path
if not self.info.distro.is_valid_cd(cd_path, check_arch=False):
return False
self.set_distro_from_arch(cd_path)
#if self.info.skip_md5_check:
return True
md5sums_file = join_path(cd_path, self.info.distro.md5sums)
for rel_path in self.info.distro.get_required_files():
if rel_path == self.info.distro.md5sums:
continue
check_file = associated_task.add_subtask(self.check_file)
file_path = join_path(cd_path, rel_path)
if not check_file(file_path, rel_path, md5sums_file):
return False
return True
示例9: _iter_items
def _iter_items(cls, repo, common_path = None):
if common_path is None:
common_path = cls._common_path_default
rela_paths = set()
# walk loose refs
# Currently we do not follow links
for root, dirs, files in os.walk(join_path_native(repo.git_dir, common_path)):
if 'refs/' not in root: # skip non-refs subfolders
refs_id = [ i for i,d in enumerate(dirs) if d == 'refs' ]
if refs_id:
dirs[0:] = ['refs']
# END prune non-refs folders
for f in files:
abs_path = to_native_path_linux(join_path(root, f))
rela_paths.add(abs_path.replace(to_native_path_linux(repo.git_dir) + '/', ""))
# END for each file in root directory
# END for each directory to walk
# read packed refs
for sha, rela_path in cls._iter_packed_refs(repo):
if rela_path.startswith(common_path):
rela_paths.add(rela_path)
# END relative path matches common path
# END packed refs reading
# return paths in sorted order
for path in sorted(rela_paths):
try:
yield cls.from_path(repo, path)
except ValueError:
continue
示例10: find_iso
def find_iso(self, associated_task=None):
log.debug("Searching for local ISO")
for path in self.get_iso_search_paths():
path = join_path(path, '*.iso')
isos = glob.glob(path)
for iso in isos:
if self.info.distro.is_valid_iso(iso, self.info.check_arch):
return iso
示例11: __init__
def __init__(self, application):
self.application = application
self.info = application.info
#~ if hasattr(sys,'frozen') and sys.frozen:
#~ root_dir = dirname(abspath(sys.executable))
#~ else:
#~ root_dir = ''
#~ self.info.root_dir = abspath(root_dir)
self.info.temp_dir = join_path(self.info.root_dir, 'temp')
self.info.data_dir = join_path(self.info.root_dir, 'data')
self.info.bin_dir = join_path(self.info.root_dir, 'bin')
self.info.image_dir = join_path(self.info.data_dir, 'images')
self.info.translations_dir = join_path(self.info.root_dir, 'translations')
self.info.trusted_keys = join_path(self.info.data_dir, 'trustedkeys.gpg')
self.info.application_icon = join_path(self.info.image_dir, self.info.application_name.capitalize() + ".ico")
self.info.icon = self.info.application_icon
self.info.iso_md5_hashes = {}
log.debug('data_dir=%s' % self.info.data_dir)
log.debug('bin_dir=%s' % self.info.bin_dir)
log.debug('image_dir=%s' % self.info.image_dir)
log.debug('application_icon=%s' % self.info.application_icon)
if self.info.locale:
locale.setlocale(locale.LC_ALL, self.info.locale)
log.debug('user defined locale = %s' % self.info.locale)
gettext.install(self.info.application_name, localedir=self.info.translations_dir, unicode=True)
示例12: create_dir_structure
def create_dir_structure(self, associated_task=None):
self.info.disks_dir = join_path(self.info.target_dir, "disks")
self.info.backup_dir = self.info.target_dir + "-backup"
self.info.install_dir = join_path(self.info.target_dir, "install")
self.info.install_boot_dir = join_path(self.info.install_dir, "boot")
#self.info.disks_boot_dir = join_path(self.info.disks_dir, "boot")
dirs = [
self.info.target_dir,
self.info.disks_dir,
self.info.install_dir,
self.info.install_boot_dir,
#self.info.disks_boot_dir,
#join_path(self.info.disks_boot_dir, "grub"),
join_path(self.info.install_boot_dir, "grub"),]
for d in dirs:
if not os.path.isdir(d):
log.debug("Creating dir %s" % d)
os.mkdir(d)
else:
log.info("%s exists, will not be created" % d)
示例13: modify_grub_configuration
def modify_grub_configuration(self):
template_file = join_path(self.info.data_dir, 'grub.install.cfg')
template = read_file(template_file)
if self.info.run_task == "cd_boot":
isopath = ""
## TBD at the moment we are extracting the ISO, not the CD content
#~ elif self.info.cd_path:
#~ isopath = unix_path(self.info.cd_path)
elif self.info.iso_path:
isopath = unix_path(self.info.iso_path)
if self.info.target_drive.is_fat():
rootflags = "rootflags=sync"
else:
rootflags = "rootflags=syncio"
dic = dict(
custom_installation_dir = unix_path(self.info.custominstall),
iso_path = isopath,
keyboard_variant = self.info.keyboard_variant,
keyboard_layout = self.info.keyboard_layout,
locale = self.info.locale,
accessibility = self.info.accessibility,
kernel = unix_path(self.info.kernel),
initrd = unix_path(self.info.initrd),
rootflags = rootflags,
title1 = "Completing the Linux Mint installation.",
title2 = "For more installation boot options, press `ESC' now...",
normal_mode_title = "Normal mode",
safe_graphic_mode_title = "Safe graphic mode",
acpi_workarounds_title = "ACPI workarounds",
verbose_mode_title = "Verbose mode",
demo_mode_title = "Demo mode",
)
content = template
for k,v in dic.items():
k = "$(%s)" % k
content = content.replace(k, v)
if self.info.run_task == "cd_boot":
content = content.replace(" automatic-ubiquity", "")
content = content.replace(" iso-scan/filename=", "")
grub_config_file = join_path(self.info.install_boot_dir, "grub", "grub.cfg")
write_file(grub_config_file, content)
示例14: create_preseed_diskimage
def create_preseed_diskimage(self):
source = join_path(self.info.data_dir, 'preseed.disk')
template = read_file(source)
password = md5_password(self.info.password)
dic = dict(
timezone = self.info.timezone,
password = password,
keyboard_variant = self.info.keyboard_variant,
keyboard_layout = self.info.keyboard_layout,
locale = self.info.locale,
user_full_name = self.info.user_full_name,
username = self.info.username)
for k,v in dic.items():
k = "$(%s)" % k
template = template.replace(k, v)
preseed_file = join_path(self.info.install_dir, "preseed.cfg")
write_file(preseed_file, template)
source = join_path(self.info.data_dir, "wubildr-disk.cfg")
target = join_path(self.info.install_dir, "wubildr-disk.cfg")
copy_file(source, target)
示例15: download_diskimage
def download_diskimage(self, diskimage, associated_task=None):
proxy = self.info.web_proxy
save_as = join_path(self.info.disks_dir, diskimage.split("/")[-1])
if os.path.isfile(save_as):
os.unlink(save_as)
try:
download = associated_task.add_subtask(downloader.download, is_required=False)
self.dimage_path = download(diskimage, save_as, web_proxy=proxy)
return self.dimage_path is not None
except Exception:
log.exception("Cannot download disk image file %s:" % diskimage)
return False