本文整理汇总了Python中configuration.Configuration.get_dct_cmd_on_start方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_dct_cmd_on_start方法的具体用法?Python Configuration.get_dct_cmd_on_start怎么用?Python Configuration.get_dct_cmd_on_start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.get_dct_cmd_on_start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_dct_cmd_on_start [as 别名]
class Manager:
def __init__(self):
"""
Structure of dct_execution
{"execution_name" : {KEY_FILTERCHAIN : ref, KEY_MEDIA : ref}}
"""
self.dct_exec = {}
self.config = Configuration()
self.resource = Resource()
# tcp server for output observer
self.nb_observer_client = 0
self.server_observer = Server()
self.server_observer.start("", 5030)
self.notify_event_client = {}
self.id_client_notify = 0
# launch command on start
thread.start_new_thread(self.config.get_dct_cmd_on_start(), (self, ))
def close(self):
logger.info("Close manager and close server.")
for execution in self.dct_exec.values():
execution[KEY_MEDIA].close()
self.server_observer.stop()
##########################################################################
################################ CLIENT ##################################
##########################################################################
def is_connected(self):
return True
##########################################################################
############################# SERVER STATE ###############################
##########################################################################
def add_notify_server(self):
self.id_client_notify += 1
self.notify_event_client[self.id_client_notify] = False
return self.id_client_notify
def need_notify(self, i_id):
notify = self.notify_event_client.get(i_id, None)
if notify is None:
# logger.warning("The client id %s is not in the notify list.")
return False
if not notify:
return False
self.notify_event_client[i_id] = False
return True
def _active_notify(self):
for notify in self.notify_event_client.keys():
self.notify_event_client[notify] = True
##########################################################################
######################## EXECUTION FILTER ################################
##########################################################################
def start_filterchain_execution(self, execution_name, media_name, filterchain_name, file_name=None, is_client_manager=False):
execution = self.dct_exec.get(execution_name, None)
if execution:
log.print_function(logger.error, "The execution %s is already created." % (execution_name))
return False
filterchain = self.resource.get_filterchain(filterchain_name, force_new_filterchain=True)
if not filterchain:
log.print_function(logger.error, "Filterchain %s not exist or contain error." % (filterchain_name))
return False
# Exception, if not media_name, we take the default media_name from the filterchain
if not media_name:
media_name = filterchain.get_default_media_name()
media = self.resource.get_media(media_name)
if not media:
log.print_function(logger.error, "Media %s not exist or you didn't set the default media on filterchain." % (media_name))
return False
if media.is_media_video() and file_name:
media.set_file(file_name)
media.set_is_client_manager(is_client_manager)
filterchain.set_media_param(media.get_dct_media_param())
media.add_observer(filterchain.execute)
self.dct_exec[execution_name] = {KEY_FILTERCHAIN: filterchain, KEY_MEDIA : media}
self._active_notify()
return True
def stop_filterchain_execution(self, execution_name):
execution = self.dct_exec.get(execution_name, None)
if not execution:
log.print_function(logger.warning, "The execution %s is already stopped." % execution_name)
return False
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_dct_cmd_on_start [as 别名]
class CmdHandler:
def __init__(self):
"""
Structure of dct_execution
{"execution_name" : {KEY_FILTERCHAIN : ref, KEY_MEDIA : ref}}
"""
self.dct_exec = {}
self.config = Configuration()
self.resource = Resource()
# all record history, contains:
# {"time": ..., "media_name": ..., "path": ...}
self.lst_record_historic = []
self.count_keys = defaultdict(int)
self._is_keep_alive_media = self.config.get_is_keep_alive_media()
self.old_rec_dir_path = self.config.get_path_save_record()
# tcp server for output observer
self.nb_observer_client = 0
self.server_observer = Server()
self.server_observer.start("", 5030)
self.notify_event_client = {}
self.id_client_notify = 0
self.publisher = self.resource.get_publisher()
# launch command on start
thread.start_new_thread(self.config.get_dct_cmd_on_start(), (self,))
def get_publisher(self):
return self.publisher
def close(self):
logger.info("Close cmdHandler and close server.")
for media_name in self.resource.get_media_name_list():
media = self.resource.get_media(media_name)
media.close()
media.destroy()
self.server_observer.stop()
self.publisher.stop()
self.publisher.deregister(keys.get_key_execution_list())
self.publisher.deregister(keys.get_key_filter_param())
self.publisher.deregister(keys.get_key_media_param())
self.publisher.deregister(keys.get_key_lst_rec_historic())
self.publisher.deregister(keys.get_key_count())
@staticmethod
def _post_command_(arg):
funct_name = inspect.currentframe().f_back.f_code.co_name
del arg["self"]
# special case, observer is reference
if "observer" in arg:
arg["observer"] = "REF"
if arg:
logger.info("Request : %s - %s" % (funct_name, arg))
else:
logger.info("Request : %s" % funct_name)
#
# CLIENT ##################################
#
def is_connected(self):
self._post_command_(locals())
return True
#
# EXECUTION FILTER ################################
#
def start_filterchain_execution(
self, execution_name, media_name, filterchain_name, file_name,
is_client_manager):
self._post_command_(locals())
execution = self.dct_exec.get(execution_name, None)
if execution:
log.print_function(
logger.error, "The execution %s is already created." %
execution_name)
return False
filterchain = self.resource.get_filterchain(
filterchain_name,
force_new_filterchain=True)
if not filterchain:
log.print_function(
logger.error, "Filterchain %s not exist or contain error." %
filterchain_name)
return False
# Exception, if not media_name, we take the default media_name from the
# filterchain
if not media_name:
media_name = filterchain.get_default_media_name()
if not media_name:
media_name = self.config.get_default_media_name()
media = self.resource.get_media(media_name)
if not media:
log.print_function(
#.........这里部分代码省略.........