...
This commit is contained in:
parent
c3a098d0d6
commit
370d010b2c
12
impra/cli.py
12
impra/cli.py
|
@ -30,7 +30,7 @@
|
||||||
# ~~ package cli ~~
|
# ~~ package cli ~~
|
||||||
|
|
||||||
from optparse import OptionParser, OptionGroup
|
from optparse import OptionParser, OptionGroup
|
||||||
import sys
|
import sys, os, platform
|
||||||
import impra.crypt as crypt
|
import impra.crypt as crypt
|
||||||
import impra.util as util
|
import impra.util as util
|
||||||
import impra.core as core
|
import impra.core as core
|
||||||
|
@ -177,7 +177,6 @@ data command Examples:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# ~~ conf CMD ~~
|
# ~~ conf CMD ~~
|
||||||
if a[0] == 'conf' :
|
if a[0] == 'conf' :
|
||||||
|
@ -267,7 +266,9 @@ you can remove index but all presents files on the box %s will be unrecoverable
|
||||||
print(mid,status,resp)
|
print(mid,status,resp)
|
||||||
|
|
||||||
elif o.add :
|
elif o.add :
|
||||||
impst.addFile(o.add[0],o.add[1],o.user,o.category)
|
done = impst.addFile(o.add[0],o.add[1],o.user,o.category)
|
||||||
|
if done :
|
||||||
|
print('OK')
|
||||||
|
|
||||||
elif o.get :
|
elif o.get :
|
||||||
ids = []
|
ids = []
|
||||||
|
@ -277,7 +278,10 @@ you can remove index but all presents files on the box %s will be unrecoverable
|
||||||
else: ids.append(sid)
|
else: ids.append(sid)
|
||||||
for sid in ids :
|
for sid in ids :
|
||||||
key = impst.index.getById(str(sid))
|
key = impst.index.getById(str(sid))
|
||||||
if key !=None : impst.getFile(key)
|
if key !=None :
|
||||||
|
done = impst.getFile(key)
|
||||||
|
if done :
|
||||||
|
print('OK')
|
||||||
else: print('-- `%s` is not a valid id --' % sid)
|
else: print('-- `%s` is not a valid id --' % sid)
|
||||||
|
|
||||||
elif o.search :
|
elif o.search :
|
||||||
|
|
|
@ -46,7 +46,7 @@ from os.path import abspath, dirname, join, realpath, basename, get
|
||||||
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
|
||||||
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, C
|
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, C, clear
|
||||||
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
|
||||||
|
|
||||||
LINE_SEP = C.IBLACK+'―'*120+C.OFF
|
LINE_SEP = C.IBLACK+'―'*120+C.OFF
|
||||||
|
@ -394,6 +394,7 @@ class ImpraIndex:
|
||||||
def print(self,header='', matchIds=None):
|
def print(self,header='', matchIds=None):
|
||||||
"""Print index content as formated bloc"""
|
"""Print index content as formated bloc"""
|
||||||
data = self.toString(matchIds).split(self.SEP_ITEM)
|
data = self.toString(matchIds).split(self.SEP_ITEM)
|
||||||
|
clear()
|
||||||
print(header)
|
print(header)
|
||||||
print(C.ON_IBLACK+' \
|
print(C.ON_IBLACK+' \
|
||||||
%s%s%s' % (C.BYELLOW,'ID' ,' '*1 )+'\
|
%s%s%s' % (C.BYELLOW,'ID' ,' '*1 )+'\
|
||||||
|
@ -500,22 +501,22 @@ class ImpraStorage:
|
||||||
nid = self.conf.get('nid' ,'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
|
if nid is None : nid = 0
|
||||||
|
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 = 1) :
|
||||||
# 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
|
||||||
encData = get_file_content(self.pathInd)
|
encData = get_file_content(self.pathInd)
|
||||||
print('--\nindex in cache')
|
else: refresh = True
|
||||||
else :
|
else: refresh = True
|
||||||
print('refresh index')
|
if refresh :
|
||||||
self._getIdIndex()
|
self._getIdIndex()
|
||||||
if self.idx :
|
if self.idx :
|
||||||
encData = self._getCryptIndex()
|
encData = self._getCryptIndex()
|
||||||
with open(self.pathInd, mode='w', encoding='utf-8') as o:
|
with open(self.pathInd, mode='w', encoding='utf-8') as o:
|
||||||
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(), int(nid))
|
||||||
rt.stop()
|
rt.stop()
|
||||||
return index
|
return index
|
||||||
|
@ -526,7 +527,9 @@ class ImpraStorage:
|
||||||
if self.idx :
|
if self.idx :
|
||||||
self.ih.delete(self.idx, True)
|
self.ih.delete(self.idx, True)
|
||||||
self.ih.deleteBin()
|
self.ih.deleteBin()
|
||||||
self.conf.rem('*','index')
|
self.conf.rem('*','index')
|
||||||
|
self.idx = None
|
||||||
|
remove(self.pathInd)
|
||||||
|
|
||||||
def saveIndex(self):
|
def saveIndex(self):
|
||||||
""""""
|
""""""
|
||||||
|
@ -547,6 +550,7 @@ class ImpraStorage:
|
||||||
self.conf.set('time',str(datetime.now()),'index')
|
self.conf.set('time',str(datetime.now()),'index')
|
||||||
self.clean()
|
self.clean()
|
||||||
rt.stop()
|
rt.stop()
|
||||||
|
return True
|
||||||
|
|
||||||
def encryptTextFile(self,path):
|
def encryptTextFile(self,path):
|
||||||
""""""
|
""""""
|
||||||
|
@ -563,6 +567,7 @@ class ImpraStorage:
|
||||||
|
|
||||||
def addFile(self, path, label, usr='all', catg=''):
|
def addFile(self, path, label, usr='all', catg=''):
|
||||||
""""""
|
""""""
|
||||||
|
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,usr))),DEBUG_INFO)
|
||||||
|
|
||||||
|
@ -619,17 +624,19 @@ class ImpraStorage:
|
||||||
|
|
||||||
else :
|
else :
|
||||||
self.index.add(hlst['head'][3],label,hlst['head'][1],ext,ownerHash,catg,md5,bFlag)
|
self.index.add(hlst['head'][3],label,hlst['head'][1],ext,ownerHash,catg,md5,bFlag)
|
||||||
self.saveIndex()
|
done = self.saveIndex()
|
||||||
self.conf.set('nid', str(self.index.id),'index')
|
self.conf.set('nid', str(self.index.id),'index')
|
||||||
else :
|
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('--\nfile already exist on server as `%s` [id:%i]\n' % (self.index.dic[md5][ImpraIndex.LABEL],self.index.dic[md5][ImpraIndex.UID]))
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
print(e)
|
print(e)
|
||||||
rt.stop()
|
rt.stop()
|
||||||
|
return done
|
||||||
|
|
||||||
def getFile(self,key):
|
def getFile(self,key):
|
||||||
""""""
|
""""""
|
||||||
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
|
||||||
|
done = False
|
||||||
row = self.index.get(key)
|
row = self.index.get(key)
|
||||||
if row==None :
|
if row==None :
|
||||||
print('--\n%s not on the server' % key)
|
print('--\n%s not on the server' % key)
|
||||||
|
@ -651,12 +658,14 @@ class ImpraStorage:
|
||||||
path = self.fsplit.deployFile(hlst, row[ImpraIndex.LABEL], row[ImpraIndex.EXT], row[ImpraIndex.UID], row[ImpraIndex.CATG])
|
path = self.fsplit.deployFile(hlst, row[ImpraIndex.LABEL], row[ImpraIndex.EXT], row[ImpraIndex.UID], row[ImpraIndex.CATG])
|
||||||
if row[ImpraIndex.BFLAG] == ImpraIndex.FILE_CRYPT:
|
if row[ImpraIndex.BFLAG] == ImpraIndex.FILE_CRYPT:
|
||||||
self.decryptTextFile(path)
|
self.decryptTextFile(path)
|
||||||
|
done = True
|
||||||
else :
|
else :
|
||||||
print('--\n`%s` is private' % row[ImpraIndex.LABEL])
|
print('--\n`%s` is private' % row[ImpraIndex.LABEL])
|
||||||
else :
|
else :
|
||||||
print('--\n`%s` invalid count parts %i/%i' %(row[ImpraIndex.LABEL],len(ids),row[ImpraIndex.PARTS]))
|
print('--\n`%s` invalid count parts %i/%i' %(row[ImpraIndex.LABEL],len(ids),row[ImpraIndex.PARTS]))
|
||||||
|
|
||||||
rt.stop()
|
rt.stop()
|
||||||
|
return done
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
""""""
|
""""""
|
||||||
|
|
|
@ -34,12 +34,13 @@ from inspect import stack
|
||||||
from errno import EEXIST
|
from errno import EEXIST
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from math import log, floor, ceil
|
from math import log, floor, ceil
|
||||||
from os import urandom, popen, sep, makedirs
|
from os import urandom, popen, sep, makedirs, system
|
||||||
from os.path import dirname, realpath, abspath, join
|
from os.path import dirname, realpath, abspath, join
|
||||||
from random import choice
|
from random import choice
|
||||||
from re import split as regsplit
|
from re import split as regsplit
|
||||||
from subprocess import PIPE, Popen
|
from subprocess import PIPE, Popen
|
||||||
from sys import stderr, executable as pyexec
|
from sys import stderr, executable as pyexec
|
||||||
|
import platform
|
||||||
#~ from sys.stdout import isatty
|
#~ from sys.stdout import isatty
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
@ -190,35 +191,10 @@ def __CALLER__(args=''):
|
||||||
else: val += "'"
|
else: val += "'"
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def hilite(string, color=32, bold=True):
|
if platform.system() == 'Windows' :
|
||||||
""""""
|
clear = lambda: system('cls')
|
||||||
global COLOR_MODE
|
else : clear = lambda: system('clear')
|
||||||
if COLOR_MODE and True:
|
|
||||||
attr = [color]
|
|
||||||
if bold:
|
|
||||||
attr.append('1')
|
|
||||||
|
|
||||||
#~ 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')
|
|
||||||
|
|
||||||
string = '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
|
|
||||||
print(string)
|
|
||||||
return string
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# ~~ class RuTime ~~
|
# ~~ class RuTime ~~
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
from impra.core import ImpraConf, ImpraStorage
|
from impra.core import ImpraConf, ImpraStorage
|
||||||
from impra.util import IniFile, RuTime, get_file_path
|
from impra.util import IniFile, RuTime, get_file_path
|
||||||
from impra.cli import Cli
|
from impra.cli import Cli
|
||||||
|
import sys, os
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#~ try :
|
#~ try :
|
||||||
|
@ -50,7 +50,9 @@ if __name__ == '__main__':
|
||||||
#~ print('\033[1;46mHighlighted Cyan like Caribbean\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;47mHighlighted Gray like Ghost\033[1;m')
|
||||||
#~ print('\033[1;48mHighlighted Crimson like Chianti\033[1;m')
|
#~ print('\033[1;48mHighlighted Crimson like Chianti\033[1;m')
|
||||||
Cli(get_file_path(__file__ ))
|
Cli(get_file_path(__file__ ))
|
||||||
|
#os.system('echo python imprastorage data -l')
|
||||||
|
|
||||||
#~ except Exception as e :
|
#~ except Exception as e :
|
||||||
#~ print(e)
|
#~ print(e)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user