Skip to content
Snippets Groups Projects
Commit a178f406 authored by Ramin Yaghoubzadeh Torky's avatar Ramin Yaghoubzadeh Torky
Browse files

Using ipaaca.exit() in scripts as well

parent fad0742b
No related branches found
No related tags found
No related merge requests found
......@@ -36,30 +36,37 @@ from __future__ import division, print_function
import sys
import ipaaca
import traceback
if __name__=='__main__':
iap = ipaaca.IpaacaArgumentParser(
'ipaaca-logcat')
iap.add_argument(
'-s', '--strip-fields',
dest='strip', action='store_true',
default=False,
help='strip leading/trailing whitespace from all fields')
iap.add_argument(
'-d', '--delimiter',
dest='delimiter', nargs=1,
default=['\t'],
help='field delimiter, interpreted as python unicode string (default \'\\t\')')
iap.add_argument(
'-f', '--fields',
dest='fields', default=['time', 'text'], nargs='+',
help='fields to print (defaults: \'time\' \'text\')')
arguments = iap.parse_args()
delimiter = eval("u'"+arguments.delimiter[0]+"'", {"__builtins__":None}, {} )
#print(arguments); sys.exit(1)
modify = (lambda s: s.strip()) if arguments.strip else (lambda s: s)
#modify = lambda s: type(s).__name__
for line in sys.stdin:
record = eval(line.strip(), {"__builtins__":None}, {} )
print(delimiter.join([modify(unicode(record[f])) for f in arguments.fields]))
try:
iap = ipaaca.IpaacaArgumentParser('ipaaca-logcat')
iap.add_argument(
'-s', '--strip-fields',
dest='strip', action='store_true',
default=False,
help='strip leading/trailing whitespace from all fields')
iap.add_argument(
'-d', '--delimiter',
dest='delimiter', nargs=1,
default=['\t'],
help='field delimiter, interpreted as python unicode string (default \'\\t\')')
iap.add_argument(
'-f', '--fields',
dest='fields', default=['time', 'text'], nargs='+',
help='fields to print (defaults: \'time\' \'text\')')
arguments = iap.parse_args()
delimiter = eval("u'"+arguments.delimiter[0]+"'", {"__builtins__":None}, {} )
#print(arguments); sys.exit(1)
modify = (lambda s: s.strip()) if arguments.strip else (lambda s: s)
#modify = lambda s: type(s).__name__
for line in sys.stdin:
record = eval(line.strip(), {"__builtins__":None}, {} )
print(delimiter.join([modify(unicode(record[f])) for f in arguments.fields]))
except (KeyboardInterrupt, SystemExit):
pass # ret below
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
......@@ -112,8 +112,7 @@ if __name__ == '__main__':
time.sleep(0.1)
except KeyboardInterrupt:
pass
if platform.system() == 'Windows':
os._exit(0)
else:
sys.exit(0)
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
......@@ -97,10 +97,11 @@ def iu_event_handler(iu, event_type, local):
print(pretty_printed_iu_event(iu, event_type, local), end='\n\n')
def exit(code):
if platform.system() == 'Windows':
os._exit(code)
else:
sys.exit(code)
ipaaca.exit(code)
#if platform.system() == 'Windows':
# os._exit(code)
#else:
# sys.exit(code)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca IU Sniffer -- Selectively listen to IPAACA traffic')
parser.add_argument(
......@@ -186,4 +187,7 @@ if __name__ == '__main__':
time.sleep(1)
except KeyboardInterrupt:
pass
exit(code=0)
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
......@@ -49,21 +49,28 @@ def main(log_mode, filename=None):
except KeyboardInterrupt:
il.close_logfile()
print('Logging-Component closed by keyboard interrupt.')
sys.exit(0)
if __name__ == '__main__':
iap = ipaaca.IpaacaArgumentParser(
'ipaaca-logger')
iap.add_argument(
'-m', '--log-mode', dest='log_mode',
choices=ipaacalog.LOG_MODES,
default='append',
help="set what to do when logfile exists "
"(default: 'append'; 'timestamp' adds timestamp in any case)")
iap.add_argument(
'filename', nargs='?',
metavar='FILE',
help='set name of logfile')
arguments = iap.parse_args()
main(arguments.log_mode, arguments.filename)
try:
iap = ipaaca.IpaacaArgumentParser(
'ipaaca-logger')
iap.add_argument(
'-m', '--log-mode', dest='log_mode',
choices=ipaacalog.LOG_MODES,
default='append',
help="set what to do when logfile exists "
"(default: 'append'; 'timestamp' adds timestamp in any case)")
iap.add_argument(
'filename', nargs='?',
metavar='FILE',
help='set name of logfile')
arguments = iap.parse_args()
main(arguments.log_mode, arguments.filename)
except KeyboardInterrupt:
pass
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
......@@ -38,14 +38,17 @@ import platform
import sys
import time
import traceback
import ipaaca
def exit(code):
if platform.system() == 'Windows':
os._exit(code)
else:
sys.exit(code)
ipaaca.exit(code)
#if platform.system() == 'Windows':
# os._exit(code)
#else:
# sys.exit(code)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca Maintainor')
......@@ -59,11 +62,11 @@ if __name__ == '__main__':
if (ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT is not None and
ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT != 'socket'):
print("ERROR: Works only with RSB transport type 'socket'.")
exit(1)
ipaaca.exit(1)
if (ipaaca.defaults.IPAACA_DEFAULT_RSB_SOCKET_SERVER is not None and
ipaaca.defaults.IPAACA_DEFAULT_RSB_SOCKET_SERVER != '1'):
print("ERROR: Works only in socket server mode '0'.")
exit(1)
ipaaca.exit(1)
# Configure rsb socket transport
ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT = 'socket'
......@@ -78,4 +81,7 @@ if __name__ == '__main__':
decision = raw_input('Shutdown the IPAACA socket transport hub (y/[n])?')
if decision in 'yY':
break
exit(code=0)
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment