本文整理汇总了Python中psr.sys.Sys.removeFile方法的典型用法代码示例。如果您正苦于以下问题:Python Sys.removeFile方法的具体用法?Python Sys.removeFile怎么用?Python Sys.removeFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psr.sys.Sys
的用法示例。
在下文中一共展示了Sys.removeFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onCommandMerge
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import removeFile [as 别名]
def onCommandMerge(self):
""""""
done = True
if not Sys.g.QUIET : self.parser.print_header()
if done :
toPath = None
try :
Sys.ptask()
key = Io.get_data(self.o.keyfile)
km = Kirmah(key)
kcf = None
istar = True
try:
import tarfile
dpath = Sys.dirname(Sys.realpath(self.o.outputfile))+Sys.sep if self.o.outputfile is not None else Sys.dirname(Sys.realpath(self.a[1]))+Sys.sep
if self.o.outputfile is None :
self.o.outputfile = dpath
with tarfile.open(self.a[1], mode='r') as tar:
#~ print(dpath)
tar.extractall(path=dpath)
kcf = None
for tarinfo in tar:
#~ print(tarinfo.name)
if tarinfo.isreg() and tarinfo.name[-4:]=='.kcf':
#~ print(dpath+tarinfo.name)
kcf = dpath+tarinfo.name
if kcf is not None :
km.DIR_OUTBOX = dpath
toPath = km.mergeFile(kcf, self.o.outputfile)
except BadKeyException:
Sys.pwarn((('BadKeyException : ',('wrong key ',Sys.CLZ_WARN_PARAM), ' !'),), False)
done = False
except Exception :
istar = False
toPath = km.mergeFile(self.a[1], self.o.outputfile)
#~ if self.o.outputfile is not None :
#~ Io.rename(toPath, self.o.outputfile)
#~ toPath = self.o.outputfile
except BadKeyException:
Sys.pwarn((('BadKeyException : ',('wrong key ',Sys.CLZ_WARN_PARAM), ' !'),), False)
done = False
except Exception as e :
done = False
if Sys.g.DEBUG :
print(e)
elif not Sys.g.QUIET :
Sys.pwarn((str(e),))
if not done :
if istar :
with tarfile.open(self.a[1], mode='r') as tar:
for tarinfo in tar:
Sys.removeFile(dpath+tarinfo.name)
if not Sys.g.QUIET :
self.onend_cmd('Kirmah Merge', self.stime, done, toPath)
示例2: sendFile
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import removeFile [as 别名]
def sendFile(self, data, retry=False):
""""""
done = None
key = None
if data is not None:
key, label, ext, count, catg, hlst, usr, ownerHash, sha256, size = data
self.idxu.index.addUser(usr, ownerHash)
account = self.idxu.switchFileAccount()
sendIds = []
cancel = False
d = None
Sys.cli_emit_progress(0)
Sys.sleep(0.2)
if not retry:
Sys.pwlog(
[
(" Sending... ", Const.CLZ_7),
(" (", Const.CLZ_0),
(
" ~" + Sys.readableBytes(Sys.getsize(self.outbox + hlst["data"][0][1] + Kirmah.EXT)),
Const.CLZ_3,
),
(" per msg ) ", Const.CLZ_0, True),
]
)
else:
Sys.pwlog(
[
(" Retry sending last file... ", Const.CLZ_0),
(label + ext, Const.CLZ_7),
(" (" + catg + ")", Const.CLZ_3, True),
]
)
ignore = False
for i, row in enumerate(hlst["data"]):
""""""
if retry:
if not Io.file_exists(self.outbox + row[1] + Kirmah.EXT):
continue
elif not ignore:
Sys.pwlog([(" Ignoring file 1 to " + str(i), Const.CLZ_1, True)])
ignore = True
d = Sys.datetime.now()
msg = self.idxu.mb.build(usr, "all", hlst["head"][2], self.outbox + row[1] + Kirmah.EXT)
try:
mid = self.idxu.ih.send(msg.as_string(), self.rootBox)
except Exception as e:
Sys.pwarn((("addFile : ", (str(e), Sys.CLZ_WARN_PARAM), " !"),))
Sys.echo("waiting 5 s and retry")
Sys.sleep(5)
# force reconnect
self.impst.idxu.switchFileAccount(account, True)
# retry
mid = self.idxu.ih.send(msg.as_string(), self.rootBox)
finally:
if not mid is None:
status, resp = self.idxu.ih.fetch(mid[1], "(UID BODYSTRUCTURE)", True)
if status == self.idxu.ih.OK:
sendIds.append((mid[1], row))
Sys.pwlog(
[
(" part ", Const.CLZ_0),
(str(row[0]).rjust(2, "0"), Const.CLZ_2),
(" sent as msg ", Const.CLZ_0),
(str(mid[1]).rjust(5, "0"), Const.CLZ_1),
(" (", Const.CLZ_7),
(str(int(row[4]) + 1).rjust(2, "0"), Const.CLZ_2),
("/", Const.CLZ_7),
(str(count), Const.CLZ_3),
(") in ", Const.CLZ_7),
(Sys.getDelta(d), Const.CLZ_4, True),
]
)
Sys.cli_emit_progress(int((i + 1) * 100 / len(hlst["data"])))
Sys.removeFile(self.outbox + row[1] + Kirmah.EXT)
else:
Sys.pwarn((("error occured when sending part ", (row[0], Sys.Clz.fgb3), " !"),))
diff = self.checkSendIds(sendIds, hlst["head"][2])
if len(sendIds) == count or retry:
self.idxu.get(True)
self.idxu.index.add(key, label, hlst["head"][1], ext, ownerHash, catg, sha256, size, account)
done = self.idxu.update()
Io.removeFile(self.addmapPath + Kirmah.EXT)
# resending missing parts
else:
Sys.pwarn((("TODO => must resending ", ("missing", Sys.CLZ_WARN_PARAM), " parts"),))
print(diff)
# clean
for mid, row in sendIds:
if Io.file_exists(self.outbox + row[1] + Kirmah.EXT):
Sys.removeFile(self.outbox + row[1] + Kirmah.EXT)
#.........这里部分代码省略.........