本文整理汇总了Python中psr.sys.Sys.basename方法的典型用法代码示例。如果您正苦于以下问题:Python Sys.basename方法的具体用法?Python Sys.basename怎么用?Python Sys.basename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psr.sys.Sys
的用法示例。
在下文中一共展示了Sys.basename方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildFile
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import basename [as 别名]
def buildFile(self, fromPath, label="", catg=""):
count = self.getCountParts(fromPath)
Sys.pwlog([(" Get Hash... ", Const.CLZ_7, True)])
sha256 = hash_sha256_file(fromPath)
Sys.pwlog([(" hash : ", Const.CLZ_0), (sha256, Const.CLZ_2, True), (" Build File...", Const.CLZ_0, True)])
kg = KeyGen(128)
size = Sys.getsize(fromPath)
row = self.idxu.index.get(sha256)
if row is None:
if label == "":
label, ext = Sys.getFileExt(Sys.basename(fromPath))
else:
label, ext = Sys.getFileExt(label)
if catg == "":
catg = self.idxu.index.getAutoCatg(ext)
size = Sys.getsize(fromPath)
Sys.pwlog(
[
(" Splitting ", Const.CLZ_1),
(label, Const.CLZ_7),
(ext, Const.CLZ_7),
(" (", Const.CLZ_0),
(Sys.readableBytes(size), Const.CLZ_3),
(")", Const.CLZ_0, True),
]
)
Sys.cli_emit_progress(0)
Sys.sleep(0.2)
km = Kirmah(kg.key)
km.DIR_OUTBOX = self.outbox
# hlst genetate with sha256
hlst = km.ck.getHashList(sha256, int(count), True)
usr = self.idxu.conf.get("name", "infos")
ownerHash = self.idxu.mb.getHashName(usr)
km.split(fromPath, hlst)
Sys.pwlog([(" done ", Const.CLZ_2, True)])
row = [kg.key, label, ext, count, catg, hlst, usr, ownerHash, sha256, size]
self.backupAddMap(row)
else:
Sys.pwlog(
[
(" File Already exist ! ", Const.CLZ_1, True),
(" id : ".rjust(10, " "), Const.CLZ_0),
(str(row[ImpraIndex.UID]), Const.CLZ_1, True),
(" label : ".rjust(10, " "), Const.CLZ_0),
(row[ImpraIndex.LABEL], Const.CLZ_3, True),
]
)
row = None
return row
示例2: onCommandAdd
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import basename [as 别名]
def onCommandAdd(self):
""""""
if not len(self.a) > 1:
self.parser.error_cmd((self.a[0] + " command need one argument",), True)
else:
vfile = self.a[1]
if not Io.file_exists(vfile):
if Sys.isdir(vfile):
for f in Sys.listdir(vfile):
if not Sys.isdir(f):
label, ext = Sys.getFileExt(Sys.basename(f))
if self.o.category is None:
self.o.category = ""
done = self.impst.addFile(vfile + Sys.sep + f, label, self.o.category)
if done:
self.Cli.printLineSep(Const.LINE_SEP_CHAR, Const.LINE_SEP_LEN)
Sys.dprint(" ", end="")
Sys.echo(" == OK == ", Sys.Clz.bg2 + Sys.Clz.fgb7)
Sys.dprint()
else:
self.parser.error_cmd((self.a[0] + " is not a file or a directory",), True)
else:
if not len(self.a) > 2:
label = Sys.basename(vfile)
else:
label = self.a[2]
if self.o.category is None:
self.o.category = ""
Sys.clear()
self.pheader()
done = self.impst.addFile(vfile, label, self.o.category)
if done:
self.Cli.printLineSep(Const.LINE_SEP_CHAR, Const.LINE_SEP_LEN)
Sys.dprint(" ", end="")
Sys.echo(" == OK == ", Sys.Clz.bg2 + Sys.Clz.fgb7)
Sys.dprint()
else:
self.Cli.printLineSep(Const.LINE_SEP_CHAR, Const.LINE_SEP_LEN)
Sys.dprint(" ", end="")
Sys.echo(" == KO == ", Sys.Clz.bg1 + Sys.Clz.fgb7)
Sys.dprint()
示例3: setDestFile
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import basename [as 别名]
def setDestFile(self, path):
""""""
if path is not None :
self.dst = ''.join([path, Sys.sep, '' if self.src is None else Sys.basename(self.src)])
if self.encmode:
self.dst = ''.join([self.dst, Kirmah.EXT if not self.splitmode else Kirmah.EXT_TARK])
else :
self.dst, ext = Sys.getFileExt(self.dst)
if not ext == (Kirmah.EXT if not self.splitmode else Kirmah.EXT_TARK):
self.dst += ext
#~ if Io.file_exists(self.dst):
#~ raise FileNeedOverwriteException(self.dst)
else : self.dst = None
示例4: build
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import basename [as 别名]
def build(self, nameFrom, nameTo, subject, filePath):
"""Build mail with attachment part
:Returns: 'email.message.Message'
"""
msg = MIMEMultipart()
msg['From'] = self.getHashName(nameFrom)+'@'+self.DOMAIN_NAME
msg['To'] = self.getHashName(nameTo)+'@'+self.DOMAIN_NAME
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = Header(subject,'utf-8')
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(filePath, 'rb').read())
encode_base64(part)
part.add_header('Content-Disposition','attachment; filename="%s"' % Sys.basename(filePath))
msg.attach(part)
return msg
示例5: onCommandEnc
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import basename [as 别名]
def onCommandEnc(self):
""""""
done = True
if self.o.outputfile is None :
self.o.outputfile = Sys.basename(self.a[1])
if self.o.outputfile[-len(Kirmah.EXT):] != Kirmah.EXT :
print(self.o.outputfile[-len(Kirmah.EXT):])
self.o.outputfile += Kirmah.EXT
print(self.o.outputfile)
d = self.getDefaultOption((self.o.compress,self.o.fullcompress,self.o.nocompress))
compress = (KirmahHeader.COMP_END if d == 0 or (d is None and Io.is_binary(self.a[1])) else (KirmahHeader.COMP_ALL if d==1 or d is None else KirmahHeader.COMP_NONE))
random = True if (self.o.random is None and self.o.norandom is None) or self.o.random else False
mix = True if (self.o.mix is None and self.o.nomix is None) or self.o.mix else False
if (self.o.multiprocess is not None and not represents_int(self.o.multiprocess)) or (not self.o.multiprocess is None and not(int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8)) :
self.parser.error_cmd((('invalid option ',('-j, --multiprocess', Sys.Clz.fgb3), ' value (', ('2',Sys.Clz.fgb3),' to ', ('8',Sys.Clz.fgb3),')'),))
nproc = int(self.o.multiprocess) if not self.o.multiprocess is None and int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8 else 1
if not Sys.g.QUIET : self.parser.print_header()
if Io.file_exists(self.o.outputfile) and not self.o.force:
Sys.pwarn((('the file ',(self.o.outputfile, Sys.Clz.fgb3), ' already exists !'),))
done = Sys.pask('Are you sure to rewrite this file')
self.stime = Sys.datetime.now()
if done :
try :
Sys.ptask()
key = Io.get_data(self.o.keyfile)
km = Kirmah(key, None, compress, random, mix)
km.encrypt(self.a[1], self.o.outputfile, nproc)
except Exception as e :
done = False
print(e)
raise e
pass
if not Sys.g.QUIET :
self.onend_cmd('Kirmah Encrypt', self.stime, done, self.o.outputfile)
示例6: onCommandSplit
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import basename [as 别名]
def onCommandSplit(self):
""""""
done = True
Sys.cli_emit_progress(1)
if not self.o.parts is None and not(int(self.o.parts)>=12 and int(self.o.parts) <=62) :
self.parser.error_cmd((('invalid option ',('-p, --parts', Sys.Clz.fgb3), ' value (', ('12',Sys.Clz.fgb3),' to ', ('62',Sys.Clz.fgb3),')'),))
else : self.o.parts = int(self.o.parts)
if not Sys.g.QUIET : self.parser.print_header()
if self.o.outputfile is not None :
if self.o.outputfile[-5:]!='.tark' : self.o.outputfile += '.tark'
if Io.file_exists(self.o.outputfile) and not self.o.force:
Sys.pwarn((('the file ',(self.o.outputfile, Sys.Clz.fgb3), ' already exists !'),))
done = Sys.pask('Are you sure to rewrite this file')
self.stime = Sys.datetime.now()
if done :
try :
Sys.ptask()
Sys.cli_emit_progress(2)
key = Io.get_data(self.o.keyfile)
km = Kirmah(key)
hlst = km.ck.getHashList(Sys.basename(self.a[1]), self.o.parts, True)
Sys.cli_emit_progress(3)
kcf = km.splitFile(self.a[1], hlst)
t = int(Sys.time())
times = (t,t)
p = 85
Sys.cli_emit_progress(p)
Io.touch(kcf, times)
frav = 0.24
for row in hlst['data']:
p += frav
Io.touch(row[1]+km.EXT,times)
Sys.cli_emit_progress(p)
if self.o.outputfile is not None :
d = Sys.datetime.now()
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Preparing tark file')
hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[4])
with tarfile.open(self.o.outputfile, mode='w') as tar:
tar.add(kcf, arcname=Sys.basename(kcf))
p = 90
for row in hlst['data']:
tar.add(row[1]+km.EXT, arcname=Sys.basename(row[1]+km.EXT))
p += frav
Sys.cli_emit_progress(p)
Sys.pstep('Packing destination file', d, True)
d = Sys.datetime.now()
Sys.ptask('Finalize')
for row in hlst['data']:
Io.removeFile(row[1]+km.EXT)
p += frav
Sys.cli_emit_progress(p)
Io.removeFile(kcf)
Sys.pstep('Cleaning', d, True)
except Exception as e :
done = False
if Sys.g.DEBUG :
print('split exception')
print(e)
#~ raise e
elif not Sys.g.QUIET :
Sys.pwarn((str(e),))
if not Sys.g.QUIET:
Sys.cli_emit_progress(100)
self.onend_cmd('Kirmah Split', self.stime, done, self.o.outputfile)