cli colorize

This commit is contained in:
a-Sansara 2012-09-24 10:02:58 +02:00
parent 6a81cdd89a
commit c357185582
3 changed files with 59 additions and 27 deletions

View File

@ -157,32 +157,34 @@ data command Examples:
gpData = OptionGroup(parser, '\n------------------------------------\ndata related Options (command data)')
gpConf = OptionGroup(parser, '\n------------------------------------\nconf related Options (command conf)')
# metavar='<ARG1> <ARG2>', nargs=2
parser.add_option('-v', '--version' , help='show program\'s version number and exit' , action='store_true' , default=False)
parser.add_option('-q', '--quiet' , help='don\'t print status messages to stdout' , action='store_false', default=True)
parser.add_option('-d', '--debug' , help='set debug mode' , action='store_true' , default=False)
gpData.add_option('-l', '--list' , help='list index on imap server' , action='store_true' )
gpData.add_option('-a', '--add' , help='add file FILE with specified LABEL on server' , action='store', metavar='FILE LABEL ', nargs=2)
gpData.add_option('-g', '--get' , help='get file with specified ID from server' , action='store', metavar='ID ')
gpData.add_option('-s', '--search' , help='search file with specified PATTERN' , action='store', metavar='PATTERN ')
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('-a', '--add' , help='add file FILE with specified LABEL on server' , action='store', metavar='FILE LABEL ', nargs=2)
gpData.add_option('-g', '--get' , help='get file with specified ID from server' , action='store', metavar='ID ')
gpData.add_option('-s', '--search' , help='search file with specified PATTERN' , action='store', metavar='PATTERN ')
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', '--order-inv' , help='set colon ORDER_INVERSE (crit. for opt. -l and -s)' , action='store', metavar='ORDER_INVERSE')
#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)
gpConf.add_option('-L', '--list-conf' , help='list configuration' , action='store_true', default=False)
gpConf.add_option('-D', '--load-conf' , help='load configuration' , action='store_true', default=False)
gpConf.add_option('-H', '--set-host' , help='set imap host server' , action='store', metavar='HOST ')
gpConf.add_option('-U', '--set-user' , help='set imap user login' , action='store', metavar='USER ')
gpConf.add_option('-X', '--set-pass' , help='set imap user password' , action='store', metavar='PASS ')
gpConf.add_option('-P', '--set-port' , help='set imap port' , action='store', metavar='PORT ')
gpConf.add_option('-N', '--set-name' , help='set user name' , action='store', metavar='NAME ')
gpConf.add_option('-B', '--set-boxn' , help='set boxName on imap server (default:[%default])' , action='store', metavar='BOXNAME ')
gpConf.add_option('-H', '--set-host' , help='set imap host server' , action='store', metavar='HOST ')
gpConf.add_option('-U', '--set-user' , help='set imap user login' , action='store', metavar='USER ')
gpConf.add_option('-X', '--set-pass' , help='set imap user password' , action='store', metavar='PASS ')
gpConf.add_option('-P', '--set-port' , help='set imap port' , action='store', metavar='PORT ')
gpConf.add_option('-N', '--set-name' , help='set user name' , action='store', metavar='NAME ')
gpConf.add_option('-B', '--set-boxn' , help='set boxName on imap server (default:[%default])' , action='store', metavar='BOXNAME ')
gpConf.add_option('-K', '--gen-keys' , help='generate new key' , action='store_true', default=False)
gpConf.add_option('-A', '--active-profile', help='set active profile' , action='store', metavar='PROFILE ')
gpConf.add_option('-A', '--active-profile', help='set active profile' , action='store', metavar='PROFILE ')
parser.add_option_group(gpConf)
@ -337,7 +339,11 @@ data command Examples:
printHeaderPart('box',impst.rootBox)
Clz.print(date, Clz.fgB7, True, True)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
impst.index.print(o.order)
order = o.order
if o.order_inv is not None:
order = '-'+o.order_inv
impst.index.print(order)
elif o.add :
done = impst.addFile(o.add[0],o.add[1],o.user,o.category)
@ -368,15 +374,28 @@ data command Examples:
print()
elif o.search :
uid = conf.get('uid' ,'index')
date = conf.get('date','index')
account = conf.get('user','imap')
matchIds = impst.index.getByPattern(o.search)
core.clear()
if matchIds is not None:
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
printHeaderTitle('SEARCH')
printHeaderTitle(APP_TITLE)
printHeaderPart('account',account)
printHeaderPart('index',uid)
printHeaderPart('box',impst.rootBox)
Clz.print(date, Clz.fgB7, True, True)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
Clz.print(' searching --' , Clz.fgB3, False)
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)
order = o.order
if o.order_inv is not None:
order = '-'+o.order_inv
impst.index.print(o.order,matchIds)
else:
print('\n ',end='')

View File

@ -135,6 +135,9 @@ class FSplitter :
Clz.print('-'+str(uid) , Clz.fgB1, False)
Clz.print(ext , Clz.fgB2)
filePath += '-'+str(uid)
else :
Clz.print('\n deploying file as :' , Clz.fgn7)
Clz.print(' '+basename(filePath)+ext , Clz.fgB2, False)
filePath += ext
fp = open(filePath, 'wb+')
@ -403,6 +406,8 @@ class ImpraIndex:
"""Print index content as formated bloc"""
#clear()
from impra.cli import printLineSep, LINE_SEP_LEN, LINE_SEP_CHAR
inv = order.startswith('-')
if inv : order = order[1:]
orderIndex = self.COLS.index(order)
if orderIndex is None : orderIndex = self.COLS.index('ID')
@ -416,7 +421,7 @@ class ImpraIndex:
Clz.print('CATEGORY'+' '*22, Clz.BG4+Clz.fgB7)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
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])
d = sorted([(self.dic.get(k),k) for i, k in enumerate(self.dic) if not k.startswith(self.SEP_KEY_INTERN)], reverse=inv, key=lambda lst:lst[0][orderIndex])
a = ''
for v,k in d :
if matchIds==None or v[self.UID] in matchIds:
@ -541,7 +546,11 @@ class ImpraStorage:
rt = RuTime(eval(__CALLER__()),DEBUG_INFO)
if self.idx != None :
self.ih.delete(self.idx, True)
for i in self.delids : self.ih.delete(i, True)
if len(self.delids) > 0 :
for i in self.delids : self.ih.delete(i, True, False)
Clz.print('\n expunge, waiting server...\n', Clz.fgB1)
self.srv.expunge()
sleep(2)
encData = self.index.encrypt()
msgIndex = self.mb.buildIndex(encData)
if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : print(msgIndex.as_string())
@ -692,10 +701,13 @@ class ImpraStorage:
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)
Clz.print(' get file list from server', Clz.fgn7)
ids = self.ih.searchBySubject(hlst['head'][2], True)
for mid in ids :
self.ih.delete(mid, True)
self.ih.delete(mid, True, False)
Clz.print('\n expunge, waiting pls...\n', Clz.fgB1)
self.ih.srv.expunge()
sleep(2)
self.index.rem(key)
done = self.saveIndex()
rt.stop()
@ -732,7 +744,7 @@ class ImpraStorage:
if row[ImpraIndex.BFLAG] == ImpraIndex.FILE_CRYPT:
self.decryptTextFile(path)
print()
Clz.print(' deploying in ', Clz.fgn7, False)
Clz.print(' deploying in ', Clz.fgn7)
Clz.print(dirname(path), Clz.fgB2)
print()
done = True

View File

@ -324,7 +324,7 @@ class ImapHelper:
self.srv.select(self.rootBox)
rt.stop()
def delete(self, mid, byUid=False):
def delete(self, mid, byUid=False, expunge=True):
""""""
rt = RuTime(eval(__CALLER__('%i' % int(mid))))
status = None
@ -337,9 +337,10 @@ class ImapHelper:
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)
if expunge :
Clz.print('\n expunge, waiting server...\n', Clz.fgB1)
self.srv.expunge()
sleep(2)
rt.stop()
return status == self.OK