Freebox thin client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.9KB

  1. """
  2. Console script
  3. """
  4. import os
  5. import logging
  6. import argparse
  7. import pprint
  8. from pyfbx import Fbx
  9. log_level = (logging.WARNING, logging.INFO, logging.DEBUG)
  10. def console(log, level):
  11. log.setLevel(level)
  12. formatter = logging.Formatter('%(asctime)s - %(name)14s - %(levelname)s - %(message)s')
  13. stream_handler = logging.StreamHandler()
  14. stream_handler.setFormatter(formatter)
  15. log.addHandler(stream_handler)
  16. def main():
  17. log = logging.getLogger("pyfbx")
  18. parser = argparse.ArgumentParser()
  19. parser.add_argument("app_id", type=str, help="application identifier")
  20. parser.add_argument("-c", "--command", type=str,
  21. help="command, defaults to System.Get_the_current_system_info()",
  22. default="System.Get_the_current_system_info()")
  23. parser.add_argument("-t", "--token", type=str, help="token (or f:<filename>)")
  24. parser.add_argument("-v", "--verbose", action="count", default=0,
  25. help="increase verbosity to INFO, use twice for DEBUG")
  26. parser.add_argument("-n", "--http", action="store_true",
  27. help="Disable MDNS and use http known address")
  28. args = parser.parse_args()
  29. console(log, log_level[min(2, args.verbose)])
  30. try:
  31. myfb = Fbx(nomdns=args.http)
  32. token = args.token
  33. if token:
  34. if token.startswith('f:'):
  35. with open(args.token[2:]) as tok_file:
  36. token = tok_file.read().strip()
  37. else:
  38. log.warning(f"Registering app {__name__}, id {args.app_id}, Press button")
  39. token = myfb.register(app_id=args.app_id, app_name=__name__,
  40. device=os.uname().nodename)
  41. log.warning(f"Save your application token: {token}")
  42. myfb.mksession(app_id=args.app_id, token=token)
  43. pp = pprint.PrettyPrinter(indent=4)
  44. pp.pprint(eval(f"myfb.{args.command}"))
  45. except BaseException as err:
  46. print(err)