예제 #1
0
 def on_start(self):
     init_logger(__name__, get_verbosity(self.config))
     _LOGGER.debug("On Start")
     if self.check_host_port_config('frontend') and self.check_host_port_config('backend') and\
        self.check_other_config():
         _LOGGER.debug("On Start conf OK")
         self.do_pre()
예제 #2
0
def main():
    p4a = os.environ.get('PYTHON_SERVICE_ARGUMENT', '')
    args = json.loads(p4a)
    global _LOGGER
    _LOGGER = init_logger(__name__, level=get_verbosity(args['verbose']))
    _LOGGER.info(f"Server: p4a = {p4a}")
    _LOGGER.debug(f"Server: test debug")
    loop = asyncio.get_event_loop()
    loop.set_exception_handler(exception_handle)
    dms = BluetoothService(loop=loop, **args)
    try:
        loop.run_until_complete(dms.start())
        loop.run_forever()
    except Exception:
        _LOGGER.error("Server: E0 " + traceback.format_exc())
    finally:
        try:
            loop.run_until_complete(dms.stop())
            _LOGGER.debug("Server: Closing loop")
            loop.close()
        except Exception:
            _LOGGER.error("Server: " + traceback.format_exc())
예제 #3
0
    def start_server(self):
        if platform == 'android':
            try:
                from jnius import autoclass
                package_name = 'org.kivymfz.pymoviz.test'
                service_name = 'BluetoothService'
                service_class = '{}.Service{}'.format(package_name,
                                                      service_name.title())
                service = autoclass(service_class)
                mActivity = autoclass(
                    'org.kivy.android.PythonActivity').mActivity

                arg = dict(hostlisten=self.config.get('backend', 'host'),
                           portlisten=self.config.getint('backend', 'port'),
                           portlistenlocal=int(
                               self.config.getint('local', 'backendport')),
                           verbose=get_verbosity(self.config))
                argument = json.dumps(arg)
                _LOGGER.info("Starting %s [%s]" % (service_class, argument))
                service.start(mActivity, argument)
            except Exception:
                _LOGGER.error(traceback.format_exc())
예제 #4
0
def main():
    p4a = os.environ.get('PYTHON_SERVICE_ARGUMENT', '')
    global _LOGGER

    if len(p4a):
        args = json.loads(p4a)
        # hostlisten
        # portlisten
        # hostconnect
        # portconnect
        # connect_retry
        # connect_secs
        # db_fname
    else:
        parser = argparse.ArgumentParser(prog=__prog__)
        parser.add_argument('--portlisten',
                            type=int,
                            help='port number',
                            required=False,
                            default=11001)
        parser.add_argument('--hostlisten', required=False, default="0.0.0.0")
        parser.add_argument('--ab_portconnect',
                            type=int,
                            help='port number',
                            required=False,
                            default=9004)
        parser.add_argument('--ab_hostconnect',
                            required=False,
                            default="127.0.0.1")
        parser.add_argument('--ab_portlisten',
                            type=int,
                            help='port number',
                            required=False,
                            default=9003)
        parser.add_argument('--ab_hostlisten',
                            required=False,
                            default="0.0.0.0")
        parser.add_argument('--connect_retry',
                            type=int,
                            help='connect retry',
                            required=False,
                            default=10)
        parser.add_argument('--connect_secs',
                            type=int,
                            help='connect secs',
                            required=False,
                            default=5)
        parser.add_argument('--db_fname',
                            required=False,
                            help='DB file path',
                            default=join(dirname(__file__), '..', 'maindb.db'))
        parser.add_argument('--verbose', required=False, default="INFO")
        argall = parser.parse_known_args()
        args = dict(vars(argall[0]))
        args['undo_info'] = dict()
        args['notify_screen_on'] = -1
        args['notify_every_ms'] = -1
        import sys
        sys.argv[1:] = argall[1]
    args['android'] = len(p4a)
    _LOGGER = init_logger(__name__, get_verbosity(args['verbose']))
    _LOGGER.info(f"Server: p4a = {p4a}")
    _LOGGER.debug(f"Server: test debug {args}")
    loop = asyncio.get_event_loop()
    dms = DeviceManagerService(loop=loop, **args)
    try:
        loop.run_until_complete(dms.start())
        loop.run_forever()
    except Exception:
        _LOGGER.error(f'DMS error {traceback.format_exc()}')
    finally:
        try:
            loop.run_until_complete(dms.stop())
            _LOGGER.info("Server: Closing loop")
            loop.close()
        except Exception:
            _LOGGER.error("Server: " + traceback.format_exc())
예제 #5
0
def print_debug_message(**kwargs):
    """ Receiver to print a debug message in blue, if verbose and DEBUG are set
    """
    text = kwargs.get('text')
    if get_verbosity() and settings.DEBUG and text:
        print(Style.BRIGHT + Fore.BLUE + text)
예제 #6
0
def print_warning_message(**kwargs):
    """ Receiver to print a warning message in yellow text
    """
    text = kwargs.get('text')
    if get_verbosity():
        print(Style.BRIGHT + Fore.YELLOW + text)
예제 #7
0
def print_info_message(sender=None, **kwargs):
    """ Receiver to print an info message, no color
    """
    text = kwargs.get('text')
    if get_verbosity():
        print(Style.RESET_ALL + Fore.RESET + text)