本文整理汇总了Python中psr.sys.Sys.pwarn方法的典型用法代码示例。如果您正苦于以下问题:Python Sys.pwarn方法的具体用法?Python Sys.pwarn怎么用?Python Sys.pwarn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psr.sys.Sys
的用法示例。
在下文中一共展示了Sys.pwarn方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onCommandDec
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [as 别名]
def onCommandDec(self):
""""""
done = True
if self.o.outputfile is None :
self.o.outputfile = self.a[1][:-4] if self.a[1][-4:] == Kirmah.EXT else self.a[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 :
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
Sys.ptask()
key = Io.get_data(self.o.keyfile)
km = Kirmah(key)
km.decrypt(self.a[1], self.o.outputfile, nproc)
except BadKeyException:
done = False
Sys.pwarn((('BadKeyException : ',('wrong key ',Sys.CLZ_WARN_PARAM), ' !'),), False)
if not Sys.g.QUIET :
self.onend_cmd('Kirmah Decrypt', self.stime, done, self.o.outputfile)
示例2: main
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [as 别名]
def main():
try:
c = 0
Cli('.'+Sys.sep)
except Exception as e :
Sys.pwarn((('main : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True)
#~ raise e
c = 1
return c
示例3: main
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [as 别名]
def main():
try:
c = 0
AppGui()
except Exception as e:
Sys.pwarn((('main : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True)
raise e
c = 1
return c
示例4: halt_thread
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [as 别名]
def halt_thread(self, *args):
Sys.wlog(Sys.dprint())
Sys.pwarn(('thread interrupt',), False)
self.get('button1').set_sensitive(False)
if self.thkmh is not None and self.thkmh.isAlive():
self.thkmh.cancel()
else :
self.textbuffer.insert_at_cursor('Kmh Thread is not Alive\n')
self.on_proceed_end(True)
self.pb.hide()
self.show_log()
示例5: on_proceed_end
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [as 别名]
def on_proceed_end(self, abort=False):
""""""
try :
btn = self.get('button1')
btn.set_label('Proceed')
btn.set_sensitive(True)
self.PROCEED = False
if not abort : btn.set_label(conf.GUI_LABEL_OK)
self.get('checkbutton3').hide()
except Exception as e:
Sys.pwarn((('on_proceed_end : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),), False)
pass
return False
示例6: onCommandEnc
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [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)
示例7: onCommandKey
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [as 别名]
def onCommandKey(self):
""""""
if int(self.o.length) >= 128 and int(self.o.length) <= 4096 :
self.parser.print_header()
if not self.o.outputfile : self.o.outputfile = self.home+'.kirmah'+Sys.sep+'.default.key'
kg = KeyGen(int(self.o.length))
done = True
if Io.file_exists(self.o.outputfile) and not self.o.force :
Sys.pwarn((('the key file ',(self.o.outputfile, Sys.Clz.fgb3), ' already exists !'),
'if you rewrite this file, all previous files encrypted with the corresponding key will be unrecoverable !'))
done = Sys.pask('Are you sure to rewrite this file')
self.stime = Sys.datetime.now()
if done :
Io.set_data(self.o.outputfile, kg.key)
Sys.pstep('Generate key file', self.stime, done)
if done :
Sys.print(' '*5+Sys.realpath(self.o.outputfile), Sys.Clz.fgB1, True)
else :
self.parser.error_cmd((('invalid option ',('-l, --length', Sys.Clz.fgb3), ' value (', ('128',Sys.Clz.fgb3),' to ', ('4096',Sys.Clz.fgb3),')'),))
示例8: onCommandMerge
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [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)
示例9: onCommandSplit
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [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)
示例10: run
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [as 别名]
def run(self):
""""""
self.cancelled = False
self.evtStop.clear()
Sys.g.THREAD_CLI = self
Sys.g.GUI = True
Sys.g.GUI_PRINT_STDOUT = True
done = False
self.can_retry = True
init(conf.PRG_NAME, Sys.g.DEBUG, loglvl=Const.LOG_APP)
try :
if self.impst is None :
label = ' [[ INIT IMPRASTORAGE ]] '
label = ' '+'~'*((Const.LINE_SEP_LEN-len(label))//2-1)+label+'~'*((Const.LINE_SEP_LEN-len(label))//2-1)+' '
Sys.pwlog([(Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0 , True),
(label.ljust(Const.LINE_SEP_LEN, ' ') , Const.CLZ_INIT , True),
(Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0 , True)])
self.impst = ImpraStorage(self.conf, wkdir='.'+Sys.sep+'wk'+Sys.sep)
done = True
except Exception as e :
self.emit('needconfig')
raise e
self.emit('indexrefreshed', done)
if done :
while not self.evtStop.is_set() or not self.cancelled:
with self.condition :
self.condition.wait_for(lambda : not self.taskQueue.empty(), 2)
if self.can_retry and self.impst.hasBackupAddMap():
self.emit('hasaddretry')
self.can_retry = False
if not self.taskQueue.empty():
task, params, idtask = self.taskQueue.get_nowait()
label = ' [[ TASK '+str(idtask)+' : '+self.TASK_LABEL[task].upper()+' ]] '
label = ' '+'>'*((Const.LINE_SEP_LEN-len(label))//2-1)+label+'<'*((Const.LINE_SEP_LEN-len(label))//2-1)+' '
Sys.pwlog([(Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0 , True),
(label.ljust(Const.LINE_SEP_LEN, ' ') , Const.CLZ_ACTION, True),
(Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0 , True)])
try:
if task is self.TASK_WAIT :
print('wait')
Sys.sleep(params)
elif task is self.TASK_GET:
#~ mg = Manager(self.taskGet, 1, None, Sys.g.MPEVENT, uid=params)
#~ mg.run()
#~ self.emit('fileget', True, '')
#~ Thread(target=self.taskGet, name='impra-1', kwargs={'uid':params}).start()
print(params)
self.taskGet(params)
elif task is self.TASK_ADD:
self.taskAdd(params)
elif task is self.TASK_ADD_RETRY:
self.taskAddRetry(params)
elif task is self.TASK_REFRESH:
self.taskRefresh(params)
elif task is self.TASK_INFOS:
self.taskInfos(params)
elif task is self.TASK_REMOVE:
self.taskRemove(params)
elif task is self.TASK_EDIT:
self.taskEdit(params)
self.taskQueue.task_done()
except self.impst.SocketError() as e :
Sys.pwarn((('ImpraThread.run : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),))
self.impst.reconnect()
except Exception as e:
print(type(e))
Sys.pwarn((('ImpraThread.run : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),))
else :
""""""
Sys.sleep(0.5)
self.emit('completed')
示例11: sendFile
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [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)
#.........这里部分代码省略.........
示例12: error_cmd
# 需要导入模块: from psr.sys import Sys [as 别名]
# 或者: from psr.sys.Sys import pwarn [as 别名]
def error_cmd(self, data, pusage=False):
""""""
if pusage : self.print_usage('')
Sys.dprint()
Sys.pwarn(data, True)
AbstractCli.exit(1)