~ Fixes #49 (JSON status printed twice with Python package/docker) : explicit sys.exit(0) is now made

~ default verbosity set to WARNING as it's the convention
This commit is contained in:
nicobo 2021-01-25 23:25:07 +01:00
parent bd389242fd
commit 7f715be7bf
No known key found for this signature in database
GPG key ID: 2581E71C5FA5285F
3 changed files with 18 additions and 16 deletions

View file

@ -42,7 +42,7 @@ class Config:
'patterns': [],
'stealth': False,
'timeout': None,
'verbosity': "INFO",
'verbosity': "WARNING",
})
@ -84,7 +84,7 @@ class AskBot(Bot):
self.status['events'].append(status_message)
self.responses_count = self.responses_count + 1
logging.debug("<<< %s", message)
logging.info("<<< %s", message)
# If we reached the last message or if we exceeded it (possible if we received several answers in a batch)
if self.max_count>0 and self.responses_count >= self.max_count:
@ -137,8 +137,6 @@ def run( args=sys.argv[1:] ):
"""
A convenient CLI to play with this bot.
TODO Put generic arguments in bot.py and inherit from it (should probably provide a parent ArgumentParser)
"""
# config will be the final, merged configuration
@ -188,13 +186,15 @@ def run( args=sys.argv[1:] ):
status_args[k] = '(obfuscated)'
status_result = bot.run()
status = { 'args':vars(config), 'result':status_result }
# NOTE ensure_ascii=False + encode('utf-8').decode() is not mandatory but allows printing plain UTF-8 strings rather than \u... or \x...
# NOTE default=repr is mandatory because some objects in the args are not serializable
print( json.dumps(status,skipkeys=True,ensure_ascii=False,default=repr).encode('utf-8').decode(), file=sys.stdout, flush=True )
# Still returns the full status for simpler handling in Python
# Returns the full status to this module can be called CLI-style
return status
# Like run(), but also prints the final status to stdout
if __name__ == '__main__':
run()
status = run(sys.argv[1:])
# NOTE ensure_ascii=False + encode('utf-8').decode() is not mandatory but allows printing plain UTF-8 strings rather than \u... or \x...
# NOTE default=repr is mandatory because some objects in the args are not serializable
print( json.dumps(status,skipkeys=True,ensure_ascii=False,default=repr).encode('utf-8').decode(), file=sys.stdout, flush=True )
sys.exit(0)

View file

@ -77,7 +77,7 @@ class ArgsHelper:
'config_dir': os.getcwd(),
'input_file': sys.stdin,
'stealth': False,
'verbosity': "INFO",
'verbosity': "WARNING",
})

View file

@ -74,7 +74,7 @@ class Config:
'signal_stealth': False,
'stealth': False,
'username': None,
'verbosity': "INFO"
'verbosity': "WARNING"
})
@ -691,13 +691,15 @@ def run( args=sys.argv[1:] ):
status_args[k] = '(obfuscated)'
status_result = bot.run()
status = { 'args':vars(config), 'result':status_result }
# NOTE ensure_ascii=False + encode('utf-8').decode() is not mandatory but allows printing plain UTF-8 strings rather than \u... or \x...
# NOTE default=repr is mandatory because some objects in the args are not serializable
print( json.dumps(status,skipkeys=True,ensure_ascii=False,default=repr).encode('utf-8').decode(), file=sys.stdout, flush=True )
# Still returns the full status for simpler handling in Python
# Returns the full status to this module can be called CLI-style
return status
# Like run(), but also prints the final status to stdout
if __name__ == '__main__':
run()
status = run(sys.argv[1:])
# NOTE ensure_ascii=False + encode('utf-8').decode() is not mandatory but allows printing plain UTF-8 strings rather than \u... or \x...
# NOTE default=repr is mandatory because some objects in the args are not serializable
print( json.dumps(status,skipkeys=True,ensure_ascii=False,default=repr).encode('utf-8').decode(), file=sys.stdout, flush=True )
sys.exit(0)