本文整理汇总了Python中psr.sys.Io.file_exists方法的典型用法代码示例。如果您正苦于以下问题:Python Io.file_exists方法的具体用法?Python Io.file_exists怎么用?Python Io.file_exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psr.sys.Io
的用法示例。
在下文中一共展示了Io.file_exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def __init__(self, path, keyPath=None):
""""""
self.path = path
self.dic = {}
self.keyPath = path+'.key' if keyPath is None else keyPath
if not Io.file_exists(self.keyPath) :
kg = KeyGen()
Io.set_data(self.keyPath, kg.key)
if not Io.file_exists(path) :
self.set('profile' , 'default', 'main')
self.set('key' ,kg.key,'default.keys')
self.set('mark' ,kg.mark,'default.keys')
self.set('salt' ,'-*-ImpraStorage-*-','default.keys')
self.save()
self.read()
示例2: selectKey
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def selectKey(self, filename):
""""""
print('selectKey : ')
print(filename)
if not Io.file_exists(filename):
raise FileNotFoundException(filename)
self.kpath = filename
示例3: onCommandDec
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [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)
示例4: on_proceed
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def on_proceed(self, btn):
""""""
if btn.get_label() == conf.GUI_LABEL_OK :
btn.set_label(conf.GUI_LABEL_PROCEED)
self.PROCEED = False
self.pb.hide()
self.show_log()
else :
if not self.PROCEED :
self.PROCEED = True
self.STOPPED = False
btn.set_sensitive(False)
self.app.setDestFile(self.get('filechooserbutton3').get_filename())
if not Io.file_exists(self.app.dst) or self.warnDialog('file '+self.app.dst+' already exists', 'Overwrite file ?'):
self.pb = self.get('progressbar1')
self.pb.set_fraction(0)
self.pb.show()
self.pb.pulse()
btn.set_sensitive(True)
btn.set_label(conf.GUI_LABEL_CANCEL)
self.clear_log(self.get('checkbutton3'))
self.show_log()
self.launch_thread()
else :
self.on_proceed_end(True)
else :
self.halt_thread()
示例5: getBackupAddMap
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def getBackupAddMap(self):
""""""
data = None
if Io.file_exists(self.addmapPath + Kirmah.EXT):
call = " ".join(
[
Sys.executable,
"kirmah-cli.py",
"dec",
"-qf",
self.addmapPath + Kirmah.EXT,
"-z",
"-r",
"-m",
"-o",
self.addmapPath,
"-k",
self.idxu.index.keyPath,
]
)
print(call)
Sys.sysCall(call)
data = jloads(Io.get_data(self.addmapPath))
Io.removeFile(self.addmapPath)
return data
示例6: createDefaultKeyIfNone
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def createDefaultKeyIfNone(self):
""""""
kpath = self.getDefaultKeyPath()
if not Io.file_exists(kpath):
if Sys.isUnix():
if not Sys.isdir(conf.DEFVAL_UKEY_PATH):
Sys.mkdir_p(conf.DEFVAL_UKEY_PATH)
Io.set_data(kpath, KeyGen(conf.DEFVAL_UKEY_LENGHT).key)
self.selectKey(kpath)
示例7: getKeyInfos
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def getKeyInfos(self, filename=None):
""""""
if filename is None:
filename = self.getDefaultKeyPath()
if not Io.file_exists(filename):
raise FileNotFoundException(filename)
k = Io.get_data(filename)
s = len(k)
m = KeyGen(s).getMark(k)
return k, s, m
示例8: get
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def get(self, forceRefresh=False):
""""""
self.switchFileAccount(self.conf.profile)
index = None
uid = self.conf.get('uid' ,'index')
date = self.conf.get('date' ,'index')
tstamp = self.conf.get('time' ,'index')
refresh = forceRefresh
delta = None if tstamp is None else Sys.datetime.now() - Sys.datetime.strptime(tstamp[:-7], '%Y-%m-%d %H:%M:%S')
if not refresh and tstamp is not None and delta < Sys.timedelta(minutes = 3) :
# getFromFile
if uid != None and Io.file_exists(self.pathIdx): # int(self.idx) == int(uid)
self.idx = uid
Sys.pwlog([(' Get index from cache ' , Const.CLZ_7),
('(' , Const.CLZ_0),
(str(int(self.idx)) , Const.CLZ_2),
(')' , Const.CLZ_0, True)])
else: refresh = True
else: refresh = True
self.irefresh = refresh
if refresh :
Sys.pwlog([(' Checking index...', Const.CLZ_0, True)])
self._getId()
if self.idx :
if int(self.idx) != int(uid) or not Io.file_exists(self.pathIdx):
Sys.pwlog([(' Refreshing index (local:', Const.CLZ_0),
(str(int(uid)) , Const.CLZ_2),
(' / remote:' , Const.CLZ_0),
(str(int(self.idx)) , Const.CLZ_1),
(')' , Const.CLZ_0, True)])
date = self.ih.headerField(self.idx, 'date', True)
self.conf.sets((['uid' , str(int(self.idx)) , 'index'],
['date' , date , 'index'],
['time' , str(Sys.datetime.now()), 'index']))
self._saveLocalIndex()
else :
Sys.pwlog([(' Get index from cache ' , Const.CLZ_7),
('(' , Const.CLZ_0),
(str(int(self.idx)) , Const.CLZ_2),
(')' , Const.CLZ_0, True)])
self.conf.set('time',str(Sys.datetime.now()),'index')
self.build()
示例9: createDefaultKeyIfNone
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def createDefaultKeyIfNone(self):
""""""
kpath = self.getDefaultKeyPath()
if not Io.file_exists(kpath):
#if Sys.isUnix() :
if not Sys.isdir(conf.DEFVAL_UKEY_PATH) :
Sys.mkdir_p(conf.DEFVAL_UKEY_PATH)
k = KeyGen(conf.DEFVAL_UKEY_LENGHT)
print(k)
content = k.key
print('content')
Io.set_data(kpath, content)
print('set content')
self.selectKey(kpath)
示例10: onCommandEnc
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [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)
示例11: onCommandAdd
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [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()
示例12: decrypt
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def decrypt(self, fromPath=None):
""""""
done = False
try :
if fromPath is None :
fromPath = self.path
toPath = fromPath[:-len(Kirmah.EXT)] if fromPath.endswith(Kirmah.EXT) else fromPath+'.dump'
if Io.file_exists(fromPath) :
Sys.pwlog([(' Decrypt Index... ' , Const.CLZ_0, True)])
call = ' '.join([Sys.executable, 'kirmah-cli.py', 'dec', '-qfj2' if Sys.isUnix() else '-qf', fromPath, '-z', '-r', '-m', '-o', toPath, '-k', self.keyPath ])
print(call)
Sys.sysCall(call)
data = jloads(Io.get_data(toPath))
Io.removeFile(toPath)
else :
data = {}
done = True
except ValueError as e:
raise BadKeyException(e)
Sys.pwlog([(' done'if done else ' ko' , Const.CLZ_2 if done else Const.CLZ_1, True)])
return data
示例13: __init__
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def __init__(self, home, path, parser, Cli, a, o):
""""""
self.parser = parser
self.Cli = Cli
self.a = a
self.o = o
self.home = home
self.stime = Sys.datetime.now()
self.account = "default"
self.rootBox = "__impra__2"
self.uid = "0"
self.date = ""
if not Io.file_exists("impra2.ini" + Kirmah.EXT):
print("ini file not exist")
if len(self.a) > 0 and self.a[0] == "conf" and self.o.save:
kg = KeyGen()
Io.set_data("impra2.ini.key", kg.key)
self.ini = KiniFile("impra2.ini")
self.ini.set("key", kg.key, self.account + ".keys")
self.ini.set("mark", kg.mark, self.account + ".keys")
self.ini.set("salt", "-¤-ImpraStorage-¤-", self.account + ".keys")
else:
self.needConfig()
else:
if not (len(self.a) > 0 and self.a[0] == "conf"):
self.ini = KiniFile("impra2.ini")
self.impst = ImpraStorage(ImpraConf(self.ini), wkdir=path)
self.uid = self.impst.idxu.conf.get("uid", "index")
self.date = self.impst.idxu.conf.get("date", "index")
self.account = self.impst.idxu.conf.get("user", "imap")
self.rootBox = self.impst.rootBox
if self.impst.idxu.index != None:
noData = self.impst.idxu.index.isEmpty()
if self.uid == None or noData:
self.uid = "EMPTY"
if self.date == None or noData:
self.date = ""
else:
self.ini = KiniFile("impra2.ini")
示例14: __init__
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [as 别名]
def __init__(self, key, path, dicCategory={}, accountList={}, emit=False):
"""Initialize the index with rsa and encoded data
:Parameters:
`key` : str
appropriate key to decrypt/encrypt data
`mark` : str
appropriate mark to check correct key
`encdata` : str
initial content of the index encrypted with Kirmah Algorythm
and representing a dic index as json string
"""
self.pathPlain = path[:-len(Kirmah.EXT)]
self.keyPath = self.pathPlain+self.KEY_EXT
self.path = path
Io.set_data(self.keyPath, key)
self.dic = {}
self.acclist = accountList
encdata = Io.get_data(path, True) if Io.file_exists(path) else b''
if encdata == b'' :
self.dic = {}
self.id = 1
else :
self.dic = self.decrypt(path)
l = [self.dic[k][self.UID] for i, k in enumerate(self.dic) if not k.startswith(self.SEP_KEY_INTERN)]
if len(l) > 0 :
self.id = max(l)+1
else: self.id = 1
for k in dicCategory :
if k == 'users' :
for k1 in dicCategory[k]:
if self.SEP_KEY_INTERN+k in self.dic:
if k1 not in self.dic[self.SEP_KEY_INTERN+k]:
self.dic[self.SEP_KEY_INTERN+k][k1] = dicCategory[k][k1]
else :
if not self.SEP_KEY_INTERN+k in self.dic:
self.dic[self.SEP_KEY_INTERN+k] = dicCategory[k]
示例15: onCommandKey
# 需要导入模块: from psr.sys import Io [as 别名]
# 或者: from psr.sys.Io import file_exists [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),')'),))