text
stringlengths 1
93.6k
|
|---|
except Exception as e:
|
print(e)
|
exit()
|
def main(argv):
|
if (len(argv) < 1):
|
print_banner()
|
print_syntax()
|
return
|
if (argv[0] != 'newconfig'):
|
print_banner()
|
modules = load_modules()
|
if (argv[0] == 'list'):
|
list_mods(modules)
|
return
|
if (argv[0] == 'info'):
|
print_mod_info(modules, argv[1])
|
return
|
if (argv[0] == 'help'):
|
if (len(argv) < 2):
|
print_syntax()
|
return
|
print_mod_help(modules, argv[1])
|
return
|
if (argv[0] == 'syntax'):
|
print_mod_syntax(modules, argv[1])
|
return
|
mod = get_mod(modules, argv[0])
|
if (mod != None):
|
exec_mod(mod, argv[1:])
|
return
|
print_syntax()
|
return
|
def print_syntax():
|
print('Usage:\n'
|
' natlas-cli.py list - Display available modules\n'
|
' natlat-cli.py info <module> - Display information about the module\n'
|
' natlat-cli.py help <module> - Display help for module\n'
|
' natlat-cli.py syntax <module> - Display syntax for module\n')
|
def print_banner():
|
print('natlas v%s' % natlas.__version__)
|
print('Michael Laforest <mjlaforest@gmail.com>')
|
print('Python %s\n' % sys.version.split(' ')[0])
|
def load_modules():
|
sys.path.insert(0, './modules')
|
ret = []
|
for f in os.listdir('./modules'):
|
if (f[-3:] == '.py'):
|
mod = None
|
try:
|
mod = __import__(f[:-3], ['mod_load', 'mod_entry'])
|
except Exception as e:
|
print(e)
|
continue
|
if (hasattr(mod, 'mod_load') == 0):
|
print('[ERROR] No mod_load() for %s' % f)
|
continue
|
m = natlas_mod()
|
if (mod.mod_load(m) == 0):
|
print('[ERROR] mod_load() returned an error for %s' % f)
|
continue
|
m.filename = f
|
m.entryfunc = mod.mod_entry
|
ret.append(m)
|
return ret
|
def exec_mod(module, argv):
|
if (does_mod_accept_api(module) == 0):
|
print('Module is disabled.')
|
return 0
|
start = timer()
|
try:
|
natlas_obj = natlas.natlas()
|
except Exception as e:
|
print('[ERROR] %s' % e)
|
return 0
|
if (module.preload_conf == 1):
|
try:
|
argv, opt_conf = argv_get_conf(argv)
|
except Exception as e:
|
print('[ERROR] %s' % e)
|
return 0
|
try:
|
natlas_obj.config_load(opt_conf)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.