bugfix cli windows
This commit is contained in:
parent
193f425d66
commit
f014414041
|
@ -145,7 +145,7 @@ class Cli:
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# ~~ conf CMD ~~
|
# ~~ conf CMD ~~
|
||||||
if a[0] == 'conf' :
|
if a[0] == 'conf' :
|
||||||
self.print_header()
|
core.clear()
|
||||||
if o.load is not None or o.view is not None or o.save is not None :
|
if o.load is not None or o.view is not None or o.save is not None :
|
||||||
|
|
||||||
if o.view is not None :
|
if o.view is not None :
|
||||||
|
@ -159,9 +159,12 @@ class Cli:
|
||||||
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 : self.load_profile(o)
|
if o.load :
|
||||||
|
self.print_header()
|
||||||
|
self.load_profile(o)
|
||||||
|
|
||||||
elif o.view :
|
elif o.view :
|
||||||
|
self.print_header()
|
||||||
if o.view == 'all' :
|
if o.view == 'all' :
|
||||||
sections = self.ini.getSections()
|
sections = self.ini.getSections()
|
||||||
if len(sections) > 0:
|
if len(sections) > 0:
|
||||||
|
@ -170,6 +173,7 @@ class Cli:
|
||||||
else: self.ini.print(o.view)
|
else: self.ini.print(o.view)
|
||||||
|
|
||||||
elif o.save :
|
elif o.save :
|
||||||
|
self.print_header()
|
||||||
if not o.set_host and not o.set_user and not o.set_pass and not o.set_port and not o.set_boxname and not o.set_name and not o.gen_key:
|
if not o.set_host and not o.set_user and not o.set_pass and not o.set_port and not o.set_boxname and not o.set_name and not o.gen_key:
|
||||||
parser.error(' no options specified')
|
parser.error(' no options specified')
|
||||||
else :
|
else :
|
||||||
|
@ -193,6 +197,7 @@ class Cli:
|
||||||
self.ini.write()
|
self.ini.write()
|
||||||
self.ini.print(o.active_profile)
|
self.ini.print(o.active_profile)
|
||||||
elif o.check :
|
elif o.check :
|
||||||
|
self.print_header()
|
||||||
self.check_profile(o.check, True)
|
self.check_profile(o.check, True)
|
||||||
|
|
||||||
else :
|
else :
|
||||||
|
|
|
@ -264,7 +264,7 @@ class ImpraIndex:
|
||||||
COLS = ('HASH','LABEL','PART','TYPE','USER','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={}):
|
||||||
"""Initialize the index with rsa and encoded data
|
"""Initialize the index with rsa and encoded data
|
||||||
|
|
||||||
:Parameters:
|
:Parameters:
|
||||||
|
@ -278,9 +278,12 @@ class ImpraIndex:
|
||||||
"""
|
"""
|
||||||
self.km = Kirmah(key, mark)
|
self.km = Kirmah(key, mark)
|
||||||
self.dic = {}
|
self.dic = {}
|
||||||
self.id = id
|
if encdata =='' :
|
||||||
if encdata =='' : self.dic = {}
|
self.dic = {}
|
||||||
else : self.dic = self.decrypt(encdata)
|
self.id = 1
|
||||||
|
else :
|
||||||
|
self.dic = self.decrypt(encdata)
|
||||||
|
self.id = max([self.dic[k][self.UID] for i, k in enumerate(self.dic) if not k.startswith(self.SEP_KEY_INTERN)])+1
|
||||||
for k in dicCategory :
|
for k in dicCategory :
|
||||||
if not self.SEP_KEY_INTERN+k in self.dic:
|
if not self.SEP_KEY_INTERN+k in self.dic:
|
||||||
self.dic[self.SEP_KEY_INTERN+k] = dicCategory[k]
|
self.dic[self.SEP_KEY_INTERN+k] = dicCategory[k]
|
||||||
|
@ -364,6 +367,29 @@ class ImpraIndex:
|
||||||
rt.stop()
|
rt.stop()
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
def fixDuplicateIds(self):
|
||||||
|
"""Get corresponding keys of duplicate ids in the index
|
||||||
|
:Returns: `str`|None key
|
||||||
|
"""
|
||||||
|
rt = RuTime(eval(__CALLER__()))
|
||||||
|
r = [k for i, k in enumerate(self.dic) if not k.startswith(self.SEP_KEY_INTERN)]
|
||||||
|
l = [(k,self.dic[k][self.UID]) for k in r]
|
||||||
|
l2 = [k[1] for k in l]
|
||||||
|
mxid = max(l2)
|
||||||
|
import collections
|
||||||
|
l3 = [x for x, y in collections.Counter(l2).items() if y > 1]
|
||||||
|
d = [k[0] for k in l if any( k[1] == v for v in l3)]
|
||||||
|
for k in d:
|
||||||
|
mxid += 1
|
||||||
|
print(self.dic[k])
|
||||||
|
t = list(self.dic[k])
|
||||||
|
t[self.UID] = mxid
|
||||||
|
print(t)
|
||||||
|
self.dic[k] = tuple(t)
|
||||||
|
self.id = mxid+1
|
||||||
|
rt.stop()
|
||||||
|
return len(d)>0
|
||||||
|
|
||||||
def getByLabel(self,label):
|
def getByLabel(self,label):
|
||||||
"""Get the corresponding label in the index
|
"""Get the corresponding label in the index
|
||||||
:Returns: `str`|None key
|
:Returns: `str`|None key
|
||||||
|
@ -449,7 +475,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('USER ' +' '*10, end='')
|
print('USER' +' '*11, 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)
|
||||||
|
|
||||||
|
@ -465,7 +491,7 @@ class ImpraIndex:
|
||||||
Clz.print(formatBytes(int(v[self.SIZE]))[:8].rjust(8,' ')+' '*2 , 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.USER])).ljust(16 ,' ') , Clz.fgn7, False)
|
Clz.print(self.getUser(str(v[self.USER])).ljust(15 ,' ') , 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)
|
||||||
|
@ -487,7 +513,11 @@ class ImpraStorage:
|
||||||
self.pathInd = dirname(self.conf.ini.path)+sep+'.index'
|
self.pathInd = dirname(self.conf.ini.path)+sep+'.index'
|
||||||
self.rootBox = self.conf.get('box','imap')
|
self.rootBox = self.conf.get('box','imap')
|
||||||
iconf = ImapConfig(self.conf.get('host','imap'), self.conf.get('port','imap'), self.conf.get('user', 'imap'), self.conf.get('pass', 'imap'))
|
iconf = ImapConfig(self.conf.get('host','imap'), self.conf.get('port','imap'), self.conf.get('user', 'imap'), self.conf.get('pass', 'imap'))
|
||||||
self.ih = ImapHelper(iconf,self.rootBox)
|
try :
|
||||||
|
self.ih = ImapHelper(iconf,self.rootBox)
|
||||||
|
except Exception as e:
|
||||||
|
print('Error : '+e)
|
||||||
|
print('check your connection or your imap config')
|
||||||
self.mb = MailBuilder(self.conf.get('salt','keys'))
|
self.mb = MailBuilder(self.conf.get('salt','keys'))
|
||||||
self.fsplit = FSplitter(ConfigKey(),self.wkdir)
|
self.fsplit = FSplitter(ConfigKey(),self.wkdir)
|
||||||
self.delids = []
|
self.delids = []
|
||||||
|
@ -529,7 +559,7 @@ class ImpraStorage:
|
||||||
usrName = self.conf.get('name','infos')
|
usrName = self.conf.get('name','infos')
|
||||||
return {'catg':self.conf.get('types','catg'), 'users':{ ('%s' % self.mb.getHashName('all')) : 'all', ('%s' % self.mb.getHashName(usrName)) : usrName}}
|
return {'catg':self.conf.get('types','catg'), 'users':{ ('%s' % self.mb.getHashName('all')) : 'all', ('%s' % self.mb.getHashName(usrName)) : usrName}}
|
||||||
|
|
||||||
def getIndex(self):
|
def getIndex(self, forceRefresh=False):
|
||||||
""""""
|
""""""
|
||||||
from impra.util import DEBUG, DEBUG_LEVEL, DEBUG_WARN, DEBUG_INFO
|
from impra.util import DEBUG, DEBUG_LEVEL, DEBUG_WARN, DEBUG_INFO
|
||||||
rt = RuTime(eval(__CALLER__()),DEBUG_INFO)
|
rt = RuTime(eval(__CALLER__()),DEBUG_INFO)
|
||||||
|
@ -537,11 +567,9 @@ class ImpraStorage:
|
||||||
encData = ''
|
encData = ''
|
||||||
uid = self.conf.get('uid' ,'index')
|
uid = self.conf.get('uid' ,'index')
|
||||||
date = self.conf.get('date ','index')
|
date = self.conf.get('date ','index')
|
||||||
nid = self.conf.get('nid' ,'index')
|
|
||||||
tstamp = self.conf.get('time' ,'index')
|
tstamp = self.conf.get('time' ,'index')
|
||||||
if nid is None : nid = 0
|
refresh = forceRefresh
|
||||||
refresh = False
|
if not refresh and 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
|
||||||
|
@ -558,7 +586,7 @@ class ImpraStorage:
|
||||||
o.write(encData)
|
o.write(encData)
|
||||||
self.conf.set('time',str(datetime.now()),'index')
|
self.conf.set('time',str(datetime.now()),'index')
|
||||||
|
|
||||||
index = ImpraIndex(self.conf.get('key','keys'),self.conf.get('mark','keys'), encData, self.getIndexDefaultCatg(), int(nid))
|
index = ImpraIndex(self.conf.get('key','keys'),self.conf.get('mark','keys'), encData, self.getIndexDefaultCatg())
|
||||||
rt.stop()
|
rt.stop()
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
@ -583,6 +611,7 @@ class ImpraStorage:
|
||||||
#~ Clz.print('\n expunge, waiting server...\n', Clz.fgB1)
|
#~ Clz.print('\n expunge, waiting server...\n', Clz.fgB1)
|
||||||
#~ self.srv.expunge()
|
#~ self.srv.expunge()
|
||||||
#~ sleep(2)
|
#~ sleep(2)
|
||||||
|
self.index.fixDuplicateIds()
|
||||||
encData = self.index.encrypt()
|
encData = self.index.encrypt()
|
||||||
msgIndex = self.mb.buildIndex(encData)
|
msgIndex = self.mb.buildIndex(encData)
|
||||||
if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : print(msgIndex.as_string())
|
if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : print(msgIndex.as_string())
|
||||||
|
@ -620,7 +649,7 @@ class ImpraStorage:
|
||||||
""""""
|
""""""
|
||||||
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,catg))),DEBUG_INFO)
|
rt = RuTime(eval(__CALLER__()),DEBUG_INFO)
|
||||||
|
|
||||||
_, ext = splitext(path)
|
_, ext = splitext(path)
|
||||||
try:
|
try:
|
||||||
|
@ -672,14 +701,12 @@ class ImpraStorage:
|
||||||
print('\n-- error occured when sending part : %s\n-- retrying' % row[0])
|
print('\n-- error occured when sending part : %s\n-- retrying' % row[0])
|
||||||
print()
|
print()
|
||||||
if not cancel :
|
if not cancel :
|
||||||
self.index.add(hlst['head'][3],label,hlst['head'][1],ext,ownerHash,catg,md5,bFlag,size)
|
|
||||||
diff = self.checkSendIds(sendIds,hlst['head'][2])
|
diff = self.checkSendIds(sendIds,hlst['head'][2])
|
||||||
for mid in diff :
|
for mid in diff :
|
||||||
if mid > 0:
|
if mid > 0:
|
||||||
print(mid)
|
print(mid)
|
||||||
#self.ih.delete(str(mid), True, False)
|
#self.ih.delete(str(mid), True, False)
|
||||||
print('toto')
|
|
||||||
self.conf.set('nid', str(self.index.id),'index')
|
|
||||||
if len(diff) > 0 :
|
if len(diff) > 0 :
|
||||||
Clz.print(' error when sending, missing parts :', Clz.fgB1)
|
Clz.print(' error when sending, missing parts :', Clz.fgB1)
|
||||||
for mid in diff :
|
for mid in diff :
|
||||||
|
@ -694,6 +721,8 @@ class ImpraStorage:
|
||||||
else :
|
else :
|
||||||
print()
|
print()
|
||||||
#Clz.print(' index intall files checked\n', Clz.fgB2)
|
#Clz.print(' index intall files checked\n', Clz.fgB2)
|
||||||
|
self.index = self.getIndex(True)
|
||||||
|
self.index.add(hlst['head'][3],label,hlst['head'][1],ext,ownerHash,catg,md5,bFlag,size)
|
||||||
done = self.saveIndex()
|
done = self.saveIndex()
|
||||||
|
|
||||||
# clean
|
# clean
|
||||||
|
@ -743,6 +772,7 @@ class ImpraStorage:
|
||||||
Clz.print('\n expunge, waiting pls...\n', Clz.fgB1)
|
Clz.print('\n expunge, waiting pls...\n', Clz.fgB1)
|
||||||
self.ih.srv.expunge()
|
self.ih.srv.expunge()
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
|
self.index = self.getIndex(True)
|
||||||
self.index.rem(key)
|
self.index.rem(key)
|
||||||
done = self.saveIndex()
|
done = self.saveIndex()
|
||||||
rt.stop()
|
rt.stop()
|
||||||
|
|
|
@ -344,7 +344,11 @@ class IniFile:
|
||||||
if len(self.dic[s][k]) > 50: a = '...'
|
if len(self.dic[s][k]) > 50: a = '...'
|
||||||
Clz.print(k.ljust(10,' ')+' = ' , Clz.fgn7, False)
|
Clz.print(k.ljust(10,' ')+' = ' , Clz.fgn7, False)
|
||||||
if Clz.isUnix or k is not 'key' :
|
if Clz.isUnix or k is not 'key' :
|
||||||
Clz.print(self.dic[s][k][:50]+a, Clz.fgN2)
|
try :
|
||||||
|
Clz.print(self.dic[s][k][:50]+a, Clz.fgN2)
|
||||||
|
except Exception as e:
|
||||||
|
Clz.print('value is masked - generate errors in your os', Clz.fgb1)
|
||||||
|
pass
|
||||||
else: Clz.print('key is masked', Clz.fgb1)
|
else: Clz.print('key is masked', Clz.fgb1)
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user