cli coloriz help, readjust all options

This commit is contained in:
a-sansara 2012-09-24 19:11:20 +02:00
parent c357185582
commit 34b8ef3aab
3 changed files with 775 additions and 352 deletions

View File

@ -46,21 +46,17 @@ APP_AUTHOR = 'a-Sansara'
APP_COPY = 'pluie.org' APP_COPY = 'pluie.org'
APP_LICENSE = 'GNU GPLv3' APP_LICENSE = 'GNU GPLv3'
APP_DESC = """ APP_DESC = """
ImpraStorage provided a private imap access to store large files. ImpraStorage provided a private imap access to store large files. Each file stored on the server is split
Each file stored on the server is split in severals random parts. in severals random parts. Each part also contains random noise data (lenght depends on a crypt key) to
Each part also contains random noise data (lenght depends on a crypt key) ensure privacy and exclude easy merge without the corresponding key.
to ensure privacy and exclude easy merge without the corresponding key.
An index of files stored is encrypt (with the symmetric-key algorithm An index of files stored is encrypt (with the symmetric-key algorithm Kirmah) and regularly updated. Once
Kirmah) and regularly updated. Once decrypt, it permit to perform search decrypt, it permit to perform search on the server and download each part.
on the server and download each part.
transfert process is transparent. Just vizualize locally the index of Transfert process is transparent. Just vizualize locally the index of stored files and simply select files
stored files and simply select files to download or upload. to download or upload. ImpraStorage automatically launch the parts to download, then merge parts in the
ImpraStorage automatically launch the parts to download, then merge parts appropriate way to rebuild the original file. Inversely, a file to upload is split (in several parts with
in the appropriate way to rebuild the original file. Inversely, a file addition of noise data), and ImpraStorage randomly upload each parts then update the index.
to upload is split (in several parts with addition of noise data), and
ImpraStorage randomly upload each parts then update the index.
""" """
@ -99,60 +95,9 @@ class Cli:
def __init__(self,path): def __init__(self,path):
self.ini = util.IniFile(path+'impra.ini') self.ini = util.IniFile(path+'impra.ini')
parser = _OptionParser(prog='imprastorage', usage='\n\n\ parser = _OptionParser()
------------------------------------------------------------------------------\n\ parser.print_help = self.print_help
-- %s --\n\ parser.print_usage = self.print_usage
------------------------------------------------------------------------------\n\
-- version : %s copyright : %s --\n\
-- author : %s license : %s --\n\
------------------------------------------------------------------------------\n\
\n\
%s conf [-D|-L| -K,-H {host},-U {user},-X {password},-P {port},\n\
-B {boxname}] [-A profileName]\n\
%s data [-l |-a {file, label} |-g {id} |-s {pattern} | -r {id}]\n\
[-c {catg}, -u {owner}]'
% (APP_TITLE,APP_VERSION,APP_COPY,APP_AUTHOR,APP_LICENSE,APP_TITLE.lower(),APP_TITLE.lower()) , epilog="""
conf command Examples:
Initialize program and set config on default profile with keys generation :
imprastorage conf -K -H imap.gmail.com -P 993 -U login -X password
Set config on a new profile with same keys from previous active profile:
imprastorage conf -H myimapserver.net -P 993 -U login -X password -B boxname -A profile1
Load config from a profile (wich become active) :
imprastorage conf -DA profile2
List config from profile :
imprastorage conf -LA profile1
data command Examples:
List index
imprastorage data -l
Add file
imprastorage data -a /path/tofile 'my video'
Add file with category (category is also a directory structure recreate
when downloading files)
imprastorage data -a /path/tofile '2009 - en la playa' -c videos/perso/2009
Get file by id
imprastorage data -g 22
Remove from server a file by id
imprastorage data -g 22
Search files matching pattern :
imprastorage data -s 'holydays'
Search files upload by a particular user on a category :
imprastorage data -s * -c films -u myfriend
""",description=APP_DESC)
gpData = OptionGroup(parser, '\n------------------------------------\ndata related Options (command data)') gpData = OptionGroup(parser, '\n------------------------------------\ndata related Options (command data)')
gpConf = OptionGroup(parser, '\n------------------------------------\nconf related Options (command conf)') gpConf = OptionGroup(parser, '\n------------------------------------\nconf related Options (command conf)')
@ -163,20 +108,16 @@ data command Examples:
parser.add_option('-q', '--quiet' , help='don\'t print status messages to stdout' , action='store_false', default=True) 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) 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('-c', '--category' , help='set specified CATEGORY (crit. for opt. -l,-a or -s)' , action='store', metavar='CATG ')
gpData.add_option('-a', '--add' , help='add file FILE with specified LABEL on server' , action='store', metavar='FILE LABEL ', nargs=2) gpData.add_option('-u', '--user' , help='set specified USER (crit. for opt. -l,-a or -s)' , action='store', metavar='OWNER ')
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' , 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', '--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 ') #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) parser.add_option_group(gpData)
gpConf.add_option('-L', '--list-conf' , help='list configuration' , action='store_true', default=False) gpConf.add_option('-V', '--view' , help='view configuration' , action='store' )
gpConf.add_option('-D', '--load-conf' , help='load configuration' , action='store_true', default=False) gpConf.add_option('-L', '--load' , help='load configuration' , action='store' )
gpConf.add_option('-S', '--save' , help='save configuration' , action='store' )
gpConf.add_option('-H', '--set-host' , help='set imap host server' , action='store', metavar='HOST ') 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('-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('-X', '--set-pass' , help='set imap user password' , action='store', metavar='PASS ')
@ -184,71 +125,28 @@ data command Examples:
gpConf.add_option('-N', '--set-name' , help='set user name' , action='store', metavar='NAME ') 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('-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('-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 ')
parser.add_option_group(gpConf) parser.add_option_group(gpConf)
(o, a) = parser.parse_args() (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() print()
if not a: if not a:
try :
if o.version :
self.print_header()
sys.exit(0)
except Exception as ex:
pass
try :
if not o.help :
parser.error(' no commando specified')
sys.exit(1)
else :
parser.print_help() parser.print_help()
print() except :
parser.error(' no commando specified') parser.error(' no commando specified')
sys.exit(1) sys.exit(1)
@ -257,15 +155,24 @@ data command Examples:
# ~~ conf CMD ~~ # ~~ conf CMD ~~
if a[0] == 'conf' : if a[0] == 'conf' :
if o.load is not None or o.view is not None or o.save is not None :
if o.view is not None :
o.active_profile = o.view
if o.load is not None :
o.active_profile = o.load
if o.save is not None :
o.active_profile = o.save
if o.active_profile==None: if o.active_profile==None:
if self.ini.has('profile') : o.active_profile = self.ini.get('profile') if self.ini.has('profile') : o.active_profile = self.ini.get('profile')
else : o.active_profile = 'default' else : o.active_profile = 'default'
if o.load_conf : self.load_profile(o) if o.load : self.load_profile(o)
elif o.list_conf : print(self.ini.toString(o.active_profile)) elif o.view : self.ini.print(o.active_profile)
else : elif o.save :
if not o.set_host and not o.set_user and not o.set_pass and not o.set_port and not o.set_boxn and not o.set_name and not o.gen_keys: if not o.set_host and not o.set_user and not o.set_pass and not o.set_port and not o.set_boxn and not o.set_name and not o.gen_keys:
parser.error(' no options specified') parser.error(' no options specified')
else : else :
@ -287,16 +194,15 @@ data command Examples:
self.ini.set('profile', o.active_profile) self.ini.set('profile', o.active_profile)
self.ini.write() self.ini.write()
self.ini.print(o.active_profile) self.ini.print(o.active_profile)
else :
self.print_usage('')
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ data CMD ~~ # ~~ data CMD ~~
elif a[0] == 'data' : elif a[0] == 'list' or a[0] == 'add' or a[0] == 'get' or a[0] == 'remove' or a[0] == 'search' :
o.active_profile = self.ini.get('profile') o.active_profile = self.ini.get('profile')
if not o.list and not o.add and not o.get and not o.search and not o.remove :
parser.error(' no options specified')
else :
if self.check_profile(o.active_profile): if self.check_profile(o.active_profile):
conf = core.ImpraConf(self.ini,o.active_profile) conf = core.ImpraConf(self.ini,o.active_profile)
@ -323,7 +229,9 @@ data command Examples:
print() print()
sys.exit(1) sys.exit(1)
if o.list :
if a[0]=='list':
uid = conf.get('uid' ,'index') uid = conf.get('uid' ,'index')
date = conf.get('date','index') date = conf.get('date','index')
account = conf.get('user','imap') account = conf.get('user','imap')
@ -340,21 +248,53 @@ data command Examples:
Clz.print(date, Clz.fgB7, True, True) Clz.print(date, Clz.fgB7, True, True)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
matchIdsCatg = None
matchIdsUser = None
matchIds = None
if o.category is not None :
print(o.category)
matchIdsCatg = impst.index.getByCategory(o.category)
if o.user is not None :
matchIdsUser = impst.index.getByUser(o.user)
if o.category is not None :
if o.user is not None :
matchIds = impst.index.getIntersection(matchIdsCatg,matchIdsUser)
else : matchIds = matchIdsCatg
elif o.user is not None :
matchIds = matchIdsUser
order = o.order order = o.order
if o.order_inv is not None: if o.order_inv is not None:
order = '-'+o.order_inv order = '-'+o.order_inv
impst.index.print(order) impst.index.print(order,matchIds)
elif o.add :
done = impst.addFile(o.add[0],o.add[1],o.user,o.category) elif a[0] == 'add':
if not len(a)>1 : self.error_cmd('`'+a[0]+' need at least one argument',parser)
vfile = a[1]
if util.file_exists(vfile) :
if not len(a)>2 :
label, ext = core.splitext(core.basename(vfile))
else: label = a[2]
if o.category is None : o.category = ''
done = impst.addFile(vfile,label,o.category)
if done : if done :
print('\n ',end='') print('\n ',end='')
Clz.print(' == OK == ', Clz.bg2+Clz.fgb7) Clz.print(' == OK == ', Clz.bg2+Clz.fgb7)
print() print()
elif o.get : else : self.error_cmd('`'+a[1]+' is not a file',parser)
elif a[0] == 'get':
if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser)
vid = a[1]
ids = [] ids = []
for sid in o.get.split(',') : for sid in vid.split(',') :
seq = sid.split('-') seq = sid.split('-')
if len(seq)==2 : ids.extend(range(int(seq[0]),int(seq[1])+1)) if len(seq)==2 : ids.extend(range(int(seq[0]),int(seq[1])+1))
else: ids.append(sid) else: ids.append(sid)
@ -373,11 +313,17 @@ data command Examples:
Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7) Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7)
print() print()
elif o.search :
elif a[0] == 'search':
uid = conf.get('uid' ,'index') uid = conf.get('uid' ,'index')
date = conf.get('date','index') date = conf.get('date','index')
account = conf.get('user','imap') account = conf.get('user','imap')
matchIds = impst.index.getByPattern(o.search)
if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser)
vsearch = a[1]
matchIds = impst.index.getByPattern(vsearch)
core.clear() core.clear()
if matchIds is not None: if matchIds is not None:
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
@ -388,11 +334,32 @@ data command Examples:
Clz.print(date, Clz.fgB7, True, True) Clz.print(date, Clz.fgB7, True, True)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
Clz.print(' searching --' , Clz.fgB3, False) Clz.print(' searching --' , Clz.fgB3, False)
Clz.print(' `'+o.search+'`' , Clz.fgB7, False) Clz.print(' `'+vsearch+'`' , Clz.fgB7, False)
Clz.print(' -- found ' , Clz.fgB3, False) Clz.print(' -- found ' , Clz.fgB3, False)
Clz.print(str(len(matchIds)), Clz.fgB1, False) Clz.print(str(len(matchIds)), Clz.fgB1, False)
Clz.print(' results --' , Clz.fgB3) Clz.print(' results --' , Clz.fgB3)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
matchIdsCatg = None
matchIdsUser = None
matchIdsCrit = None
if o.category is not None :
print(o.category)
matchIdsCatg = impst.index.getByCategory(o.category)
if o.user is not None :
matchIdsUser = impst.index.getByUser(o.user)
if o.category is not None :
if o.user is not None :
matchIdsCrit = impst.index.getIntersection(matchIdsCatg,matchIdsUser)
else : matchIdsCrit = matchIdsCatg
elif o.user is not None :
matchIdsCrit = matchIdsUser
if matchIdsCrit is not None :
matchIds = impst.index.getIntersection(matchIds,matchIdsCrit)
order = o.order order = o.order
if o.order_inv is not None: if o.order_inv is not None:
order = '-'+o.order_inv order = '-'+o.order_inv
@ -400,11 +367,15 @@ data command Examples:
else: else:
print('\n ',end='') print('\n ',end='')
Clz.print(' == no match found for pattern `', Clz.bg3+Clz.fgB4, False) Clz.print(' == no match found for pattern `', Clz.bg3+Clz.fgB4, False)
Clz.print(o.search , Clz.bg3+Clz.fgB1, False) Clz.print(vsearch , Clz.bg3+Clz.fgB1, False)
Clz.print('` == ' , Clz.bg3+Clz.fgB4) Clz.print('` == ' , Clz.bg3+Clz.fgB4)
print() print()
elif o.remove :
key = impst.index.getById(o.remove) elif a[0] == 'remove':
if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser)
vid = a[1]
key = impst.index.getById(vid)
if key !=None : if key !=None :
done = impst.removeFile(key) done = impst.removeFile(key)
if done : if done :
@ -418,14 +389,473 @@ data command Examples:
Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7) Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7)
print() print()
else : parser.print_help() else :
self.error_cmd('unknow command `'+a[0]+'`',parser)
print() print()
def error_cmd(self,msg, parser):
parser.error(msg)
sys.exit(1)
def check_profile(self,profile): def check_profile(self,profile):
"""""" """"""
return self.ini.hasSection(profile+'.keys') and self.ini.has('host',profile+'.imap') and self.ini.has('user',profile+'.imap') and self.ini.has('pass',profile+'.imap') and self.ini.has('port',profile+'.imap') return self.ini.hasSection(profile+'.keys') and self.ini.has('host',profile+'.imap') and self.ini.has('user',profile+'.imap') and self.ini.has('pass',profile+'.imap') and self.ini.has('port',profile+'.imap')
def print_header(self):
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
printHeaderTitle(APP_TITLE)
printHeaderPart('version',APP_VERSION)
printHeaderPart('author',APP_AUTHOR)
printHeaderPart('license',APP_LICENSE)
printHeaderPart('copyright','2012 '+APP_COPY)
Clz.print(' ', Clz.OFF)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
print()
def print_version(self, data):
self.print_header()
def print_usage(self, data, withoutHeader=False):
if not withoutHeader : self.print_header()
Clz.print(' USAGE :\n', Clz.fgB3)
Clz.print(' imprastorage ', Clz.fgb7, False)
Clz.print('--help ', Clz.fgB3)
Clz.print(' imprastorage ', Clz.fgb7, False)
Clz.print('add ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('filePath', Clz.fgb1, False)
Clz.print('} ', Clz.fgB1, False)
Clz.print('[', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('name', Clz.fgb1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(' -c ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('category', Clz.fgb1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(']', Clz.fgB3)
Clz.print(' imprastorage ', Clz.fgb7, False)
Clz.print('get ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('id|ids', Clz.fgb1, False)
Clz.print('}', Clz.fgB1)
Clz.print(' imprastorage ', Clz.fgb7, False)
Clz.print('list ', Clz.fgB3, False)
Clz.print('[', Clz.fgB3, False)
Clz.print(' -c ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('category', Clz.fgb1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(' -u ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('user', Clz.fgb1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(' -o', Clz.fgB3, False)
Clz.print('|', Clz.fgB1, False)
Clz.print('-O ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('colon', Clz.fgb1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(']', Clz.fgB3)
Clz.print(' imprastorage ', Clz.fgb7, False)
Clz.print('remove ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('id', Clz.fgb1, False)
Clz.print('}', Clz.fgB1)
Clz.print(' imprastorage ', Clz.fgb7, False)
Clz.print('search ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('pattern', Clz.fgb1, False)
Clz.print('} ', Clz.fgB1, False)
Clz.print('[', Clz.fgB3, False)
Clz.print(' -c ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('category', Clz.fgb1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(' -u ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('user', Clz.fgb1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(' -o', Clz.fgB3, False)
Clz.print('|', Clz.fgB1, False)
Clz.print('-O ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('colon', Clz.fgb1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(']', Clz.fgB3)
Clz.print(' imprastorage ', Clz.fgb7, False)
Clz.print('conf', Clz.fgB3, False)
Clz.print(' -L', Clz.fgB3, False)
Clz.print('|', Clz.fgB1, False)
Clz.print('-V ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('profile', Clz.fgb1, False)
Clz.print('}', Clz.fgB1)
Clz.print(' imprastorage ', Clz.fgb7, False)
Clz.print('conf', Clz.fgB3, False)
Clz.print(' -S ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('profile', Clz.fgb1, False)
Clz.print('} ', Clz.fgB1, False)
Clz.print('[', Clz.fgB3, False)
Clz.print(' -K ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('length', Clz.fgB1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(', -H ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('host', Clz.fgB1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(', -U ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('user', Clz.fgB1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(', -X ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('password', Clz.fgB1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(', -P ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('port', Clz.fgB1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(', -B ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('box', Clz.fgB1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(', -N ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('name', Clz.fgB1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(' ]', Clz.fgB3)
def print_options(self):
print('\n')
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
Clz.print(' MAIN OPTIONS :\n' , Clz.fgB3)
Clz.print(' '*4+'-h, --help' , Clz.fgB3)
Clz.print(' '*50+'display help message' , Clz.fgB7)
Clz.print(' '*4+'-q, --quiet' , Clz.fgB3)
Clz.print(' '*50+'don\'t print status messages to stdout' , Clz.fgB7)
Clz.print(' '*4+'-d, --debug' , Clz.fgB3)
Clz.print(' '*50+'set debug mode' , Clz.fgB7)
Clz.print(' '*4+'-v, --version' , Clz.fgB3)
Clz.print(' '*50+'show program\'s version number' , Clz.fgB7)
print('\n')
Clz.print(' COMMANDS OPTIONS :\n' , Clz.fgB3)
Clz.print(' '*4+'-c ' , Clz.fgB3, False)
Clz.print('CATEGORY'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --category '.ljust(18,' ') , Clz.fgB3, False)
Clz.print('CATEGORY'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'set a category' , Clz.fgB7)
Clz.print(' '*4+'-u ' , Clz.fgB3, False)
Clz.print('USER'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --user'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('USER'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'set a user' , Clz.fgB7)
Clz.print(' '*4+'-o ' , Clz.fgB3, False)
Clz.print('COLON'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --order'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('COLON'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'order by specified colon' , Clz.fgB7)
Clz.print(' '*4+'-O ' , Clz.fgB3, False)
Clz.print('COLON'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --order-rev'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('COLON'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'reverse order by specified colon' , Clz.fgB7)
print('\n')
Clz.print(' CONF OPTIONS :\n', Clz.fgB3)
Clz.print(' '*4+'-L ' , Clz.fgB3, False)
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --load'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'load the specified profile' , Clz.fgB7)
Clz.print(' '*4+'-V ' , Clz.fgB3, False)
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --view'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'view the specified profile (or current)' , Clz.fgB7)
Clz.print(' '*4+'-S ' , Clz.fgB3, False)
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --order'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'save the specified profile' , Clz.fgB7)
print('\n')
Clz.print(' CONF -S OPTIONS :\n', Clz.fgB3)
Clz.print(' '*4+'-N ' , Clz.fgB3, False)
Clz.print('NAME'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --set-name'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('NAME'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'set imprastorage username' , Clz.fgB7)
Clz.print(' '*4+'-K ' , Clz.fgB3, False)
Clz.print('LENGTH'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --gen-key'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('LENGTH'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'generate a new key of optionnal LENGTH length (default:256)', Clz.fgB7)
Clz.print(' '*4+'-H ' , Clz.fgB3, False)
Clz.print('HOST'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --set-host'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('HOST'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'set imap host' , Clz.fgB7)
Clz.print(' '*4+'-U ' , Clz.fgB3, False)
Clz.print('USER'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --set-user'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('USER'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'set imap user' , Clz.fgB7)
Clz.print(' '*4+'-X ' , Clz.fgB3, False)
Clz.print('PASSWORD'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --set-password'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('USER'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'set imap password' , Clz.fgB7)
Clz.print(' '*4+'-P ' , Clz.fgB3, False)
Clz.print('PORT'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --set-port'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('PORT'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'set imap port' , Clz.fgB7)
Clz.print(' '*4+'-B ' , Clz.fgB3, False)
Clz.print('BOXNAME'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --set-box'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('BOXNAME'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'set imap boxname (default:__impra__)' , Clz.fgB7)
print('\n')
def print_help(self):
""""""
self.print_header()
Clz.print(APP_DESC, Clz.fgN1)
self.print_usage('', True)
self.print_options()
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
print()
Clz.print(' EXEMPLES :\n', Clz.fgB3)
Clz.print(' '*4+'command add :', Clz.fgB3)
Clz.print(' '*8+'# add (upload) a file',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('add ', Clz.fgB3, False)
Clz.print('/home/Share/2009-mountains.avi', Clz.fgB1)
Clz.print(' '*8+'# add a file with a label (label will be the filename on downloading)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('add ', Clz.fgB3, False)
Clz.print('/home/Share/2009-mountains.avi \'summer 2009 - in mountains\'', Clz.fgB1)
Clz.print(' '*8+'# add a file on a category (category will be the dir structure on downloading)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('add ', Clz.fgB3, False)
Clz.print('/home/Share/2009-mountains.avi', Clz.fgB1, False)
Clz.print(' -c ', Clz.fgB3, False)
Clz.print('videos/perso/2009', Clz.fgB1)
Clz.print(' '*8+'# add a file with a label on a category',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('add ', Clz.fgB3, False)
Clz.print('/home/Share/2009-mountains.avi \'summer 2009 - in mountains\'', Clz.fgB1, False)
Clz.print(' -c ', Clz.fgB3, False)
Clz.print('videos/perso/2009', Clz.fgB1)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
Clz.print('\n'+' '*4+'command get :', Clz.fgB3)
Clz.print(' '*8+'# get file with id 15',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('get ', Clz.fgB3, False)
Clz.print('15', Clz.fgB1)
Clz.print(' '*8+'# get files with id 15,16,17,18,19',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('get ', Clz.fgB3, False)
Clz.print('15-19', Clz.fgB1)
Clz.print(' '*8+'# get files with id 22,29,30',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('get ', Clz.fgB3, False)
Clz.print('22,29,30', Clz.fgB1)
Clz.print(' '*8+'# get files with id 22,29,30,31,32,33,34,35,48',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('get ', Clz.fgB3, False)
Clz.print('22,29-35,48', Clz.fgB1)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
Clz.print('\n'+' '*4+'command list :', Clz.fgB3)
Clz.print(' '*8+'# list all files',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('list', Clz.fgB3)
Clz.print(' '*8+'# list all files (sorted by LABEL)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('list', Clz.fgB3, False)
Clz.print(' -o ' , Clz.fgB3, False)
Clz.print('LABEL', Clz.fgB1)
Clz.print(' '*8+'# list all files on category `videos/perso` ',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('list', Clz.fgB3, False)
Clz.print(' -c ' , Clz.fgB3, False)
Clz.print('videos/perso', Clz.fgB1)
Clz.print(' '*8+'# list all files sent by `bob`',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('list', Clz.fgB3, False)
Clz.print(' -u ' , Clz.fgB3, False)
Clz.print('bob', Clz.fgB1)
Clz.print(' '*8+'# list all files sent by `bob` on category `videos/perso` (reverse sorted by SIZE)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('list', Clz.fgB3, False)
Clz.print(' -O ' , Clz.fgB3, False)
Clz.print('SIZE', Clz.fgB1, False)
Clz.print(' -c ' , Clz.fgB3, False)
Clz.print('videos/perso', Clz.fgB1, False)
Clz.print(' -u ' , Clz.fgB3, False)
Clz.print('bob', Clz.fgB1)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
Clz.print('\n'+' '*4+'command remove :', Clz.fgB3)
Clz.print(' '*8+'# remove file with id 15 (removing command only take a single id)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('remove ', Clz.fgB3, False)
Clz.print('15', Clz.fgB1)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
Clz.print('\n'+' '*4+'command search :', Clz.fgB3)
Clz.print(' '*8+'# search all files wich contains `mountains`',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('search ', Clz.fgB3, False)
Clz.print('mountains', Clz.fgB1)
Clz.print(' '*8+'# search all files wich contains `old mountain` on category `videos/perso`',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('search ', Clz.fgB3, False)
Clz.print('\'old mountain\'', Clz.fgB1, False)
Clz.print(' -c ' , Clz.fgB3, False)
Clz.print('videos/perso', Clz.fgB1)
Clz.print(' '*8+'# search all files wich contains `old mountain` sent by user `bob`',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('search ', Clz.fgB3, False)
Clz.print('\'old mountain\'', Clz.fgB1, False)
Clz.print(' -u ' , Clz.fgB3, False)
Clz.print('bob', Clz.fgB1)
Clz.print(' '*8+'# search all files wich contains `old mountain` (reverse sorted by SIZE)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('search ', Clz.fgB3, False)
Clz.print('\'old mountain\'', Clz.fgB1, False)
Clz.print(' -O ' , Clz.fgB3, False)
Clz.print('SIZE', Clz.fgB1)
Clz.print(' '*8+'# search all files wich contains `old mountain` sent by user `bob` and on category `videos/perso` (reverse',Clz.fgn7)
Clz.print(' '*8+'# sorted by LABEL)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('search ', Clz.fgB3, False)
Clz.print('\'old mountain\'', Clz.fgB1, False)
Clz.print(' -c ' , Clz.fgB3, False)
Clz.print('videos/perso', Clz.fgB1, False)
Clz.print(' -u ' , Clz.fgB3, False)
Clz.print('bob', Clz.fgB1, False)
Clz.print(' -O ' , Clz.fgB3, False)
Clz.print('LABEL' , Clz.fgB1)
Clz.print(' '*8+'# search all files starting by `old mountain`',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('search ', Clz.fgB3, False)
Clz.print('\'^old mountain\'', Clz.fgB1)
Clz.print(' '*8+'# search all files ending by `old mountain`',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('search ', Clz.fgB3, False)
Clz.print('\'old mountain$\'', Clz.fgB1)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
Clz.print('\n'+' '*4+'command conf :', Clz.fgB3)
Clz.print(' '*8+'# this command is tipycally a profile creation (or rewrite if profile exists)',Clz.fgn7)
Clz.print(' '*8+'# set a userName, generate a new Key and set imap account with host,port,user,password for profile bobgmail',Clz.fgn7)
Clz.print(' '*8+'# then set it as current profile',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('conf ', Clz.fgB3, False)
Clz.print('-S ', Clz.fgB3, False)
Clz.print('bobgmail ', Clz.fgB1, False)
Clz.print('-N ', Clz.fgB3, False)
Clz.print('bob ', Clz.fgB1, False)
Clz.print('-K -H ', Clz.fgB3, False)
Clz.print('imap.gmail.com ', Clz.fgB1, False)
Clz.print('-P ', Clz.fgB3, False)
Clz.print('993 ', Clz.fgB1, False)
Clz.print('-U ', Clz.fgB3, False)
Clz.print('bob22 ', Clz.fgB1, False)
Clz.print('-X ', Clz.fgB3, False)
Clz.print('mypassword ', Clz.fgB1)
Clz.print(' '*8+'# load config profile bobimap and set it as current profile',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('conf ', Clz.fgB3, False)
Clz.print('-L ', Clz.fgB3, False)
Clz.print('bobimap ', Clz.fgB1)
Clz.print(' '*8+'# view config current profile',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('conf ', Clz.fgB3, False)
Clz.print('-V', Clz.fgB3)
Clz.print(' '*8+'# view config profile bobgmail (current profile doesn\'t change)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('conf ', Clz.fgB3, False)
Clz.print('-V ', Clz.fgB3, False)
Clz.print('bobgmail ', Clz.fgB1)
Clz.print(' '*8+'# generate a new Key for current profile (carreful with this command if your account has no empty index - ',Clz.fgn7)
Clz.print(' '*8+'# all files will be unrecoverable without the appropriate key)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('conf ', Clz.fgB3, False)
Clz.print('-S -K', Clz.fgB3)
Clz.print(' '*8+'# generate a new Key for profile bobgmail and set it as current profile (carreful with this command ',Clz.fgn7)
Clz.print(' '*8+'# if your account has no empty index - all files will be unrecoverable without the appropriate key)',Clz.fgn7)
Clz.print(' '*8+'imprastorage ', Clz.fgB7, False)
Clz.print('conf ', Clz.fgB3, False)
Clz.print('-S ', Clz.fgB3, False)
Clz.print('bobgmail ', Clz.fgB1, False)
Clz.print('-K', Clz.fgB3)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
print()
def load_profile(self,o): def load_profile(self,o):

View File

@ -44,7 +44,7 @@ from mmap import mmap
from os import remove, urandom, sep from os import remove, urandom, sep
from os.path import abspath, dirname, join, realpath, basename, getsize, splitext from os.path import abspath, dirname, join, realpath, basename, getsize, splitext
from re import split as regsplit, match as regmatch, compile as regcompile, search as regsearch from re import split as regsplit, match as regmatch, compile as regcompile, search as regsearch
from time import time from time import time, sleep
from impra.imap import ImapHelper, ImapConfig from impra.imap import ImapHelper, ImapConfig
from impra.util import __CALLER__, RuTime, formatBytes, randomFrom, bstr, quote_escape, stack, run, file_exists, get_file_content, DEBUG, DEBUG_ALL, DEBUG_LEVEL, DEBUG_NOTICE, DEBUG_WARN, mkdir_p, is_binary, clear, Clz from impra.util import __CALLER__, RuTime, formatBytes, randomFrom, bstr, quote_escape, stack, run, file_exists, get_file_content, DEBUG, DEBUG_ALL, DEBUG_LEVEL, DEBUG_NOTICE, DEBUG_WARN, mkdir_p, is_binary, clear, Clz
from impra.crypt import Kirmah, ConfigKey, Noiser, Randomiz, hash_sha256, hash_md5_file, BadKeyException from impra.crypt import Kirmah, ConfigKey, Noiser, Randomiz, hash_sha256, hash_md5_file, BadKeyException
@ -246,7 +246,7 @@ class ImpraIndex:
"""""" """"""
EXT = 3 EXT = 3
"""""" """"""
OWNER = 4 USER = 4
"""""" """"""
CATG = 5 CATG = 5
"""""" """"""
@ -260,7 +260,7 @@ class ImpraIndex:
"""""" """"""
FILE_CRYPT = 'c' FILE_CRYPT = 'c'
"""""" """"""
COLS = ('HASH','LABEL','PART','TYPE','OWNER','CATEGORY','ID','BLFAG','SIZE') COLS = ('HASH','LABEL','PART','TYPE','USER','CATEGORY','ID','BLFAG','SIZE')
"""""" """"""
def __init__(self, key, mark, encdata='', dicCategory={}, id=0): def __init__(self, key, mark, encdata='', dicCategory={}, id=0):
@ -385,6 +385,37 @@ class ImpraIndex:
rt.stop() rt.stop()
return l return l
def getByCategory(self,category):
"""Get ids corresponding to category
:Returns: `[uid]`|None matchIds
"""
rt = RuTime(eval(__CALLER__(category)))
l = None
r = [ k for i,k in enumerate(self.dic) if not k.startswith(self.SEP_KEY_INTERN) and regsearch(category,self.dic[k][self.CATG]) is not None ]
l = [self.dic[k][self.UID] for k in r]
rt.stop()
return l
def getByUser(self,user):
"""Get ids corresponding to category
:Returns: `[uid]`|None matchIds
"""
rt = RuTime(eval(__CALLER__(user)))
l = None
r = [ k for i,k in enumerate(self.dic) if not k.startswith(self.SEP_KEY_INTERN) and regsearch(user,self.getUser(self.dic[k][self.USER])) is not None ]
l = [self.dic[k][self.UID] for k in r]
rt.stop()
return l
def getIntersection(self,list1, list2):
"""Get ids intercept list1 and list2
:Returns: `[uid]`|None matchIds
"""
rt = RuTime(eval(__CALLER__()))
l = [ i for i in set(list1).intersection(set(list2))]
rt.stop()
return l
def encrypt(self): def encrypt(self):
"""""" """"""
#~ print('encrypting index :') #~ print('encrypting index :')
@ -417,7 +448,7 @@ class ImpraIndex:
print('SIZE' +' '*5 , end='') print('SIZE' +' '*5 , end='')
print('PART' +' '*2 , end='') print('PART' +' '*2 , end='')
print('TYPE' +' '*2 , end='') print('TYPE' +' '*2 , end='')
print('OWNER' +' '*10, end='') print('USER ' +' '*10, end='')
Clz.print('CATEGORY'+' '*22, Clz.BG4+Clz.fgB7) Clz.print('CATEGORY'+' '*22, Clz.BG4+Clz.fgB7)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
@ -430,10 +461,10 @@ class ImpraIndex:
Clz.print(' '+str(k)[0:6]+'... ' , Clz.fgN2, False) Clz.print(' '+str(k)[0:6]+'... ' , Clz.fgN2, False)
if len(v[self.LABEL])>36 : a = '...' if len(v[self.LABEL])>36 : a = '...'
Clz.print(str(v[self.LABEL][:36]+a).ljust(40,' ') , Clz.fgN7, False) 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(formatBytes(int(v[self.SIZE]))[:8].rjust(8,' ')+' '*2 , Clz.fgN5, False)
Clz.print(str(v[self.PARTS]).rjust(2 ,'0') +' '*2 , Clz.fgN1, 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(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(self.getUser(str(v[self.USER])).ljust(16 ,' ') , Clz.fgn7, False)
Clz.print(str(v[self.CATG]) +' '*2 , Clz.fgN3) Clz.print(str(v[self.CATG]) +' '*2 , Clz.fgN3)
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
@ -509,7 +540,7 @@ class ImpraStorage:
tstamp = self.conf.get('time' ,'index') tstamp = self.conf.get('time' ,'index')
if nid is None : nid = 0 if nid is None : nid = 0
refresh = False refresh = False
if tstamp is not None and (datetime.now() - datetime.strptime(tstamp[:-7], '%Y-%m-%d %H:%M:%S')) < timedelta(minutes = 1) : if tstamp is not None and (datetime.now() - datetime.strptime(tstamp[:-7], '%Y-%m-%d %H:%M:%S')) < timedelta(minutes = 3) :
# getFromFile # getFromFile
if uid != None and file_exists(self.pathInd): # int(self.idx) == int(uid) if uid != None and file_exists(self.pathInd): # int(self.idx) == int(uid)
self.idx = uid self.idx = uid
@ -584,11 +615,11 @@ class ImpraStorage:
lsrv = self.ih.searchBySubject(subject,True) lsrv = self.ih.searchBySubject(subject,True)
return [ i for i in set(lloc).difference(set(lsrv))] return [ i for i in set(lloc).difference(set(lsrv))]
def addFile(self, path, label, usr='all', catg=''): def addFile(self, path, label, catg=''):
"""""" """"""
done = False done = False
from impra.util import DEBUG, DEBUG_LEVEL, DEBUG_NOTICE, DEBUG_WARN, DEBUG_INFO from impra.util import DEBUG, DEBUG_LEVEL, DEBUG_NOTICE, DEBUG_WARN, DEBUG_INFO
rt = RuTime(eval(__CALLER__('"%s","%s","%s"' % (path[:13]+'...',label,usr))),DEBUG_INFO) rt = RuTime(eval(__CALLER__('"%s","%s","%s"' % (path[:13]+'...',label,catg))),DEBUG_INFO)
_, ext = splitext(path) _, ext = splitext(path)
@ -617,6 +648,7 @@ class ImpraStorage:
for v in hlst['data']: for v in hlst['data']:
print(v) print(v)
usr = self.conf.get('name','infos')
ownerHash = self.mb.getHashName(usr) ownerHash = self.mb.getHashName(usr)
self.index.addUser(usr,ownerHash) self.index.addUser(usr,ownerHash)
@ -624,12 +656,12 @@ class ImpraStorage:
sendIds = [] sendIds = []
test = True test = True
for row in hlst['data'] : 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') msg = self.mb.build(usr,'all',hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr')
mid = self.ih.send(msg.as_string(), self.rootBox) mid = self.ih.send(msg.as_string(), self.rootBox)
if mid is not None : if mid is not None :
print(' ',end='') print(' ',end='')
Clz.print('part ' , Clz.fgn7, False) Clz.print('part ' , Clz.fgn7, False)
Clz.print(str(row[0]) , Clz.fgB1, False) Clz.print(str(row[0]) , Clz.fgB2, False)
Clz.print(' sent as msg ', Clz.fgn7, False) Clz.print(' sent as msg ', Clz.fgn7, False)
Clz.print(str(mid[1]) , Clz.fgB1) Clz.print(str(mid[1]) , Clz.fgB1)
sendIds.append((mid[1],row)) sendIds.append((mid[1],row))
@ -653,7 +685,7 @@ class ImpraStorage:
Clz.print(' error when sending, missing parts :', Clz.fgB1) Clz.print(' error when sending, missing parts :', Clz.fgB1)
print(diff) print(diff)
for mid, row in sendIds : 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') msg = self.mb.build(usr,'all',hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr')
Clz.print(' resending part ' , Clz.fgn7, False) Clz.print(' resending part ' , Clz.fgn7, False)
Clz.print(str(row[0]) , Clz.fgN2, False) Clz.print(str(row[0]) , Clz.fgN2, False)
mid = self.ih.send(msg.as_string(), self.rootBox) mid = self.ih.send(msg.as_string(), self.rootBox)
@ -731,9 +763,7 @@ class ImpraStorage:
hlst = ck.getHashList(key,row[ImpraIndex.PARTS],True) hlst = ck.getHashList(key,row[ImpraIndex.PARTS],True)
ids = self._getIdsBySubject(hlst['head'][2]) ids = self._getIdsBySubject(hlst['head'][2])
if len(ids) >= row[ImpraIndex.PARTS]: if len(ids) >= row[ImpraIndex.PARTS]:
status, resp = self.ih.srv.fetch(ids[0],'(BODY[HEADER.FIELDS (TO)])')
to = bstr(resp[0][1][4:-4])
if to == self.mb.getHashName('all')+'@'+self.mb.DOMAIN_NAME or to == self.mb.getHashName(self.conf.ini.get('name',self.conf.profile+'.infos'))+'@'+self.mb.DOMAIN_NAME :
for mid in ids : for mid in ids :
self.ih.downloadAttachment(mid,self.fsplit.DIR_INBOX) self.ih.downloadAttachment(mid,self.fsplit.DIR_INBOX)
if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE :
@ -745,15 +775,10 @@ class ImpraStorage:
self.decryptTextFile(path) self.decryptTextFile(path)
print() print()
Clz.print(' deploying in ', Clz.fgn7) Clz.print(' deploying in ', Clz.fgn7)
Clz.print(dirname(path), Clz.fgB2) Clz.print(' '+dirname(path), Clz.fgB2)
print() print()
done = True done = True
else :
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 : else :
print() print()
Clz.print(' == `' , Clz.bg3+Clz.fgB4, False) Clz.print(' == `' , Clz.bg3+Clz.fgB4, False)

View File

@ -10,53 +10,21 @@ from ctypes import windll, Structure, c_short as SHORT, c_ushort as WORD, byref
class COORD(Structure): class COORD(Structure):
"""struct in wincon.h.""" """struct in wincon.h."""
_fields_ = [ _fields_ = [("X", SHORT),("Y", SHORT)]
("X", SHORT),
("Y", SHORT)]
class SMALL_RECT(Structure): class SMALL_RECT(Structure):
"""struct in wincon.h.""" """struct in wincon.h."""
_fields_ = [ _fields_ = [("Left", SHORT),("Top", SHORT),("Right", SHORT),("Bottom", SHORT)]
("Left", SHORT),
("Top", SHORT),
("Right", SHORT),
("Bottom", SHORT)]
class CONSOLE_SCREEN_BUFFER_INFO(Structure): class CONSOLE_SCREEN_BUFFER_INFO(Structure):
"""struct in wincon.h.""" """struct in wincon.h."""
_fields_ = [ _fields_ = [("dwSize", COORD),("dwCursorPosition", COORD),("wAttributes", WORD),("srWindow", SMALL_RECT),("dwMaximumWindowSize", COORD)]
("dwSize", COORD),
("dwCursorPosition", COORD),
("wAttributes", WORD),
("srWindow", SMALL_RECT),
("dwMaximumWindowSize", COORD)]
# winbase.h # winbase.h
STD_INPUT_HANDLE = -10 STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11 STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE = -12 STD_ERROR_HANDLE = -12
# wincon.h
FOREGROUND_BLACK = 0x0000
FOREGROUND_BLUE = 0x0001
FOREGROUND_GREEN = 0x0002
FOREGROUND_CYAN = 0x0003
FOREGROUND_RED = 0x0004
FOREGROUND_MAGENTA = 0x0005
FOREGROUND_YELLOW = 0x0006
FOREGROUND_GREY = 0x0007
FOREGROUND_INTENSITY = 0x0008 # foreground color is intensified.
BACKGROUND_BLACK = 0x0000
BACKGROUND_BLUE = 0x0010
BACKGROUND_GREEN = 0x0020
BACKGROUND_CYAN = 0x0030
BACKGROUND_RED = 0x0040
BACKGROUND_MAGENTA = 0x0050
BACKGROUND_YELLOW = 0x0060
BACKGROUND_GREY = 0x0070
BACKGROUND_INTENSITY = 0x0080 # background color is intensified.
stdout_handle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) stdout_handle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute
GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo