示例#1
0
 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
示例#2
0
 def save(self,path=None,notAssign=False):
     """"""
     path = path if path is not None else self.path
     Io.set_data(path, '# last updated : '+str(Sys.datetime.now())+Const.LF+self.toString())
     call = ' '.join(['python3', 'kirmah-cli.py', 'enc', '-qf', path, '-z', '-r', '-m', '-o', path+'.kmh', '-k', self.keyPath ])
     Sys.sysCall(call)
     Io.removeFile(path)
     if not notAssign : self.path = path
示例#3
0
 def encrypt(self, fromPath=None):
     """"""
     if fromPath is None :
         fromPath = self.pathPlain
     Sys.pwlog([(' Encrypt Index... ' , Const.CLZ_0, True)])
     Io.set_data(fromPath, jdumps(self.dic))        
     call = ' '.join([Sys.executable, 'kirmah-cli.py', 'enc', '-qfj2' if Sys.isUnix() else '-qf', fromPath, '-z', '-r', '-m', '-o', fromPath+Kirmah.EXT, '-k', self.keyPath ])
     #~ print(call)
     Sys.sysCall(call)
     Io.removeFile(fromPath)
     Sys.pwlog([(' done', Const.CLZ_2, True)])   
     return Io.get_data(fromPath+Kirmah.EXT, True)
示例#4
0
 def read(self):
     """"""
     try:
         call = ' '.join([Sys.executable, 'kirmah-cli.py', 'dec', '-qf', self.path+'.kmh', '-z', '-r', '-m', '-o', self.path, '-k', self.keyPath ])
         Sys.sysCall(call)            
         with Io.rfile(self.path, False) as fi:
             csection = 'main'
             self.dic[csection] = {}
             for l in fi:
                 l = l.rstrip().lstrip()
                 if len(l) > 0 and not l[0]=='#' :
                     d = regsplit(' *= *', l , 1)
                     if len(d)> 1:
                         self.dic[csection][d[0]] = d[1] if d[1] is not None else ''
                     elif len(l)>0 and l[0]=='[':
                         csection = l.strip('[]')
                         self.dic[csection] = {}
         Io.removeFile(self.path)
     except IOError :
         pass
示例#5
0
 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
示例#6
0
 def backupAddMap(self, data):
     """"""
     Io.set_data(self.addmapPath, jdumps(data))
     call = " ".join(
         [
             Sys.executable,
             "kirmah-cli.py",
             "enc",
             "-qf",
             self.addmapPath,
             "-z",
             "-r",
             "-m",
             "-o",
             self.addmapPath + Kirmah.EXT,
             "-k",
             self.idxu.index.keyPath,
         ]
     )
     print(call)
     Sys.sysCall(call)
     Io.removeFile(self.addmapPath)