本文整理汇总了Python中slpkg.utils.Utils.read_file方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.read_file方法的具体用法?Python Utils.read_file怎么用?Python Utils.read_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类slpkg.utils.Utils
的用法示例。
在下文中一共展示了Utils.read_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Patches
# 需要导入模块: from slpkg.utils import Utils [as 别名]
# 或者: from slpkg.utils.Utils import read_file [as 别名]
#.........这里部分代码省略.........
if not find_package(repo_pkg_name, self.meta.pkg_path):
self.count_added += 1
self.count_upg -= 1
return self.count_upg
def views(self):
"""
Views packages
"""
for upg, size in sorted(zip(self.upgrade_all, self.comp_sum)):
pkg_split = split_package(upg[:-4])
color = self.meta.color["YELLOW"]
if not find_package(pkg_split[0], self.meta.pkg_path):
color = self.meta.color["RED"]
ver = get_installed_version(pkg_split[0])
print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>12}{12}".format(
color, pkg_split[0] + ver, self.meta.color["ENDC"],
" " * (23-len(pkg_split[0] + ver)), pkg_split[1],
" " * (18-len(pkg_split[1])), pkg_split[2],
" " * (8-len(pkg_split[2])), pkg_split[3],
" " * (7-len(pkg_split[3])), "Slack",
size, " K")).rstrip()
def upgrade(self):
"""
Upgrade packages
"""
for pkg in self.upgrade_all:
check_md5(pkg_checksum(pkg, "slack_patches"), self.patch_path + pkg)
pkg_ver = "{0}-{1}".format(split_package(pkg)[0],
split_package(pkg)[1])
if find_package(split_package(pkg)[0] + "-", self.meta.pkg_path):
print("[ {0}upgrading{1} ] --> {2}".format(
self.meta.color["YELLOW"], self.meta.color["ENDC"],
pkg[:-4]))
PackageManager((self.patch_path + pkg).split()).upgrade(
"--install-new")
self.upgraded.append(pkg_ver)
else:
print("[ {0}installing{1} ] --> {2}".format(
self.meta.color["GREEN"], self.meta.color["ENDC"],
pkg[:-4]))
PackageManager((self.patch_path + pkg).split()).upgrade(
"--install-new")
self.installed.append(pkg_ver)
def kernel(self):
"""
Check if kernel upgraded if true
then reinstall "lilo"
"""
for core in self.upgrade_all:
if "kernel" in core:
if self.meta.default_answer == "y":
answer = self.meta.default_answer
else:
print("")
Msg().template(78)
print("| {0}*** HIGHLY recommended reinstall 'LILO' "
"***{1}".format(self.meta.color["RED"],
self.meta.color["ENDC"]))
Msg().template(78)
answer = raw_input("\nThe kernel has been upgraded, "
"reinstall `LILO` [y/N]? ")
if answer in ["y", "Y"]:
subprocess.call("lilo", shell=True)
break
def slackpkg_update(self):
"""
This replace slackpkg ChangeLog.txt file with new
from Slackware official mirrors after update distribution.
"""
changelog_txt = "ChangeLog.txt"
changelog_old = changelog_txt + ".old"
arch = "64" if os.uname()[4] == "x86_64" else ""
slackware_mirror = self.utils.read_config(self.utils.read_file(
self.meta.conf_path + "slackware-changelogs-mirror"))
slackpkg_mirror = self.utils.read_config(
self.utils.read_file("{0}{1}".format(self.meta.slackpkg_conf,
"mirrors")))
if slackpkg_mirror and "current" in slackpkg_mirror:
log_mirror = "{0}slackware{1}-current/{2}".format(slackware_mirror,
arch,
changelog_txt)
else:
log_mirror = "{0}slackware{1}-{2}/{3}".format(slackware_mirror,
arch,
slack_ver(),
changelog_txt)
slackware_log = URL(log_mirror).reading()
if os.path.isfile(self.meta.slackpkg_lib_path + changelog_txt):
if os.path.isfile(self.meta.slackpkg_lib_path + changelog_old):
os.remove(self.meta.slackpkg_lib_path + changelog_old)
shutil.copy2(self.meta.slackpkg_lib_path + changelog_txt,
self.meta.slackpkg_lib_path + changelog_old)
os.remove(self.meta.slackpkg_lib_path + changelog_txt)
with open(self.meta.slackpkg_lib_path + changelog_txt, "w") as log:
log.write(slackware_log)
log.close()