windows cli
This commit is contained in:
parent
46bb274636
commit
193f425d66
7
cmd.bat
Normal file
7
cmd.bat
Normal file
|
@ -0,0 +1,7 @@
|
|||
@echo off
|
||||
TITLE ImpraStorage (GNU GPLv3)
|
||||
set cmd=''
|
||||
set /P cmd=imprastorage %=%
|
||||
set acmd=%cmd:"='%
|
||||
imprastorage.exe %cmd%
|
||||
cmd.bat
|
99
impra/cli.py
99
impra/cli.py
|
@ -98,13 +98,11 @@ class Cli:
|
|||
parser = _OptionParser()
|
||||
parser.print_help = self.print_help
|
||||
parser.print_usage = self.print_usage
|
||||
|
||||
gpData = OptionGroup(parser, '\n------------------------------------\ndata related Options (command data)')
|
||||
gpConf = OptionGroup(parser, '\n------------------------------------\nconf related Options (command conf)')
|
||||
|
||||
self.wkpath = path+core.sep+'wk'+core.sep
|
||||
gpData = OptionGroup(parser, '')
|
||||
gpConf = OptionGroup(parser, '')
|
||||
|
||||
# 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)
|
||||
|
||||
|
@ -134,22 +132,14 @@ class Cli:
|
|||
print()
|
||||
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)
|
||||
self.parserError(' no commando specified')
|
||||
else :
|
||||
core.clear()
|
||||
parser.print_help()
|
||||
except :
|
||||
parser.error(' no commando specified')
|
||||
sys.exit(1)
|
||||
self.parserError(' no commando specified')
|
||||
|
||||
else:
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -185,7 +175,8 @@ class Cli:
|
|||
else :
|
||||
if o.set_port and not util.represents_int(o.set_port):
|
||||
parser.error(' port must be a number')
|
||||
sys.exit(1)
|
||||
self.exit(1)
|
||||
else :
|
||||
if o.set_boxname: self.ini.set('box' , o.set_boxname,o.active_profile+'.imap')
|
||||
if o.set_host: self.ini.set('host', o.set_host,o.active_profile+'.imap')
|
||||
if o.set_user: self.ini.set('user', o.set_user,o.active_profile+'.imap')
|
||||
|
@ -207,6 +198,10 @@ class Cli:
|
|||
else :
|
||||
self.print_usage('')
|
||||
|
||||
elif a[0] == 'help':
|
||||
core.clear()
|
||||
parser.print_help()
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# ~~ data CMD ~~
|
||||
elif a[0] == 'list' or a[0] == 'add' or a[0] == 'get' or a[0] == 'remove' or a[0] == 'search' :
|
||||
|
@ -215,11 +210,12 @@ class Cli:
|
|||
|
||||
|
||||
if self.check_profile(o.active_profile):
|
||||
core.clear()
|
||||
self.print_header()
|
||||
conf = core.ImpraConf(self.ini,o.active_profile)
|
||||
impst = None
|
||||
try:
|
||||
impst = core.ImpraStorage(conf)
|
||||
impst = core.ImpraStorage(conf, False, self.wkpath)
|
||||
except crypt.BadKeyException as e :
|
||||
print()
|
||||
Clz.print(' it seems that your current profile `' , Clz.fgB1, False)
|
||||
|
@ -232,13 +228,13 @@ class Cli:
|
|||
remIndex = input(' remove index ? (yes/no) ')
|
||||
if remIndex.lower()=='yes':
|
||||
Clz.print(' ',Clz.OFF)
|
||||
impst = core.ImpraStorage(conf, True)
|
||||
impst = core.ImpraStorage(conf, True, self.wkpath)
|
||||
|
||||
else :
|
||||
print()
|
||||
print(' bye')
|
||||
print()
|
||||
sys.exit(1)
|
||||
self.exit(1)
|
||||
|
||||
|
||||
if a[0]=='list':
|
||||
|
@ -284,7 +280,7 @@ class Cli:
|
|||
|
||||
elif a[0] == 'add':
|
||||
if not len(a)>1 : self.error_cmd('`'+a[0]+' need at least one argument',parser)
|
||||
|
||||
else:
|
||||
vfile = a[1]
|
||||
if util.file_exists(vfile) :
|
||||
if not len(a)>2 :
|
||||
|
@ -303,7 +299,7 @@ class Cli:
|
|||
elif a[0] == 'get':
|
||||
|
||||
if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser)
|
||||
|
||||
else:
|
||||
vid = a[1]
|
||||
ids = []
|
||||
for sid in vid.split(',') :
|
||||
|
@ -333,6 +329,8 @@ class Cli:
|
|||
account = conf.get('user','imap')
|
||||
|
||||
if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser)
|
||||
else :
|
||||
|
||||
vsearch = a[1]
|
||||
|
||||
matchIds = impst.index.getByPattern(vsearch)
|
||||
|
@ -386,13 +384,16 @@ class Cli:
|
|||
elif a[0] == 'remove':
|
||||
|
||||
if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser)
|
||||
else :
|
||||
|
||||
if not util.represents_int(a[1]):
|
||||
print('\n ',end='')
|
||||
Clz.print(' == `' , Clz.bg1+Clz.fgB7, False)
|
||||
Clz.print(a[1] , Clz.bg1+Clz.fgB3, False)
|
||||
Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7)
|
||||
print()
|
||||
sys.exit(1)
|
||||
self.exit(1)
|
||||
else :
|
||||
vid = a[1]
|
||||
key = impst.index.getById(vid)
|
||||
if key !=None :
|
||||
|
@ -414,8 +415,19 @@ class Cli:
|
|||
|
||||
|
||||
def error_cmd(self,msg, parser):
|
||||
parser.error(msg)
|
||||
sys.exit(1)
|
||||
core.clear()
|
||||
self.print_usage('')
|
||||
Clz.print('error : '+msg,Clz.fgB7)
|
||||
self.exit(1)
|
||||
|
||||
def parserError(self, msg):
|
||||
core.clear()
|
||||
self.print_usage('')
|
||||
Clz.print('error : '+msg,Clz.fgB7)
|
||||
self.exit(1)
|
||||
|
||||
def exit(self, code):
|
||||
if Clz.isUnix : sys.exit(code)
|
||||
|
||||
def check_profile(self,profile, activeCheck=False):
|
||||
""""""
|
||||
|
@ -427,7 +439,7 @@ class Cli:
|
|||
conf = core.ImpraConf(self.ini,profile)
|
||||
impst = None
|
||||
try:
|
||||
impst = core.ImpraStorage(conf)
|
||||
impst = core.ImpraStorage(conf, False, self.wkpath)
|
||||
Clz.print(' done...', Clz.fgB2)
|
||||
except crypt.BadKeyException as e :
|
||||
pass
|
||||
|
@ -469,27 +481,30 @@ class Cli:
|
|||
|
||||
Clz.print(' USAGE :\n', Clz.fgB3)
|
||||
Clz.print(' imprastorage ', Clz.fgb7, False)
|
||||
if Clz.isUnix:
|
||||
Clz.print('--help ', Clz.fgB3)
|
||||
else:
|
||||
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('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('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('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('id|ids', Clz.fgB1, False)
|
||||
Clz.print('}', Clz.fgB1)
|
||||
|
||||
Clz.print(' imprastorage ', Clz.fgb7, False)
|
||||
|
@ -497,45 +512,45 @@ class Cli:
|
|||
Clz.print('[', Clz.fgB3, False)
|
||||
Clz.print(' -c ', Clz.fgB3, False)
|
||||
Clz.print('{', Clz.fgB1, False)
|
||||
Clz.print('category', 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('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('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('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('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('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('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('colon', Clz.fgB1, False)
|
||||
Clz.print('}', Clz.fgB1, False)
|
||||
Clz.print(']', Clz.fgB3)
|
||||
|
||||
|
@ -545,14 +560,14 @@ class Cli:
|
|||
Clz.print('|', Clz.fgB1, False)
|
||||
Clz.print('-V ', Clz.fgB3, False)
|
||||
Clz.print('{', Clz.fgB1, False)
|
||||
Clz.print('profile', 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('profile', Clz.fgB1, False)
|
||||
Clz.print('} ', Clz.fgB1, False)
|
||||
Clz.print('[', Clz.fgB3, False)
|
||||
Clz.print(' -K', Clz.fgB3, False)
|
||||
|
@ -592,8 +607,6 @@ class Cli:
|
|||
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)
|
||||
|
@ -692,7 +705,7 @@ class Cli:
|
|||
""""""
|
||||
self.print_header()
|
||||
Clz.print(APP_DESC, Clz.fgN1)
|
||||
self.print_usage('', True)
|
||||
self.print_usage('',True)
|
||||
self.print_options()
|
||||
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
|
||||
print()
|
||||
|
|
|
@ -630,7 +630,7 @@ class ImpraStorage:
|
|||
print()
|
||||
Clz.print(' file : ' , Clz.fgn7, False)
|
||||
Clz.print(path , Clz.fgN1)
|
||||
Clz.print(' md5sum : ' , Clz.fgn7, False)
|
||||
Clz.print(' hash : ' , Clz.fgn7, False)
|
||||
Clz.print(md5 , Clz.fgN2)
|
||||
print()
|
||||
if not self.index.get(md5) :
|
||||
|
|
0
impra/imap.py
Executable file → Normal file
0
impra/imap.py
Executable file → Normal file
3
impra/util.py
Executable file → Normal file
3
impra/util.py
Executable file → Normal file
|
@ -51,7 +51,6 @@ DEBUG_INFO = 3
|
|||
|
||||
DEBUG = True
|
||||
DEBUG_LEVEL = DEBUG_INFO
|
||||
|
||||
COLOR_MODE = True
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -447,7 +446,7 @@ class Coloriz:
|
|||
# normal eq bold
|
||||
exec('self._wn%i = self._wf%i' % (i,i))
|
||||
# normal high intensity eq bold high intensity
|
||||
exec('self._wN%i = self._wB%i' % (i,i))
|
||||
exec('self._wN%i = self._wF%i' % (i,i))
|
||||
j += 1
|
||||
|
||||
if not self.isUnix :
|
||||
|
|
14
imprastorage.py
Executable file → Normal file
14
imprastorage.py
Executable file → Normal file
|
@ -26,8 +26,8 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with ImpraStorage. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from impra.core import ImpraConf, ImpraStorage
|
||||
from impra.util import IniFile, RuTime, get_file_path
|
||||
from impra.core import ImpraConf, ImpraStorage, realpath, dirname, abspath, sep
|
||||
from impra.util import IniFile, RuTime, get_file_path, Clz
|
||||
from impra.cli import Cli
|
||||
import sys, os
|
||||
|
||||
|
@ -38,6 +38,14 @@ import sys, os
|
|||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Cli(get_file_path(__file__ ))
|
||||
if not Clz.isUnix:
|
||||
if len(sys.argv)>1 and sys.argv[1] == '--run' :
|
||||
Cli.print_header(None)
|
||||
os.system(realpath('./cmd.bat'))
|
||||
elif len(sys.argv)==1 :
|
||||
os.system(realpath('./launcher.bat'))
|
||||
else: Cli(realpath('./')+sep)
|
||||
else :
|
||||
Cli(get_file_path(realpath('./')+sep))
|
||||
|
||||
#python -O -m compileall impra/*.py
|
||||
|
|
42
launcher.bat
42
launcher.bat
|
@ -1,60 +1,22 @@
|
|||
@Echo Off
|
||||
:: This first title is used to store the registry setting
|
||||
:: You can use it for the title of the First window, or change
|
||||
:: The Title of both windows after opening
|
||||
Set _Title=ImpraStorage
|
||||
:: Set Height in lines, Width in characters. Buffer width is set
|
||||
:: to the same value as the window width
|
||||
Set _Height=60
|
||||
Set _Width=122
|
||||
Set _BHeight=5000
|
||||
Set _BWidth=%_Width%
|
||||
:: Set position of the Top left corner in pixels
|
||||
:: Position is relative to the Top left corner of the screen
|
||||
Set _xPos=0
|
||||
Set _yPos=0
|
||||
:: Color values are the same as for the Color command
|
||||
Set _Color=1E
|
||||
:: Calculate hex values needed in the registry
|
||||
Set /A _BufferSize=_BHeight*0x10000+_BWidth
|
||||
Set /A _WindowPos=_yPos*0x10000+_xPos
|
||||
Set /A _WindowSize=_Height*0x10000+_Width
|
||||
:: This command will be passed to the Prompt to change the Title and Prompt
|
||||
:: The ampersand must be escaped
|
||||
:: Set _Cmd=Title Send^&Prompt $T$G
|
||||
:: Call :_OpenCP %_BufferSize% %_Color% %_WindowPos% %_WindowSize% "%_Title%" "%_CMD%"
|
||||
|
||||
:: Increase the _yPos value so 2nd window is below the first.
|
||||
:: 12 is the height in pixels for the font being used.
|
||||
:: 40 is a value to allow for the height of the Title Bar. Adjust as needed
|
||||
|
||||
::Set /A _yPos=_yPos+_Height*12+40
|
||||
::Set /A _WindowPos=_yPos*0x10000+_xPos
|
||||
|
||||
|
||||
:: 0 = Black 8 = Gray
|
||||
:: 1 = Blue 9 = Light Blue
|
||||
:: 2 = Green A = Light Green
|
||||
:: 3 = Aqua B = Light Aqua
|
||||
:: 4 = Red C = Light Red
|
||||
:: 5 = Purple D = Light Purple
|
||||
:: 6 = Yellow E = Light Yellow
|
||||
:: 7 = White F = Bright White
|
||||
|
||||
:: This command will be passed to the Prompt to change the Title, Prompt, and Color
|
||||
Set _Cmd=Title ImpraStorage^&Prompt $T$G^&Color 0F
|
||||
Set _Cmd=Title ^&Prompt ^&Color 0F^&ImpraStorage.exe --run
|
||||
Call :_OpenCP %_BufferSize% %_Color% %_WindowPos% %_WindowSize% "%_Title%" "%_CMD%"
|
||||
Goto :EOF
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
:: Subroutines
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
:_OpenCP
|
||||
Reg Add "HKCU\Console\%~5" /V ScreenBufferSize /T REG_DWORD /D %1 /F
|
||||
Reg Add "HKCU\Console\%~5" /V ScreenColors /T REG_DWORD /D 0x%2 /F
|
||||
Reg Add "HKCU\Console\%~5" /V WindowPosition /T REG_DWORD /D %3 /F
|
||||
Reg Add "HKCU\Console\%~5" /V WindowSize /T REG_DWORD /D %4 /F
|
||||
Start "%~5" %COMSPEC% /K %6
|
||||
:: Only one single command line is needed to receive user input
|
||||
FOR /F "tokens=*" %%A IN ('TYPE CON') DO SET INPUT=%%A
|
||||
:: Use quotes if you want to display redirection characters as well
|
||||
ECHO You typed: "%INPUT%"
|
||||
exit
|
|
@ -4,7 +4,10 @@ from cx_Freeze import setup, Executable
|
|||
productName = "ImpraStorage"
|
||||
|
||||
# Dependencies are automatically detected, but it might need fine tuning.
|
||||
build_exe_options = {"packages": ["os","subprocess","importlib","platform"], "excludes": ["tkinter"]}
|
||||
build_exe_options = {"packages": ["os","subprocess","importlib","platform"],
|
||||
"excludes": ["tkinter"],
|
||||
"include_files": [('launcher.bat','launcher.bat'),('cmd.bat','cmd.bat'),('wk','wk')]
|
||||
}
|
||||
|
||||
# GUI applications require a different base on Windows (the default is for a
|
||||
# console application).
|
||||
|
@ -18,15 +21,13 @@ base = None
|
|||
|
||||
|
||||
if 'bdist_msi' in sys.argv:
|
||||
sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + productName]
|
||||
sys.argv += ['--install-script', 'install.py']
|
||||
sys.argv += ['--initial-target-dir', 'C:\\' + productName]
|
||||
# sys.argv += ['--install-script', 'install.py']
|
||||
|
||||
exe = Executable(
|
||||
script="imprastorage.py",
|
||||
base=None,
|
||||
targetName="ImpraStorage.exe",
|
||||
targetDir="lib",
|
||||
shortcutName="ImpraStorage",
|
||||
targetName="imprastorage.exe"
|
||||
)
|
||||
setup(
|
||||
name="ImpraStorage.exe",
|
||||
|
@ -34,15 +35,15 @@ if 'bdist_msi' in sys.argv:
|
|||
author="a-Sansara",
|
||||
description="ImpraStorage provided a private imap access to store large files. License GNU GPLv3 Copyright 2012 pluie.org",
|
||||
executables=[exe],
|
||||
include-files=('./launcher.bat','./launcher.bat')
|
||||
options = {"build_exe": build_exe_options},
|
||||
scripts=[
|
||||
'install.py'
|
||||
|
||||
]
|
||||
)
|
||||
else :
|
||||
|
||||
setup( name = "ImpraStorage",
|
||||
version = "0.5",
|
||||
description = "mpraStorage provided a private imap access to store large files",
|
||||
description = "ImpraStorage provided a private imap access to store large files",
|
||||
options = {"build_exe": build_exe_options},
|
||||
executables = [Executable("imprastorage.py", base=base)])
|
||||
|
|
Loading…
Reference in New Issue
Block a user