Initialized logging

This commit is contained in:
2019-11-05 19:56:00 +01:00
parent b12204360e
commit 0d2adf1b6c
10 changed files with 448 additions and 249 deletions
+61 -11
View File
@@ -1,22 +1,72 @@
import getopt
import sys
from core.utils import sysarg_to_string
from core.sheerka import Sheerka
import logging
def usage():
print("Sheerka v0.1\n")
print("usage:")
print(sys.argv[0] + "[-hd] command ")
def main():
sheerka = Sheerka()
sheerka.initialize()
# first, record the event
event_as_string = sysarg_to_string(sys.argv[1:])
result = sheerka.eval(event_as_string)
def sysarg_to_string(argv):
"""
Transform a list of strings into a single string
Add quotes if needed
:return:
"""
if argv is None or not argv:
return ""
# execute the concepts
print(result)
return True
result = ""
first = True
for s in argv:
if not first:
result += " "
result += '"' + s + '"' if " " in s else s
first = False
return result
def init_logging(debug):
if debug:
log_format = "%(asctime)s %(name)s [%(levelname)s] %(message)s"
log_level = logging.DEBUG
else:
log_format = "%(message)s"
log_level = logging.INFO
logging.basicConfig(format=log_format, level=log_level)
def main(argv):
try:
opts, args = getopt.getopt(argv, "hd", ["help", "debug"])
debug = False
for o, a in opts:
if o in ('-h', "--help"):
usage()
return True
if o in ('-d', "--debug"):
debug = True
init_logging(debug)
sheerka = Sheerka()
sheerka.initialize()
_in = sysarg_to_string(args)
result = sheerka.eval(_in)
logging.info(result)
return result[-1].status
except getopt.GetoptError:
usage()
sys.exit(2)
if __name__ == '__main__':
res = main()
res = main(sys.argv[1:])
exit(0 if res else 1)