本文整理汇总了Python中fsbc.paths.Paths.expand_path方法的典型用法代码示例。如果您正苦于以下问题:Python Paths.expand_path方法的具体用法?Python Paths.expand_path怎么用?Python Paths.expand_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fsbc.paths.Paths
的用法示例。
在下文中一共展示了Paths.expand_path方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: expand_default_path
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def expand_default_path(self, src, default_dir):
if "://" in src:
return src, None
src = Paths.expand_path(src, default_dir)
archive = Archive(src)
# if not archive.exists(src):
# dirs = [default_dir]
# for dir in dirs:
# path = os.path.join(dir, src)
# print("checking", repr(path))
# archive = Archive(path)
# if archive.exists(path):
# #if os.path.exists(path):
# src = path
# break
# else:
# raise Exception("Cannot find path for " + repr(src))
return src, archive
示例2: prepare_hard_drives
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def prepare_hard_drives(self):
print("LaunchHandler.prepare_hard_drives")
current_task.set_progress(gettext("Preparing hard drives..."))
# self.on_progress(gettext("Preparing hard drives..."))
for i in range(0, 10):
key = "hard_drive_{0}".format(i)
src = self.config.get(key, "")
dummy, ext = os.path.splitext(src)
ext = ext.lower()
if is_http_url(src):
name = src.rsplit("/", 1)[-1]
name = urllib.parse.unquote(name)
self.on_progress(gettext("Downloading {0}...".format(name)))
dest = os.path.join(self.temp_dir, name)
Downloader.install_file_from_url(src, dest)
src = dest
elif src.startswith("hd://game/"):
self.unpack_game_hard_drive(i, src)
self.disable_save_states()
return
elif src.startswith("hd://template/workbench/"):
self.prepare_workbench_hard_drive(i, src)
self.disable_save_states()
return
elif src.startswith("hd://template/empty/"):
self.prepare_empty_hard_drive(i, src)
self.disable_save_states()
return
if ext in Archive.extensions:
print("zipped hard drive", src)
self.unpack_hard_drive(i, src)
self.disable_save_states()
elif src.endswith("HardDrive"):
print("XML-described hard drive", src)
self.unpack_hard_drive(i, src)
self.disable_save_states()
else:
src = Paths.expand_path(src)
self.config[key] = src
示例3: convert_uri
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def convert_uri(self, uri, prefer_path=False):
if uri.startswith("sha1://"):
return self.open_sha1_uri(uri)
elif uri.startswith("db://"):
# old name for sha1://
return self.open_sha1_uri(uri)
elif is_http_url(uri):
return self.open_url(uri)
elif uri.startswith("locker://"):
return open_locker_uri(
uri, opener_cache_dict=self.opener_cache_dict
)
else:
if uri.startswith("$"):
uri = Paths.expand_path(uri)
if prefer_path and os.path.exists(uri):
# return helper object so isinstance does not match with str
return File(uri)
return Archive(uri).open(uri)
示例4: get_cover_path
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def get_cover_path(self):
sha1 = LauncherConfig.get("front_sha1")
if sha1:
return "sha1:" + sha1
path = self.get_override_path("cover_image")
if path and os.path.exists(path):
return path
if self.uuid:
paths = FSGSDirectories.get_images_dirs()
for dir_ in paths:
p = os.path.join(dir_, self.platform, "Images",
self.uuid[:2], self.uuid, "front.png")
if os.path.exists(p):
return p
p = os.path.join(dir_, self.platform, "Thumbnails",
self.uuid[:2], self.uuid, "front.png")
if os.path.exists(p):
return p
letter = self.get_letter(self.name)
if not letter:
return None
name = self.name
override_dir = LauncherConfig.get("covers_dir")
if override_dir:
paths = [Paths.expand_path(override_dir)]
else:
paths = FSGSDirectories.get_covers_dirs()
for dir_ in paths:
path = os.path.join(dir_, letter, name + ".jpg")
if os.path.exists(path):
return path
path = os.path.join(dir_, letter, name + ".png")
if os.path.exists(path):
return path
path = os.path.join(dir_, name + ".jpg")
if os.path.exists(path):
return path
path = os.path.join(dir_, name + ".png")
if os.path.exists(path):
return path
return None
示例5: fix_file_checksum
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def fix_file_checksum(sha1_key, key, base_dir, is_rom=False):
path = config.get(key, "")
# hack to synchronize URLs
# print(repr(path))
if path.startswith("http://") or path.startswith("https://"):
sha1 = path
config[sha1_key] = sha1
return
path = Paths.expand_path(path)
sha1 = config.get(sha1_key, "")
if not path:
return
if sha1:
# assuming sha1 is correct
return
if not os.path.exists(path):
print(repr(path), "does not exist")
path = os.path.join(base_dir, path)
if not os.path.exists(path):
print(repr(path), "does not exist")
return
if os.path.isdir(path):
# could set a fake checksum here or something, to indicate
# that it isn't supposed to be set..
return
print("checksumming", repr(path))
size = os.path.getsize(path)
if size > 64 * 1024 * 1024:
# not checksumming large files right now
print("not checksumming large file")
return
if is_rom:
sha1 = checksum_tool.checksum_rom(path)
else:
sha1 = checksum_tool.checksum(path)
config[sha1_key] = sha1
示例6: prepare_roms
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def prepare_roms(self):
print("LaunchHandler.prepare_roms")
current_task.set_progress(gettext("Preparing kickstart ROMs..."))
amiga_model = self.config.get("amiga_model", "A500")
model_config = Amiga.get_model_config(amiga_model)
roms = [("kickstart_file", model_config["kickstarts"])]
if self.config["kickstart_ext_file"] or model_config["ext_roms"]:
# not all Amigas have extended ROMs
roms.append(("kickstart_ext_file", model_config["ext_roms"]))
if amiga_model.lower() == "cd32/fmv":
roms.append(("fvm_rom", [CD32_FMV_ROM]))
if self.config["graphics_card"].lower().startswith("picasso-iv"):
roms.append(("graphics_card_rom", [PICASSO_IV_74_ROM]))
if self.config["accelerator"].lower() == "cyberstorm-ppc":
roms.append(("accelerator_rom", ["cyberstormppc.rom"]))
if self.config["freezer_cartridge"] == "action-replay-2":
# Ideally, we would want to recognize ROMs based on zeroing the
# first four bytes, but right now we simply recognize a common
# additional version. freezer_cartridge_rom isn't a real option,
# we just want to copy the rom file and let FS-UAE find it
roms.append(("[freezer_cartridge]",
[ACTION_REPLAY_MK_II_2_14_ROM.sha1,
ACTION_REPLAY_MK_II_2_14_MOD_ROM.sha1]))
elif self.config["freezer_cartridge"] == "action-replay-3":
roms.append(("[freezer_cartridge]",
[ACTION_REPLAY_MK_III_3_17_ROM.sha1,
ACTION_REPLAY_MK_III_3_17_MOD_ROM.sha1]))
for config_key, default_roms in roms:
print("ROM:", config_key, default_roms)
src = self.config[config_key]
if not src:
for sha1 in default_roms:
if is_sha1(sha1):
rom_src = self.fsgs.file.find_by_sha1(sha1)
if rom_src:
src = rom_src
break
else:
# roms_dir = FSGSDirectories.get_kickstarts_dir()
# src = os.path.join(roms_dir, sha1)
# if os.path.exists(src):
# break
# loop up file in roms dir instead
src = sha1
elif src == "internal":
continue
elif src:
src = Paths.expand_path(src)
if not src:
raise TaskFailure(
gettext("Did not find required Kickstart or "
"ROM for {}. Wanted one of these files: {}".format(
config_key, repr(default_roms))))
use_temp_kickstarts_dir = False
dest = os.path.join(self.temp_dir, os.path.basename(src))
archive = Archive(src)
stream = None
if not archive.exists(src):
dirs = [self.fsgs.amiga.get_kickstarts_dir()]
for dir in dirs:
path = os.path.join(dir, src)
print("checking", repr(path))
archive = Archive(path)
if archive.exists(path):
src = path
break
else:
try:
stream = self.fsgs.file.open(src)
if stream is None:
raise FileNotFoundError(src)
except FileNotFoundError:
raise TaskFailure(gettext(
"Cannot find required ROM "
"file: {name}".format(name=repr(src))))
with open(dest, "wb") as f:
if stream:
f.write(stream.read())
else:
ROMManager.decrypt_archive_rom(archive, src, file=f)
if use_temp_kickstarts_dir:
self.config[config_key] = os.path.basename(src)
else:
self.config[config_key] = dest
if use_temp_kickstarts_dir:
self.config["kickstarts_dir"] = self.temp_dir
示例7: get_screenshot_path
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def get_screenshot_path(self, number):
if number == 0:
sha1 = LauncherConfig.get("title_sha1")
else:
sha1 = LauncherConfig.get("screen{0}_sha1".format(number))
if sha1:
return "sha1:" + sha1
if number == 0:
path = self.get_override_path("title_image")
else:
path = self.get_override_path("screen{0}_image".format(number))
if path and os.path.exists(path):
return path
if self.uuid:
if number == 0:
name = "title.png"
else:
name = "screen{0}.png".format(number)
paths = FSGSDirectories.get_images_dirs()
for dir_ in paths:
p = os.path.join(dir_, self.platform, "Images",
self.uuid[:2], self.uuid, name)
if os.path.exists(p):
return p
p = os.path.join(dir_, self.platform, "Thumbnails",
self.uuid[:2], self.uuid, name)
if os.path.exists(p):
return p
letter = self.get_letter(self.name)
if not letter:
return None
name = self.name
if number == 0:
override_dir = LauncherConfig.get("titles_dir")
if override_dir:
paths = [Paths.expand_path(override_dir)]
else:
paths = FSGSDirectories.get_titles_dirs()
else:
override_dir = LauncherConfig.get("screenshots_dir")
if override_dir:
paths = [Paths.expand_path(override_dir)]
else:
paths = FSGSDirectories.get_screenshots_dirs()
if number >= 2:
name = "{0}_{1}".format(name, number)
for dir_ in paths:
path = os.path.join(dir_, letter, name + ".png")
if os.path.exists(path):
return path
path = os.path.join(dir_, letter, name + ".gif")
if os.path.exists(path):
return path
path = os.path.join(dir_, name + ".png")
if os.path.exists(path):
return path
path = os.path.join(dir_, letter, name + ".gif")
if os.path.exists(path):
return path
return None
示例8: get_override_path
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def get_override_path(name):
path = LauncherConfig.get(name)
if not path:
return ""
path = Paths.expand_path(path)
return path
示例9: expand_default_path
# 需要导入模块: from fsbc.paths import Paths [as 别名]
# 或者: from fsbc.paths.Paths import expand_path [as 别名]
def expand_default_path(src, default_dir):
if "://" in src:
return src, None
src = Paths.expand_path(src, default_dir)
archive = Archive(src)
return src, archive