From 6a81cdd89a076a000b5277ae76b778b4de02ada4 Mon Sep 17 00:00:00 2001 From: a-sansara Date: Fri, 21 Sep 2012 19:12:30 +0200 Subject: [PATCH] manage cli messages commands, add size, remove command, colors in printing inifile --- impra/cli.py | 156 +++++++++++++++++++++-------- impra/core.py | 261 +++++++++++++++++++++++++++++++++--------------- impra/imap.py | 17 +++- impra/util.py | 47 +++++++-- imprastorage.py | 25 +---- 5 files changed, 347 insertions(+), 159 deletions(-) diff --git a/impra/cli.py b/impra/cli.py index 400e456..ea3401f 100644 --- a/impra/cli.py +++ b/impra/cli.py @@ -66,10 +66,10 @@ ImpraStorage randomly upload each parts then update the index. def printLineSep(sep,lenSep): """""" - Clz.print(sep*lenSep, Clz.fgB0) + Clz.print(sep*lenSep, Clz.fgN0) def printHeaderTitle(title): """""" - Clz.print(' -- %s -- ' % title, Clz.BG4+Clz.fgB7, False, True) + Clz.print(' == '+title+' == ', Clz.BG4+Clz.fgB7, False, True) def printHeaderPart(label,value): """""" @@ -169,6 +169,7 @@ data command Examples: gpData.add_option('-r', '--remove' , help='remove FILE with specified ID from server' , action='store', metavar='ID ') gpData.add_option('-c', '--category' , help='set specified CATEGORY (crit. for opt. -l,-a or -s)' , action='store', metavar='CATG ' , default='') gpData.add_option('-u', '--user' , help='set specified USER (crit. for opt. -l,-a or -s)' , action='store', metavar='OWNER ' , default='all') + gpData.add_option('-o', '--order' , help='set colon ORDER (crit. for opt. -l and -s)' , action='store', metavar='ORDER ' , default='ID') #gpData.add_option('-o', '--output-dir' , help='set specified OUTPUT DIR (for opt. -l,-a,-d or -g)' , action='store', metavar='DIR ') parser.add_option_group(gpData) @@ -186,9 +187,63 @@ data command Examples: parser.add_option_group(gpConf) (o, a) = parser.parse_args() - - +# USAGE : +# +# imprastorage add {filePath} [{name} -c {category} -u {owner}] +# imprastorage list [-o {colon}, -c {category} -u {owner}] +# imprastorage get {id|ids} | -n {name} +# imprastorage remove {id} | -n {name} +# imprastorage search {pattern} [-c {category} -u {owner} -o {colon}] +# imprastorage conf [-A profileName] -L | -V | +# -S [-K, -H {host}, -U {user}, -X {password}, -P {port}, -B {box}, -N {name}] +# +# EXEMPLES : +# +# command add : +# imprastorage add /home/Share/2009-mountains.avi +# imprastorage add /home/Share/2009-mountains.avi 'summer 2009 - in mountains' +# imprastorage add /home/Share/2009-mountains.avi -u family +# imprastorage add /home/Share/2009-mountains.avi -c videos/perso/2009 +# imprastorage add /home/Share/2009-mountains.avi 'summer 2009 - in mountains' -c videos/perso/2009 -u family +# +# command list : +# imprastorage list +# imprastorage list -o LABEL +# imprastorage list -c videos/perso +# imprastorage list -u family +# imprastorage list -o SIZE -c videos/perso -u family +# +# command get : +# imprastorage get 15 +# imprastorage get 15-19 +# imprastorage get 22,29,30 +# imprastorage get 22,29,30-35,48 +# imprastorage get -n 'summer 2009 - in mountains' +# +# command remove : +# imprastorage remove 15 +# imprastorage remove -n 'summer 2009 - in mountains' +# +# command search : +# imprastorage search 'mountains' +# imprastorage search 'mountains' -c videos/perso +# imprastorage search 'mountains' -u family +# imprastorage search 'mountains' -o LABEL +# imprastorage search 'mountains' -c videos/perso -u family -o LABEL +# imprastorage search '^mountains' +# imprastorage search 'mountains$' +# +# command conf : +# imprastorage conf -L +# imprastorage conf -LA bobgmail +# imprastorage conf -V +# imprastorage conf -VA bobgmail +# imprastorage conf -S -K +# imprastorage conf -SA bobgmail -K +# imprastorage conf -SA bobgmail -K -H imap.gmail.com -U bob22 -X mypassword -N bob +# + print() if not a: parser.print_help() print() @@ -204,8 +259,6 @@ data command Examples: if self.ini.has('profile') : o.active_profile = self.ini.get('profile') else : o.active_profile = 'default' - print(self.ini) - if o.load_conf : self.load_profile(o) elif o.list_conf : print(self.ini.toString(o.active_profile)) @@ -231,7 +284,7 @@ data command Examples: if self.check_profile(o.active_profile): self.ini.set('profile', o.active_profile) self.ini.write() - print(self.ini.toString(o.active_profile)) + self.ini.print(o.active_profile) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~ data CMD ~~ @@ -249,20 +302,26 @@ data command Examples: try: impst = core.ImpraStorage(conf) except crypt.BadKeyException as e : - print('Error : ') - print(e) - print(""" -it seems that your current profile %s has a wrong key to decrypt index on server. -you can remove index but all presents files on the box %s will be unrecoverable -""" % (o.active_profile, conf.get('box','imap'))) - remIndex = input('remove index ? (yes/no)') + print() + Clz.print(' it seems that your current profile `' , Clz.fgB1, False) + Clz.print(o.active_profile , Clz.fgB3, False) + Clz.print('` has a wrong key to decrypt index on server.' , Clz.fgB1) + Clz.print(' you can remove index but all presents files on the box `', Clz.fgB1, False) + Clz.print(conf.get('box','imap') , Clz.fgB3, False) + Clz.print('` will be unrecoverable\n' , Clz.fgB1, True, False) + + remIndex = input(' remove index ? (yes/no) ') if remIndex.lower()=='yes': + Clz.print(' ',Clz.OFF) impst = core.ImpraStorage(conf, True) + else : - print('bye') + print() + print(' bye') + print() sys.exit(1) - if o.list : + if o.list : uid = conf.get('uid' ,'index') date = conf.get('date','index') account = conf.get('user','imap') @@ -278,18 +337,14 @@ you can remove index but all presents files on the box %s will be unrecoverable printHeaderPart('box',impst.rootBox) Clz.print(date, Clz.fgB7, True, True) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) - impst.index.print() + impst.index.print(o.order) - status, resp = impst.ih.srv.search(None, '(SUBJECT "%s")' % '584d15abeb71fbd92fa5861970088b32ebb1d2d6650cec6115a28b64877d70f2') - ids = [m for m in resp[0].split()] - for mid in ids : - status, resp = impst.ih.srv.fetch(mid,'(UID RFC822.SIZE)') - print(mid,status,resp) - elif o.add : done = impst.addFile(o.add[0],o.add[1],o.user,o.category) if done : - print('OK') + print('\n ',end='') + Clz.print(' == OK == ', Clz.bg2+Clz.fgb7) + print() elif o.get : ids = [] @@ -302,31 +357,50 @@ you can remove index but all presents files on the box %s will be unrecoverable if key !=None : done = impst.getFile(key) if done : - print('OK') - else: print('-- `%s` is not a valid id --' % sid) + print('\n ',end='') + Clz.print(' == OK == ', Clz.bg2+Clz.fgb7) + print() + else: + print('\n ',end='') + Clz.print(' == `' , Clz.bg1+Clz.fgB7, False) + Clz.print(str(sid) , Clz.bg1+Clz.fgB3, False) + Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7) + print() elif o.search : matchIds = impst.index.getByPattern(o.search) if matchIds is not None: - headstr = '-'*120+'\n -- SEARCH: `'+o.search+'` -- found '+str(len(matchIds))+' results --\n'+'-'*120 - impst.index.print(headstr,matchIds) + printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) + printHeaderTitle('SEARCH') + Clz.print(' `'+o.search+'`' , Clz.fgB7, False) + Clz.print(' -- found ' , Clz.fgB3, False) + Clz.print(str(len(matchIds)), Clz.fgB1, False) + Clz.print(' results --' , Clz.fgB3) + printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) + impst.index.print(o.order,matchIds) else: - print(' -- no match found for pattern `%s` --' % o.search) + print('\n ',end='') + Clz.print(' == no match found for pattern `', Clz.bg3+Clz.fgB4, False) + Clz.print(o.search , Clz.bg3+Clz.fgB1, False) + Clz.print('` == ' , Clz.bg3+Clz.fgB4) + print() elif o.remove : - print(o.remove) - - #~ filePath = '/media/Data/dev/big_toph3.jpg' - #~ lab = 'Meuf\'bonne aussi4' - #~ print('\n -- ADD FILE -- ') - #~ impst.addFile(filePath,lab,conf.get('name','infos'),'images') - - #~ else : - #~ self.load_profile(o) - #~ print('data cmd') - #~ print(o) + key = impst.index.getById(o.remove) + if key !=None : + done = impst.removeFile(key) + if done : + print('\n ',end='') + Clz.print(' == OK == ', Clz.bg2+Clz.fgb7) + print() + else: + print('\n ',end='') + Clz.print(' == `' , Clz.bg1+Clz.fgB7, False) + Clz.print(str(o.remove) , Clz.bg1+Clz.fgB3, False) + Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7) + print() else : parser.print_help() - + print() def check_profile(self,profile): diff --git a/impra/core.py b/impra/core.py index c27bd7a..7a0b206 100644 --- a/impra/core.py +++ b/impra/core.py @@ -92,7 +92,12 @@ class FSplitter : m = mmap(f.fileno(), 0) p = 0 psize = ceil(getsize(fromPath)/hlst['head'][1]) - print(formatBytes(getsize(fromPath))+' on '+str(len(hlst['data']))+' parts (~'+formatBytes(psize)+')') + Clz.print(' '+formatBytes(getsize(fromPath)), Clz.fgB2, False) + Clz.print(' on ' , Clz.fgn7, False) + Clz.print(str(len(hlst['data'])) , Clz.fgB1, False) + Clz.print(' parts (~' , Clz.fgn7, False) + Clz.print(formatBytes(psize) , Clz.fgB2, False) + Clz.print(')' , Clz.fgn7) while m.tell() < m.size(): self._splitPart(m,p,psize,hlst['data'][p]) p += 1 @@ -124,8 +129,11 @@ class FSplitter : else: dirPath = self.DIR_DEPLOY filePath = dirPath+fileName - if file_exists(filePath+ext): - print('\n-- `%s` already exist, deploying file as :\n-- `%s`\n' % (filePath+ext,filePath+'-'+str(uid)+ext)) + if file_exists(filePath+ext): + Clz.print('\n name already exist, deploying file as :' , Clz.fgB1) + Clz.print(' '+basename(filePath) , Clz.fgB2, False) + Clz.print('-'+str(uid) , Clz.fgB1, False) + Clz.print(ext , Clz.fgB2) filePath += '-'+str(uid) filePath += ext @@ -137,7 +145,7 @@ class FSplitter : p += 1 fp.close() rt.stop() - return dirPath+fileName+ext + return filePath def _mergePart(self,fp,part,phlst,depDir): """""" @@ -182,7 +190,6 @@ class ImpraConf: self.set('types', 'music,films,doc,images,archives,games','catg') if save : self.ini.write() - #print(self.ini.toString()) def get(self, key, section='main', profile=None): """""" @@ -228,8 +235,6 @@ class ImpraIndex: SEP_KEY_INTERN = '@' """Separator used for internal key such categories""" - MD5 = 7 - """""" HASH = 0 """""" LABEL = 1 @@ -246,10 +251,14 @@ class ImpraIndex: """""" BFLAG = 7 """""" - + SIZE = 8 + """""" FILE_BINARY = 'b' + """""" FILE_CRYPT = 'c' - + """""" + COLS = ('HASH','LABEL','PART','TYPE','OWNER','CATEGORY','ID','BLFAG','SIZE') + """""" def __init__(self, key, mark, encdata='', dicCategory={}, id=0): """Initialize the index with rsa and encoded data @@ -272,11 +281,11 @@ class ImpraIndex: if not self.SEP_KEY_INTERN+k in self.dic: self.dic[self.SEP_KEY_INTERN+k] = dicCategory[k] - def add(self,key, label, count, ext='', usr='', cat='', md5='', bFlag='b'): + def add(self,key, label, count, ext='', usr='', cat='', md5='', bFlag='b', size=''): """Add an entry to the index """ if self.get(md5) == None : - self.dic[md5] = (key,label,count,ext,usr,cat, self.id, bFlag) + self.dic[md5] = (key,label,count,ext,usr,cat,self.id,bFlag,size) self.id +=1 else : print(label+' already exist') @@ -390,34 +399,37 @@ class ImpraIndex: raise BadKeyException(e) return data - def print(self,header='', matchIds=None): + def print(self,order='ID', matchIds=None): """Print index content as formated bloc""" #clear() - if header is not '':print(header) from impra.cli import printLineSep, LINE_SEP_LEN, LINE_SEP_CHAR - #printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) + orderIndex = self.COLS.index(order) + if orderIndex is None : orderIndex = self.COLS.index('ID') + Clz.print(' ID'+' '*1, Clz.BG4+Clz.fgB7, False, False) - print('HASH' +' '*15, end='') - print('LABEL' +' '*38, end='') + print('HASH' +' '*6 , end='') + print('LABEL' +' '*35, end='') + print('SIZE' +' '*5 , end='') print('PART' +' '*2 , end='') print('TYPE' +' '*2 , end='') - print('OWNER' +' '*12, end='') - Clz.print('CATEGORY'+' '*17, Clz.BG4+Clz.fgB7) + print('OWNER' +' '*10, end='') + Clz.print('CATEGORY'+' '*22, Clz.BG4+Clz.fgB7) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) - data = '' - r = [k for i, k in enumerate(self.dic) if not k.startswith(self.SEP_KEY_INTERN)] - for k in r : - v = self.dic.get(k) - k = k.lstrip('\n\r') - if not k[0]==self.SEP_KEY_INTERN and len(k)>1: - if matchIds==None or v[self.UID] in matchIds: - Clz.print(str(v[self.UID]).rjust(1+ceil(len(str(v[self.UID]))/10),' ') +' '*2, Clz.fgB1, False) - Clz.print(str(k)[0:12]+'... ' +' '*2, Clz.fgn2, False) - Clz.print(str(v[self.LABEL]).ljust(42,' ') +' '*2, Clz.fgB7, False) - Clz.print(str(v[self.PARTS]).rjust(2 ,'0') +' '*2, Clz.fgB5, False) - Clz.print(str(v[self.EXT]).ljust(5,' ') +' '*2, Clz.fgB4, False) - Clz.print(self.getUser(str(v[self.OWNER])).ljust(15,' ') +' '*2, Clz.fgB7, False) - Clz.print(str(v[self.CATG]) +' '*2, Clz.fgB4) + + d = sorted([(self.dic.get(k),k) for i, k in enumerate(self.dic) if not k.startswith(self.SEP_KEY_INTERN)], key=lambda lst:lst[0][orderIndex]) + a = '' + for v,k in d : + if matchIds==None or v[self.UID] in matchIds: + a = '' + Clz.print(str(v[self.UID]).rjust(1+ceil(len(str(v[self.UID]))/10),' ')+' ', Clz.bg1+Clz.fgB7, False) + Clz.print(' '+str(k)[0:6]+'... ' ,Clz.fgN2, False) + if len(v[self.LABEL])>36 : a = '...' + Clz.print(str(v[self.LABEL][:36]+a).ljust(40,' ') ,Clz.fgN7, False) + Clz.print(formatBytes(int(v[self.SIZE]))[:8].ljust(10,' '),Clz.fgN5, False) + Clz.print(str(v[self.PARTS]).rjust(2 ,'0') +' '*2 ,Clz.fgN1, False) + Clz.print(str(v[self.EXT][:5]).ljust(7,' ') ,Clz.fgn3, False) + Clz.print(self.getUser(str(v[self.OWNER])).ljust(15,' ') ,Clz.fgn7, False) + Clz.print(str(v[self.CATG]) +' '*2 ,Clz.fgN3) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) @@ -497,9 +509,11 @@ class ImpraStorage: if uid != None and file_exists(self.pathInd): # int(self.idx) == int(uid) self.idx = uid encData = get_file_content(self.pathInd) + Clz.print(' get index from cache', Clz.fgn7) else: refresh = True else: refresh = True if refresh : + Clz.print(' refreshing index', Clz.fgn7) self._getIdIndex() if self.idx : encData = self._getCryptIndex() @@ -555,6 +569,12 @@ class ImpraStorage: with open(path, mode='w') as o: o.write(data) + def checkSendIds(self,sendIds,subject): + """""" + lloc = [bytes(str(data[0]),'utf-8') for mid, data in enumerate(sendIds)] + lsrv = self.ih.searchBySubject(subject,True) + return [ i for i in set(lloc).difference(set(lsrv))] + def addFile(self, path, label, usr='all', catg=''): """""" done = False @@ -563,73 +583,136 @@ class ImpraStorage: _, ext = splitext(path) - try: - md5 = hash_md5_file(path) - print('--\nmd5sum `%s` %s' % (path,md5)) - if not self.index.get(md5) : - - if catg=='' : catg = self.index.getAutoCatg(ext) - - bFlag = ImpraIndex.FILE_BINARY - if not is_binary(path): - bFlag = ImpraIndex.FILE_CRYPT - path = self.encryptTextFile(path) + try: + size = getsize(path) + if size > 0 : + md5 = hash_md5_file(path) + print() + Clz.print(' file : ' , Clz.fgn7, False) + Clz.print(path , Clz.fgN1) + Clz.print(' md5sum : ' , Clz.fgn7, False) + Clz.print(md5 , Clz.fgN2) + print() + if not self.index.get(md5) : - hlst = self.fsplit.addFile(path,md5) - if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : - print(hlst['head']) - for v in hlst['data']: - print(v) - - ownerHash = self.mb.getHashName(usr) - self.index.addUser(usr,ownerHash) + if catg=='' : catg = self.index.getAutoCatg(ext) + + bFlag = ImpraIndex.FILE_BINARY + if not is_binary(path): + bFlag = ImpraIndex.FILE_CRYPT + path = self.encryptTextFile(path) + + hlst = self.fsplit.addFile(path,md5) + if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : + print(hlst['head']) + for v in hlst['data']: + print(v) + + ownerHash = self.mb.getHashName(usr) + self.index.addUser(usr,ownerHash) - cancel = False - sendIds = [] - test = True - for row in hlst['data'] : - msg = self.mb.build(self.conf.get('name','infos'),usr,hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr') - mid = self.ih.send(msg.as_string(), self.rootBox) - if mid is not None : - print('part %s sent as msg %s' % (row[0],mid[1])) - sendIds.append((mid[1],row)) - remove(self.fsplit.DIR_OUTBOX+row[1]+'.ipr') - else: - print('\n-- error occured when sending part : %s\n-- retrying' % row[0]) + cancel = False + sendIds = [] + test = True + for row in hlst['data'] : + msg = self.mb.build(self.conf.get('name','infos'),usr,hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr') mid = self.ih.send(msg.as_string(), self.rootBox) if mid is not None : - print('part %s sent as msg %s' % (row[0],mid[1])) + print(' ',end='') + Clz.print(' part ' , Clz.fgn7, False) + Clz.print(str(row[0]) , Clz.fgB1, False) + Clz.print(' sent as msg ', Clz.fgn7, False) + Clz.print(str(mid[1]) , Clz.fgB1) sendIds.append((mid[1],row)) - remove(self.fsplit.DIR_OUTBOX+row[1]+'.ipr') - else: - print('\n-- can\'t send part %s\n-- cancelling ' % row[0]) - cancel = True - break - - if cancel : + else: + print('\n-- error occured when sending part : %s\n-- retrying' % row[0]) + mid = self.ih.send(msg.as_string(), self.rootBox) + if mid is not None : + print('part %s sent as msg %s' % (row[0],mid[1])) + sendIds.append((mid[1],row)) + else: + print('\n-- can\'t send part %s\n-- cancelling ' % row[0]) + cancel = True + break + print() + if not cancel : + self.index.add(hlst['head'][3],label,hlst['head'][1],ext,ownerHash,catg,md5,bFlag,size) + done = self.saveIndex() + self.conf.set('nid', str(self.index.id),'index') + diff = self.checkSendIds(sendIds,hlst['head'][2]) + if len(diff) > 0 : + Clz.print(' error when sending, missing parts :', Clz.fgB1) + print(diff) + for mid, row in sendIds : + msg = self.mb.build(self.conf.get('name','infos'),usr,hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr') + Clz.print(' resending part ' , Clz.fgn7, False) + Clz.print(str(row[0]) , Clz.fgN2, False) + mid = self.ih.send(msg.as_string(), self.rootBox) + else : + print() + #Clz.print(' index intall files checked\n', Clz.fgB2) + + + # clean for mid, row in sendIds : - self.ih.delete(mid, True) + if cancel : self.ih.delete(mid, True) if file_exists(self.fsplit.DIR_OUTBOX+row[1]+'.ipr') : remove(self.fsplit.DIR_OUTBOX+row[1]+'.ipr') self.clean() - + else : - self.index.add(hlst['head'][3],label,hlst['head'][1],ext,ownerHash,catg,md5,bFlag) - done = self.saveIndex() - self.conf.set('nid', str(self.index.id),'index') + print(' ',end='') + Clz.print(' == file already exist on server as ' , Clz.fgN7+Clz.bg1, False) + Clz.print(self.index.dic[md5][ImpraIndex.LABEL] , Clz.bg1+Clz.fgB3, False) + Clz.print(' [id:' , Clz.fgN7+Clz.bg1, False) + Clz.print(str(self.index.dic[md5][ImpraIndex.UID]) , Clz.bg1+Clz.fgB3, False) + Clz.print('] == ' , Clz.fgN7+Clz.bg1) + print() else : - print('--\nfile already exist on server as `%s` [id:%i]\n' % (self.index.dic[md5][ImpraIndex.LABEL],self.index.dic[md5][ImpraIndex.UID])) + print(' ',end='') + Clz.print(' == files is empty or don\t exists == ' , Clz.bg1+Clz.fgN7) + print() + except Exception as e : print(e) rt.stop() return done + def removeFile(self,key): + """""" + from impra.util import DEBUG, DEBUG_LEVEL, DEBUG_NOTICE, DEBUG_WARN, DEBUG_INFO + done = False + row = self.index.get(key) + if row==None : + print() + Clz.print(' == `' , Clz.bg1+Clz.fgB7, False) + Clz.print(str(key) , Clz.bg1+Clz.fgB3, False) + Clz.print('` not on the server == ', Clz.bg1+Clz.fgB7) + print() + else : + rt = RuTime(eval(__CALLER__('"[%i] %s"' % (row[ImpraIndex.UID],row[ImpraIndex.LABEL]))),DEBUG_INFO) + ck = ConfigKey(row[ImpraIndex.HASH]) + hlst = ck.getHashList(key,row[ImpraIndex.PARTS],True) + Clz.print(' waiting srv...', Clz.fgn7) + ids = self.ih.searchBySubject(hlst['head'][2], True) + for mid in ids : + self.ih.delete(mid, True) + self.index.rem(key) + done = self.saveIndex() + rt.stop() + return done + def getFile(self,key): """""" from impra.util import DEBUG, DEBUG_LEVEL, DEBUG_NOTICE, DEBUG_WARN, DEBUG_INFO done = False - row = self.index.get(key) + row = self.index.get(key) if row==None : - print('--\n%s not on the server' % key) + print() + Clz.print(' == `' , Clz.bg1+Clz.fgB7, False) + Clz.print(str(key) , Clz.bg1+Clz.fgB3, False) + Clz.print('` not on the server == ', Clz.bg1+Clz.fgB7) + print() + else : rt = RuTime(eval(__CALLER__('"[%i] %s"' % (row[ImpraIndex.UID],row[ImpraIndex.LABEL]))),DEBUG_INFO) ck = ConfigKey(row[ImpraIndex.HASH]) @@ -648,11 +731,27 @@ class ImpraStorage: path = self.fsplit.deployFile(hlst, row[ImpraIndex.LABEL], row[ImpraIndex.EXT], row[ImpraIndex.UID], row[ImpraIndex.CATG]) if row[ImpraIndex.BFLAG] == ImpraIndex.FILE_CRYPT: self.decryptTextFile(path) + print() + Clz.print(' deploying in ', Clz.fgn7, False) + Clz.print(dirname(path), Clz.fgB2) + print() done = True else : - print('--\n`%s` is private' % row[ImpraIndex.LABEL]) + print() + Clz.print(' == `' , Clz.bg3+Clz.fgB4, False) + Clz.print(str(row[ImpraIndex.LABEL]) , Clz.bg3+Clz.fgB1, False) + Clz.print('` is private == ' , Clz.bg3+Clz.fgB4) + print() else : - print('--\n`%s` invalid count parts %i/%i' %(row[ImpraIndex.LABEL],len(ids),row[ImpraIndex.PARTS])) + print() + Clz.print(' == `' , Clz.bg3+Clz.fgB4, False) + Clz.print(row[ImpraIndex.LABEL] , Clz.bg3+Clz.fgB1, False) + Clz.print('` invalid count parts ' , Clz.bg3+Clz.fgB4) + Clz.print(str(len(ids)) , Clz.bg3+Clz.fgB1) + Clz.print('/' , Clz.bg3+Clz.fgB4) + Clz.print(str(len(row[ImpraIndex.PARTS])) , Clz.bg3+Clz.fgB1) + Clz.print(' == ' , Clz.bg3+Clz.fgB4) + print() rt.stop() return done diff --git a/impra/imap.py b/impra/imap.py index 6639a2d..cb4ab99 100755 --- a/impra/imap.py +++ b/impra/imap.py @@ -35,9 +35,9 @@ from email.message import Message from imaplib import IMAP4_SSL, Time2Internaldate from os.path import join from re import search, split -from time import time +from time import time, sleep -from impra.util import __CALLER__, RuTime, bstr, stack +from impra.util import __CALLER__, RuTime, bstr, stack, Clz # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -305,6 +305,7 @@ class ImapHelper: self.srv.select(self.BOX_BIN) ids = self.search('ALL',True) if len(ids) > 0 and ids[0]!='' and ids[0]!=None: + print() #print(str(ids[0],'utf-8').split()) for mid in ids: #~ uid = bytes(mid) @@ -312,11 +313,14 @@ class ImapHelper: #~ print(mid) #status, resp = self.srv.store(mid, '+FLAGS', '\\Deleted') status, resp = self.srv.uid('store', mid, '+FLAGS', '\\Deleted' ) - print('deleting msg %i' % int(mid)) + print(' ',end='') + Clz.print(' deleting msg ',Clz.fgN7+Clz.bg1, False) + Clz.print(str(int(mid)) ,Clz.bg1+Clz.fgB3) if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE: print(status) print(resp) self.srv.expunge() + print() self.srv.select(self.rootBox) rt.stop() @@ -329,7 +333,14 @@ class ImapHelper: status, resp = self.srv.uid( 'store', mid, '+FLAGS', '\\Deleted' ) else : status, resp = self.srv.store(mid, '+FLAGS', '\\Deleted') + Clz.print(' flag msg ' , Clz.fgn7, False) + Clz.print(str(mid) , Clz.fgB1, False) + Clz.print(' as deleted', Clz.fgn7) + + Clz.print('\n expunge, waiting server...\n', Clz.fgB1) self.srv.expunge() + sleep(2) + rt.stop() return status == self.OK diff --git a/impra/util.py b/impra/util.py index 8db85eb..8810c55 100755 --- a/impra/util.py +++ b/impra/util.py @@ -35,7 +35,7 @@ from errno import EEXIST from hashlib import sha256 from math import log, floor, ceil from os import urandom, popen, sep, makedirs, system -from os.path import dirname, realpath, abspath, join +from os.path import dirname, realpath, abspath, join, getsize from random import choice from re import split as regsplit, search as regsearch, finditer as regfinditer from subprocess import PIPE, Popen @@ -231,7 +231,7 @@ class RuTime: ep = [m.start() for m in regfinditer('\)', data)] if len(sp) > 0 : Clz.print(data[:sp[0]+1], Clz.fgb3, False) - Clz.print(data[sp[0]+1:ep[0]], Clz.fgn2, False) + Clz.print(data[sp[0]+1:ep[0]], Clz.fgn7, False) Clz.print(data[ep[0]:], Clz.fgb3, False) else: Clz.print(data, Clz.fgb3, False, True) @@ -240,7 +240,7 @@ class RuTime: global Clz Clz.print(' <== ', Clz.fgb1, False) self._paramize(self.label) - Clz.print('%.5f' % (self.ec-self.sc), Clz.fgn7) + Clz.print('%.5f' % (self.ec-self.sc), Clz.fgN4) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -317,6 +317,26 @@ class IniFile: else : main += k+' = '+self.dic[s][k]+'\n' return main + content + def print(self,section='*'): + """""" + a = '' + for s in self.dic: + if section=='*' or section+'.'==s[:len(section)+1]: + if s!='main': + #~ if section=='*': content += '\n['+s+']\n' + #~ else : content += '\n['+s[len(section)+1:]+']\n' + print() + Clz.print('['+s+']', Clz.fgB3) + for k in sorted(self.dic[s]): + k = k.rstrip(' ') + if s!='main' : + a = '' + if len(self.dic[s][k]) > 50: a = '...' + Clz.print(k.ljust(10,' ')+' = ' , Clz.fgn7, False) + if Clz.isUnix or k is not 'key' : + Clz.print(self.dic[s][k][:50]+a, Clz.fgN2) + else: Clz.print('key is masked', Clz.fgb1) + def read(self): """""" try: @@ -403,6 +423,8 @@ class Coloriz: pc = PColor() pc.print('%smon label%s:%sma value%s' % (pc.BG4+pc.fgN7, pc.OFF+pc.fgn1, pc.fgb4, pc.OFF)) """ + global COLOR_MODE + self.active = COLOR_MODE if not self.isUnix: j = 0 for i in (0,4,2,6,1,5,3,7): @@ -444,14 +466,17 @@ class Coloriz: """""" if not endLF : ev = '' else: ev = self._LF - tokens = [c.lstrip(self._MARKER[0]).rstrip(self._SEP) for c in colors.split(self._MARKER) if c is not ''] - if self.isUnix : - if endClz : data += self._uOFF - print(eval('self._u'+'+self._u'.join(tokens))+data,end=ev) - else : - self.setColor(eval('self._w'+'|self._w'.join(tokens))) + if self.active : + tokens = [c.lstrip(self._MARKER[0]).rstrip(self._SEP) for c in colors.split(self._MARKER) if c is not ''] + if self.isUnix : + if endClz : data += self._uOFF + print(eval('self._u'+'+self._u'.join(tokens))+data,end=ev) + else : + self.setColor(eval('self._w'+'|self._w'.join(tokens))) + print(data,end=ev) + stdout.flush() + if endClz : self.setColor(self._wOFF) + else: print(data,end=ev) - stdout.flush() - if endClz : self.setColor(self._wOFF) Clz = Coloriz() diff --git a/imprastorage.py b/imprastorage.py index 8b3fd8e..408e6c4 100755 --- a/imprastorage.py +++ b/imprastorage.py @@ -32,28 +32,7 @@ from impra.cli import Cli import sys, os if __name__ == '__main__': - #~ try : - #~ print('\033[1;30mGray like Ghost\033[1;m') - #~ print('\033[1;31mRed like Radish\033[1;m') - #~ print('\033[1;32mGreen like Grass\033[1;m') - #~ print('\033[1;33mYellow like Yolk\033[1;m') - #~ print('\033[1;34mBlue like Blood\033[1;m') - #~ print('\033[1;35mMagenta like Mimosa\033[1;m') - #~ print('\033[1;36mCyan like Caribbean\033[1;m') - #~ print('\033[1;37mWhite like Whipped Cream\033[1;m') - #~ print('\033[1;38mCrimson like Chianti\033[1;m') - #~ print('\033[1;41mHighlighted Red like Radish\033[1;m') - #~ print('\033[1;42mHighlighted Green like Grass\033[1;m') - #~ print('\033[1;43mHighlighted Brown like Bear\033[1;m') - #~ print('\033[1;44mHighlighted Blue like Blood\033[1;m') - #~ print('\033[1;45mHighlighted Magenta like Mimosa\033[1;m') - #~ print('\033[1;46mHighlighted Cyan like Caribbean\033[1;m') - #~ print('\033[1;47mHighlighted Gray like Ghost\033[1;m') - #~ print('\033[1;48mHighlighted Crimson like Chianti\033[1;m') - Cli(get_file_path(__file__ )) - #os.system('echo python imprastorage data -l') - - #~ except Exception as e : - #~ print(e) + + Cli(get_file_path(__file__ )) #python -O -m compileall impra/*.py