@ -1,26 +1,56 @@
import os
from engine . ast import Context
if __name__ == ' __main__ ' :
import mimetypes
mimetypes . _winreg = None
from dataclasses import dataclass
import enum
import enum
import re
from tabnanny import check
import time
import time
# import dbconn
# import dbconn
import re
from typing import Callable , List , Optional
from mo_parsing import ParseException
from mo_parsing import ParseException
import aquery_parser as parser
import aquery_parser as parser
import engine
import engine
import engine . projection
import engine . projection
import engine . ddl
import engine . ddl
import reconstruct as xengine
import reconstruct as xengine
import subprocess
import subprocess
import mmap
import mmap
import sys
import sys
import os
from engine . utils import base62uuid
from engine . utils import base62uuid
import atexit
import atexit
import threading
import threading
import ctypes
import ctypes
import aquery_config
import aquery_config
import numpy as np
from engine . utils import ws
from engine . utils import add_dll_dir
## GLOBALS BEGIN
nullstream = open ( os . devnull , ' w ' )
help_message = ''' \
Run prompt . py without supplying with any arguments to run in interactive mode .
- - help , - h
print out this help message
- - version , - v
returns current version of AQuery
- - mode , - m Optional [ threaded | IPC ]
execution engine run mode :
threaded or 1 ( default ) : run the execution engine and compiler / prompt in separate threads
IPC , standalong or 2 : run the execution engine in a new process which uses shared memory to communicate with the compiler process
- - script , - s [ SCRIPT_FILE ]
script mode : run the aquery script file
- - parse - only , - p
parse only : parse the file and print out the AST
'''
## GLOBALS END
## CLASSES BEGIN
class RunType ( enum . Enum ) :
class RunType ( enum . Enum ) :
Threaded = 0
Threaded = 0
IPC = 1
IPC = 1
@ -30,75 +60,19 @@ class Backend_Type(enum.Enum):
BACKEND_MonetDB = 1
BACKEND_MonetDB = 1
BACKEND_MariaDB = 2
BACKEND_MariaDB = 2
server_mode = RunType . Threaded
server_bin = ' server.bin ' if server_mode == RunType . IPC else ' server.so '
nullstream = open ( os . devnull , ' w ' )
if aquery_config . rebuild_backend :
try :
os . remove ( server_bin )
except Exception as e :
print ( type ( e ) , e )
subprocess . call ( [ ' make ' , " info " ] )
subprocess . call ( [ ' make ' , server_bin ] , stdout = nullstream )
cleanup = True
def rm ( ) :
global cleanup
if cleanup :
mm . seek ( 0 , os . SEEK_SET )
mm . write ( b ' \x00 \x00 ' )
mm . flush ( )
try :
time . sleep ( .001 )
server . kill ( )
time . sleep ( .001 )
server . terminate ( )
except OSError :
pass
files = os . listdir ( ' . ' )
for f in files :
if f . endswith ( ' .shm ' ) :
os . remove ( f )
mm . close ( )
cleanup = False
nullstream . close ( )
def init_ipc ( ) :
global shm , server , basecmd , mm
shm = base62uuid ( )
if sys . platform != ' win32 ' :
shm + = ' .shm '
basecmd = [ ' bash ' , ' -c ' , ' rlwrap k ' ]
mm = None
if not os . path . isfile ( shm ) :
# create initial file
with open ( shm , " w+b " ) as handle :
handle . write ( b ' \x01 \x00 ' ) # [running, new job]
handle . flush ( )
mm = mmap . mmap ( handle . fileno ( ) , 2 , access = mmap . ACCESS_WRITE , offset = 0 )
if mm is None :
exit ( 1 )
else :
basecmd = [ ' bash.exe ' , ' -c ' , ' rlwrap ./k ' ]
mm = mmap . mmap ( 0 , 2 , shm )
mm . write ( b ' \x01 \x00 ' )
mm . flush ( )
server = subprocess . Popen ( [ " ./server.bin " , shm ] )
import numpy as np
c = lambda _ba : ctypes . cast ( ( ctypes . c_char * len ( _ba ) ) . from_buffer ( _ba ) , ctypes . c_char_p )
class Config :
class Config :
def __init__ ( self , nq = 0 , mode = server_mode , n_bufs = 0 , bf_szs = [ ] ) - > None :
__all_attrs__ = [ ' running ' , ' new_query ' , ' server_mode ' , ' backend_type ' , ' has_dll ' , ' n_buffers ' ]
__init_attributes__ = False
def __init_self__ ( ) :
if not Config . __init_attributes__ :
from functools import partial
for _i , attr in enumerate ( Config . __all_attrs__ ) :
if not hasattr ( Config , attr ) :
setattr ( Config , attr , property ( partial ( Config . getter , i = _i ) , partial ( Config . setter , i = _i ) ) )
__init_attributes__ = True
def __init__ ( self , mode , nq = 0 , n_bufs = 0 , bf_szs = [ ] ) - > None :
Config . __init_self__ ( )
self . int_size = 4
self . int_size = 4
self . n_attrib = 6
self . n_attrib = 6
self . buf = bytearray ( ( self . n_attrib + n_bufs ) * self . int_size )
self . buf = bytearray ( ( self . n_attrib + n_bufs ) * self . int_size )
@ -121,29 +95,83 @@ class Config:
@property
@property
def c ( self ) :
def c ( self ) :
return c ( self . buf )
return ctypes . cast ( \
( ctypes . c_char * len ( self . buf ) ) . from_buffer ( self . buf ) , ctypes . c_char_p )
def binder ( cls , attr , _i ) :
from functools import partial
setattr ( cls , attr , property ( partial ( cls . getter , i = _i ) , partial ( cls . setter , i = _i ) ) )
binder ( Config , ' running ' , 0 )
@dataclass
binder ( Config , ' new_query ' , 1 )
class PromptState ( ) :
binder ( Config , ' server_mode ' , 2 )
cleanup = True
binder ( Config , ' backend_type ' , 3 )
th = None
binder ( Config , ' has_dll ' , 4 )
send = None
binder ( Config , ' n_buffers ' , 5 )
test_parser = True
server_mode : RunType = RunType . Threaded
server_bin = ' server.bin ' if server_mode == RunType . IPC else ' server.so '
set_ready = lambda : None
get_ready = lambda : None
server_status = lambda : False
cfg : Config = None
shm : str = ' '
server : subprocess . Popen = None
basecmd : List [ str ] = None
mm : mmap = None
th : threading . Thread
send : Callable = lambda * _ : None
init : Callable [ [ ' PromptState ' ] , None ] = lambda _ : None
stmts = [ ' ' ]
payloads = { }
## CLASSES END
cfg = Config ( )
## FUNCTIONS BEGIN
th = None
def rm ( state : PromptState ) :
send = None
if state . cleanup :
state . mm . seek ( 0 , os . SEEK_SET )
state . mm . write ( b ' \x00 \x00 ' )
state . mm . flush ( )
try :
time . sleep ( .001 )
state . server . kill ( )
time . sleep ( .001 )
state . server . terminate ( )
except OSError :
pass
def init_threaded ( ) :
files = os . listdir ( ' . ' )
for f in files :
if f . endswith ( ' .shm ' ) :
os . remove ( f )
state . mm . close ( )
state . cleanup = False
nullstream . close ( )
def init_ipc ( state : PromptState ) :
state . shm = base62uuid ( )
if sys . platform != ' win32 ' :
state . shm + = ' .shm '
state . basecmd = [ ' bash ' , ' -c ' , ' rlwrap k ' ]
state . mm = None
if not os . path . isfile ( shm ) :
# create initial file
with open ( shm , " w+b " ) as handle :
handle . write ( b ' \x01 \x00 ' ) # [running, new job]
handle . flush ( )
state . mm = mmap . mmap ( handle . fileno ( ) , 2 , access = mmap . ACCESS_WRITE , offset = 0 )
if state . mm is None :
exit ( 1 )
else :
state . basecmd = [ ' bash.exe ' , ' -c ' , ' rlwrap ./k ' ]
state . mm = mmap . mmap ( 0 , 2 , state . shm )
state . mm . write ( b ' \x01 \x00 ' )
state . mm . flush ( )
state . server = subprocess . Popen ( [ " ./server.bin " , state . shm ] )
def init_threaded ( state : PromptState ) :
state . cleanup = False
if os . name == ' nt ' and aquery_config . add_path_to_ldpath :
if os . name == ' nt ' and aquery_config . add_path_to_ldpath :
t = os . environ [ ' PATH ' ] . lower ( ) . split ( ' ; ' )
t = os . environ [ ' PATH ' ] . lower ( ) . split ( ' ; ' )
vars = re . compile ( ' %.*% ' )
vars = re . compile ( ' %.*% ' )
os . add_dll_directory ( os . path . abspath ( ' . ' ) )
add_dll_dir( os . path . abspath ( ' . ' ) )
os . add_dll_directory ( os . path . abspath ( ' ./lib ' ) )
add_dll_dir( os . path . abspath ( ' ./lib ' ) )
for e in t :
for e in t :
if ( len ( e ) != 0 ) :
if ( len ( e ) != 0 ) :
if ' % ' in e :
if ' % ' in e :
@ -154,7 +182,7 @@ def init_threaded():
except Exception :
except Exception :
continue
continue
try :
try :
os. add_dll_directory ( e )
add_dll_dir( e )
except Exception :
except Exception :
continue
continue
@ -162,184 +190,258 @@ def init_threaded():
os . environ [ ' PATH ' ] = os . environ [ ' PATH ' ] + os . pathsep + os . path . abspath ( ' . ' )
os . environ [ ' PATH ' ] = os . environ [ ' PATH ' ] + os . pathsep + os . path . abspath ( ' . ' )
os . environ [ ' PATH ' ] = os . environ [ ' PATH ' ] + os . pathsep + os . path . abspath ( ' ./lib ' )
os . environ [ ' PATH ' ] = os . environ [ ' PATH ' ] + os . pathsep + os . path . abspath ( ' ./lib ' )
if aquery_config . run_backend :
if aquery_config . run_backend :
server_so = ctypes . CDLL ( ' ./ ' + server_bin )
server_so = ctypes . CDLL ( ' ./ ' + state . server_bin )
global cfg , th , send
state . send = server_so [ ' receive_args ' ]
send = server_so [ ' receive_args ' ]
aquery_config . have_hge = server_so [ ' have_hge ' ] ( )
aquery_config . have_hge = server_so [ ' have_hge ' ] ( )
if aquery_config . have_hge :
if aquery_config . have_hge :
from engine . types import get_int128_support
from engine . types import get_int128_support
get_int128_support ( )
get_int128_support ( )
th = threading . Thread ( target = server_so [ ' main ' ] , args = ( - 1 , ctypes . POINTER ( ctypes . c_char_p ) ( cfg . c ) ) , daemon = True )
state . th = threading . Thread ( target = server_so [ ' main ' ] , args = ( - 1 , ctypes . POINTER ( ctypes . c_char_p ) ( state . cfg . c ) ) , daemon = True )
th . start ( )
state . th . start ( )
def init_prompt ( ) - > PromptState :
aquery_config . init_config ( )
state = PromptState ( )
if aquery_config . rebuild_backend :
try :
os . remove ( state . server_bin )
except Exception as e :
print ( type ( e ) , e )
subprocess . call ( [ ' make ' , " info " ] )
subprocess . call ( [ ' make ' , state . server_bin ] , stdout = nullstream )
if server_mode == RunType . IPC :
state . cfg = Config ( state . server_mode )
atexit . register ( rm )
init = init_ipc
if state . server_mode == RunType . IPC :
set_ready = lambda : mm . seek ( 0 , os . SEEK_SET ) or mm . write ( b ' \x01 \x01 ' )
atexit . register ( lambda : rm ( state ) )
def __get_ready ( ) :
state . init = init_ipc
mm . seek ( 0 , os . SEEK_SET )
state . set_ready = lambda : state . mm . seek ( 0 , os . SEEK_SET ) or state . mm . write ( b ' \x01 \x01 ' )
return mm . read ( 2 ) [ 1 ]
def __get_ready ( ) :
get_ready = __get_ready
state . mm . seek ( 0 , os . SEEK_SET )
server_status = lambda : server . poll ( ) is not None
return state . mm . read ( 2 ) [ 1 ]
else :
state . get_ready = __get_ready
init = init_threaded
state . server_status = lambda : state . server . poll ( ) is not None
rm = lambda : None
def __set_ready ( ) :
global cfg
cfg . new_query = 1
set_ready = __set_ready
get_ready = lambda : aquery_config . run_backend and cfg . new_query
if aquery_config . run_backend :
server_status = lambda : not th . is_alive ( )
else :
else :
server_status = lambda : True
state . init = init_threaded
init ( )
rm = lambda : None
def __set_ready ( ) :
test_parser = True
state . cfg . new_query = 1
state . set_ready = __set_ready
# code to test parser
state . get_ready = lambda : aquery_config . run_backend and state . cfg . new_query
ws = re . compile ( r ' \ s+ ' )
if aquery_config . run_backend :
state . server_status = lambda : not state . th . is_alive ( )
else :
state . server_status = lambda : True
state . init ( state )
return state
q = ' SELECT p.Name, v.Name FROM Production.Product p JOIN Purchasing.ProductVendor pv ON p.ProductID = pv.ProductID JOIN Purchasing.Vendor v ON pv.BusinessEntityID = v.BusinessEntityID WHERE ProductSubcategoryID = 15 ORDER BY v.Name; '
def save ( q : str , cxt : xengine . Context ) :
savecmd = re . split ( r ' [ \ t] ' , q )
res = parser . parse ( q )
if len ( savecmd ) > 1 :
fname = savecmd [ 1 ]
else :
tm = time . gmtime ( )
fname = f ' { tm . tm_year } { tm . tm_mon } _ { tm . tm_mday } _ { tm . tm_hour } : { tm . tm_min } : { tm . tm_sec } '
if cxt :
from typing import Optional
def savefile ( attr : str , desc : str , ext : Optional [ str ] = None ) :
if hasattr ( cxt , attr ) :
attr : str = getattr ( cxt , attr )
if attr :
ext = ext if ext else ' . ' + desc
name = fname if fname . endswith ( ext ) else fname + ext
with open ( ' saves/ ' + name , ' wb ' ) as cfile :
cfile . write ( attr . encode ( ' utf-8 ' ) )
print ( f ' saved { desc } code as { name } ' )
savefile ( ' ccode ' , ' cpp ' )
savefile ( ' udf ' , ' udf ' , ' .hpp ' )
savefile ( ' sql ' , ' sql ' )
payload = None
def main ( running = lambda : True , next = input , state = None ) :
keep = True
if state is None :
cxt = engine . initialize ( )
state = init_prompt ( )
cxt . Info ( res )
q = ' '
while test_parser :
payload = None
try :
keep = True
if server_status ( ) :
cxt = engine . initialize ( )
init ( )
while running ( ) :
while get_ready ( ) :
try :
time . sleep ( .00001 )
if state . server_status ( ) :
print ( " > " , end = " " )
state . init ( )
q = input ( ) . lower ( )
while state . get_ready ( ) :
if q == ' exec ' : # generate build and run (AQuery Engine)
time . sleep ( .00001 )
cfg . backend_type = Backend_Type . BACKEND_AQuery . value
print ( " > " , end = " " )
cxt = engine . exec ( stmts , cxt , keep )
q = next ( ) . lower ( )
if subprocess . call ( [ ' make ' , ' snippet ' ] , stdout = nullstream ) == 0 :
if q == ' exec ' : # generate build and run (AQuery Engine)
set_ready ( )
state . cfg . backend_type = Backend_Type . BACKEND_AQuery . value
continue
cxt = engine . exec ( state . stmts , cxt , keep )
if subprocess . call ( [ ' make ' , ' snippet ' ] , stdout = nullstream ) == 0 :
elif q == ' xexec ' : # generate build and run (MonetDB Engine)
state . set_ready ( )
cfg . backend_type = Backend_Type . BACKEND_MonetDB . value
continue
cxt = xengine . exec ( stmts , cxt , keep )
if server_mode == RunType . Threaded :
elif q == ' xexec ' : # generate build and run (MonetDB Engine)
# assignment to avoid auto gc
state . cfg . backend_type = Backend_Type . BACKEND_MonetDB . value
# sqls = [s.strip() for s in cxt.sql.split(';')]
cxt = xengine . exec ( state . stmts , cxt , keep )
qs = [ ctypes . c_char_p ( bytes ( q , ' utf-8 ' ) ) for q in cxt . queries if len ( q ) ]
if state . server_mode == RunType . Threaded :
sz = len ( qs )
# assignment to avoid auto gc
payload = ( ctypes . c_char_p * sz ) ( * qs )
# sqls = [s.strip() for s in cxt.sql.split(';')]
qs = [ ctypes . c_char_p ( bytes ( q , ' utf-8 ' ) ) for q in cxt . queries if len ( q ) ]
sz = len ( qs )
payload = ( ctypes . c_char_p * sz ) ( * qs )
state . payload = payload
try :
state . send ( sz , payload )
except TypeError as e :
print ( e )
if cxt . udf is not None :
with open ( ' udf.hpp ' , ' wb ' ) as outfile :
outfile . write ( cxt . udf . encode ( ' utf-8 ' ) )
if cxt . has_dll :
with open ( ' out.cpp ' , ' wb ' ) as outfile :
outfile . write ( ( cxt . finalize ( ) ) . encode ( ' utf-8 ' ) )
subprocess . call ( [ ' make ' , ' snippet ' ] , stdout = nullstream )
state . cfg . has_dll = 1
else :
state . cfg . has_dll = 0
state . set_ready ( )
continue
elif q == ' dbg ' :
import code
from copy import deepcopy
var = { * * globals ( ) , * * locals ( ) }
sh = code . InteractiveConsole ( var )
try :
try :
send ( sz , payload )
sh . interact ( banner = ' debugging session began. ' , exitmsg = ' debugging session ended. ' )
except TypeError as e :
except BaseException as e :
# don't care about anything happened in interactive console
print ( e )
print ( e )
if cxt . udf is not None :
continue
with open ( ' udf.hpp ' , ' wb ' ) as outfile :
elif q . startswith ( ' log ' ) :
outfile . write ( cxt . udf . encode ( ' utf-8 ' ) )
qs = re . split ( r ' [ \ t] ' , q )
if len ( qs ) > 1 :
if cxt . has_dll :
cxt . log_level = qs [ 1 ]
with open ( ' out.cpp ' , ' wb ' ) as outfile :
else :
cxt . print ( cxt . log_level )
continue
elif q == ' k ' :
subprocess . call ( state . basecmd )
continue
elif q == ' print ' :
cxt . print ( state . stmts )
continue
elif q . startswith ( ' save ' ) :
save ( q , cxt )
continue
elif q == ' keep ' :
keep = not keep
continue
elif q == ' format ' or q == ' fmt ' :
subprocess . call ( [ ' clang-format ' , ' out.cpp ' ] )
elif q == ' exit ' :
rm ( state )
exit ( )
elif q == ' r ' : # build and run
if subprocess . call ( [ ' make ' , ' snippet ' ] ) == 0 :
state . set_ready ( )
continue
elif q == ' rr ' : # run
state . set_ready ( )
continue
elif q == ' script ' :
# TODO: script mode
pass
elif q . startswith ( ' save2 ' ) :
filename = re . split ( r ' [ \ t] ' , q )
if ( len ( filename ) > 1 ) :
filename = filename [ 1 ]
else :
filename = f ' out_ { base62uuid ( 4 ) } .cpp '
with open ( filename , ' wb ' ) as outfile :
outfile . write ( ( cxt . finalize ( ) ) . encode ( ' utf-8 ' ) )
outfile . write ( ( cxt . finalize ( ) ) . encode ( ' utf-8 ' ) )
subprocess . call ( [ ' make ' , ' snippet ' ] , stdout = nullstream )
continue
cfg . has_dll = 1
trimed = ws . sub ( ' ' , q . lower ( ) ) . split ( ' ' )
else :
if trimed [ 0 ] . startswith ( ' f ' ) :
cfg . has_dll = 0
fn = ' stock.a ' if len ( trimed ) < = 1 or len ( trimed [ 1 ] ) == 0 \
set_ready ( )
else trimed [ 1 ]
continue
with open ( fn , ' r ' ) as file :
contents = file . read ( ) #.lower()
elif q == ' dbg ' :
state . stmts = parser . parse ( contents )
import code
continue
from copy import deepcopy
state . stmts = parser . parse ( q )
var = { * * globals ( ) , * * locals ( ) }
cxt . Info ( state . stmts )
sh = code . InteractiveConsole ( var )
except ParseException as e :
try :
print ( e )
sh . interact ( banner = ' debugging session began. ' , exitmsg = ' debugging session ended. ' )
except BaseException as e :
# don't care about anything happened in interactive console
print ( e )
continue
elif q . startswith ( ' log ' ) :
qs = re . split ( r ' [ \ t] ' , q )
if len ( qs ) > 1 :
cxt . log_level = qs [ 1 ]
else :
cxt . print ( cxt . log_level )
continue
elif q == ' k ' :
subprocess . call ( basecmd )
continue
elif q == ' print ' :
cxt . print ( stmts )
continue
continue
elif q . startswith ( ' save ' ) :
except ( ValueError , FileNotFoundError ) as e :
savecmd = re . split ( r ' [ \ t] ' , q )
print ( e )
if len ( savecmd ) > 1 :
except ( KeyboardInterrupt ) :
fname = savecmd [ 1 ]
else :
tm = time . gmtime ( )
fname = f ' { tm . tm_year } { tm . tm_mon } _ { tm . tm_mday } _ { tm . tm_hour } : { tm . tm_min } : { tm . tm_sec } '
if cxt :
from typing import Optional
def savefile ( attr : str , desc : str , ext : Optional [ str ] = None ) :
if hasattr ( cxt , attr ) :
attr : str = getattr ( cxt , attr )
if attr :
ext = ext if ext else ' . ' + desc
name = fname if fname . endswith ( ext ) else fname + ext
with open ( ' saves/ ' + name , ' wb ' ) as cfile :
cfile . write ( attr . encode ( ' utf-8 ' ) )
print ( f ' saved { desc } code as { name } ' )
savefile ( ' ccode ' , ' cpp ' )
savefile ( ' udf ' , ' udf ' , ' .hpp ' )
savefile ( ' sql ' , ' sql ' )
continue
elif q == ' keep ' :
keep = not keep
continue
elif q == ' format ' or q == ' fmt ' :
subprocess . call ( [ ' clang-format ' , ' out.cpp ' ] )
elif q == ' exit ' :
break
break
elif q == ' r ' : # build and run
except :
if subprocess . call ( [ ' make ' , ' snippet ' ] ) == 0 :
import code , traceback
set_ready ( )
sh = code . InteractiveConsole ( { * * globals ( ) , * * locals ( ) } )
continue
sh . interact ( banner = traceback . format_exc ( ) , exitmsg = ' debugging session ended. ' )
elif q == ' rr ' : # run
save ( ' ' , cxt )
set_ready ( )
rm ( state )
continue
raise
elif q . startswith ( ' save2 ' ) :
rm ( state )
filename = re . split ( r ' [ \ t] ' , q )
## FUNCTIONS END
if ( len ( filename ) > 1 ) :
filename = filename [ 1 ]
## MAIN
else :
if __name__ == ' __main__ ' :
filename = f ' out_ { base62uuid ( 4 ) } .cpp '
state = None
with open ( filename , ' wb ' ) as outfile :
nextcmd = ' '
outfile . write ( ( cxt . finalize ( ) ) . encode ( ' utf-8 ' ) )
def check_param ( param : List [ str ] , args = False ) - > bool :
continue
global nextcmd
trimed = ws . sub ( ' ' , q . lower ( ) ) . split ( ' ' )
for p in param :
if trimed [ 0 ] . startswith ( ' f ' ) :
if p in sys . argv :
fn = ' stock.a ' if len ( trimed ) < = 1 or len ( trimed [ 1 ] ) == 0 \
if args :
else trimed [ 1 ]
return True
pos = sys . argv . index ( p )
with open ( fn , ' r ' ) as file :
if len ( sys . argv ) > pos + 1 :
contents = file . read ( ) #.lower()
nextcmd = sys . argv [ pos + 1 ]
stmts = parser . parse ( contents )
return True
continue
return False
stmts = parser . parse ( q )
if check_param ( [ ' -h ' , ' --help ' ] , True ) :
cxt . Info ( stmts )
print ( help_message )
except ParseException as e :
exit ( )
print ( e )
continue
if len ( sys . argv ) == 2 :
except ( ValueError , FileNotFoundError ) as e :
nextcmd = sys . argv [ 1 ]
print ( e )
if nextcmd . startswith ( ' - ' ) :
except ( KeyboardInterrupt ) :
nextcmd = ' '
break
except :
nextcmd = ' test.aquery '
rm ( )
if nextcmd or check_param ( [ ' -s ' , ' --script ' ] ) :
raise
with open ( nextcmd ) as file :
rm ( )
nextcmd = file . readline ( )
from engine . utils import _Counter
if file . name . endswith ( ' aquery ' ) or nextcmd . strip ( ) == ' #!aquery ' :
state = init_prompt ( )
while ( nextcmd ) :
while ( not ws . sub ( ' ' , nextcmd ) or nextcmd . strip ( ) . startswith ( ' # ' ) ) :
nextcmd = file . readline ( )
cnt = _Counter ( 1 )
main ( lambda : cnt . inc ( - 1 ) > 0 , lambda : nextcmd . strip ( ) , state )
nextcmd = file . readline ( )
if check_param ( [ ' -p ' , ' --parse ' ] ) :
with open ( nextcmd , ' r ' ) as file :
contents = file . read ( )
print ( parser . parse ( contents ) )
if check_param ( [ ' -m ' , ' --mode ' , ' --run-type ' ] ) :
nextcmd = nextcmd . lower ( )
ipc_string = [ ' ipc ' , ' proc ' , ' 2 ' , ' standalong ' ]
thread_string = [ ' thread ' , ' 1 ' ]
if any ( [ s in nextcmd for s in ipc_string ] ) :
server_mode = RunType . IPC
elif any ( [ s in nextcmd for s in thread_string ] ) :
server_mode = RunType . Threaded
main ( state = state )