本文整理汇总了Python中flexget.ipc.IPCClient类的典型用法代码示例。如果您正苦于以下问题:Python IPCClient类的具体用法?Python IPCClient怎么用?Python IPCClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPCClient类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
def start(self):
"""
Starting point when executing from commandline, dispatch execution to correct destination.
If there is a FlexGet process with an ipc server already running, the command will be sent there for execution
and results will be streamed back.
If not, this will attempt to obtain a lock, initialize the manager, and run the command here.
"""
# If another process is started, send the execution to the running process
ipc_info = self.check_ipc_info()
if ipc_info:
try:
log.info('There is a FlexGet process already running for this config, sending execution there.')
client = IPCClient(ipc_info['port'], ipc_info['password'])
except ValueError as e:
log.error(e)
else:
try:
client.handle_cli(self.args)
except KeyboardInterrupt:
log.error('Disconnecting from daemon due to ctrl-c. Executions will still continue in the '
'background.')
except EOFError:
log.error('Connection from daemon was severed.')
return
# No running process, we start our own to handle command
with self.acquire_lock():
self.initialize()
self.handle_cli()
self._shutdown()
示例2: execute_command
def execute_command(self, options):
"""
Send execute command to daemon through IPC or perform execution
on current process.
Fires events:
* manager.execute.completed
:param options: argparse options
"""
# If a daemon is started, send the execution to the daemon
ipc_info = self.check_ipc_info()
if ipc_info:
client = IPCClient(ipc_info['port'], ipc_info['password'])
client.execute(dict(options))
self.shutdown()
return
# Otherwise we run the execution ourselves
with self.acquire_lock():
fire_event('manager.execute.started', self)
self.scheduler.start(run_schedules=False)
self.scheduler.execute(options)
self.scheduler.shutdown(finish_queue=True)
try:
self.scheduler.wait()
except KeyboardInterrupt:
log.error('Got ctrl-c exiting after this task completes. Press ctrl-c again to abort this task.')
else:
fire_event('manager.execute.completed', self)
self.shutdown(finish_queue=False)
示例3: execute_command
def execute_command(self, options):
"""
Send execute command to daemon through IPC or perform execution
on current process.
Fires events:
* manager.execute.completed
:param options: argparse options
"""
# If a daemon is started, send the execution to the daemon
ipc_info = self.check_ipc_info()
if ipc_info:
try:
log.info('There is a daemon running for this config. Sending execution to running daemon.')
client = IPCClient(ipc_info['port'], ipc_info['password'])
except ValueError as e:
log.error(e)
else:
client.execute(dict(options, loglevel=self.options.loglevel))
self.shutdown()
return
# Otherwise we run the execution ourselves
with self.acquire_lock():
fire_event('manager.execute.started', self)
self.task_queue.start()
self.execute(options)
self.shutdown(finish_queue=True)
self.task_queue.wait()
fire_event('manager.execute.completed', self)
示例4: start
def start(self):
"""
Starting point when executing from commandline, dispatch execution to correct destination.
If there is a FlexGet process with an ipc server already running, the command will be sent there for execution
and results will be streamed back.
If not, this will attempt to obtain a lock, initialize the manager, and run the command here.
"""
if sys.version_info <= (2, 7):
console('-' * 79)
console('Python 2.7 will not be maintained past 2020 !')
console('Consider upgrading to 3.6 or newer at your earliest convenience.')
console('-' * 79)
# When we are in test mode, we use a different lock file and db
if self.options.test:
self.lockfile = os.path.join(self.config_base, '.test-%s-lock' % self.config_name)
# If another process is started, send the execution to the running process
ipc_info = self.check_ipc_info()
if ipc_info:
console(
'There is a FlexGet process already running for this config, sending execution there.'
)
log.debug('Sending command to running FlexGet process: %s' % self.args)
try:
client = IPCClient(ipc_info['port'], ipc_info['password'])
except ValueError as e:
log.error(e)
else:
try:
client.handle_cli(self.args)
except KeyboardInterrupt:
log.error(
'Disconnecting from daemon due to ctrl-c. Executions will still continue in the '
'background.'
)
except EOFError:
log.error('Connection from daemon was severed.')
return
if self.options.test:
log.info('Test mode, creating a copy from database ...')
db_test_filename = os.path.join(self.config_base, 'test-%s.sqlite' % self.config_name)
if os.path.exists(self.db_filename):
shutil.copy(self.db_filename, db_test_filename)
log.info('Test database created')
self.db_filename = db_test_filename
# No running process, we start our own to handle command
with self.acquire_lock():
self.initialize()
self.handle_cli()
self._shutdown()
示例5: daemon_command
def daemon_command(self, options):
"""
Fires events:
* manager.daemon.started
* manager.daemon.completed
:param options: argparse options
"""
if options.action == 'start':
if options.daemonize:
self.daemonize()
with self.acquire_lock():
try:
signal.signal(signal.SIGTERM, self._handle_sigterm)
except ValueError as e:
# If flexget is being called from another script, e.g. windows service helper, and we are not the
# main thread, this error will occur.
log.debug('Error registering sigterm handler: %s' % e)
self.ipc_server.start()
fire_event('manager.daemon.started', self)
self.scheduler.start()
try:
self.scheduler.wait()
except KeyboardInterrupt:
log.info('Got ctrl-c, shutting down.')
fire_event('manager.daemon.completed', self)
self.shutdown(finish_queue=False)
elif options.action == 'status':
ipc_info = self.check_ipc_info()
if ipc_info:
log.info('Daemon running. (PID: %s)' % ipc_info['pid'])
else:
log.info('No daemon appears to be running for this config.')
elif options.action in ['stop', 'reload']:
ipc_info = self.check_ipc_info()
if ipc_info:
try:
client = IPCClient(ipc_info['port'], ipc_info['password'])
except ValueError as e:
log.error(e)
else:
if options.action == 'stop':
client.shutdown()
elif options.action == 'reload':
client.reload()
self.shutdown()
else:
log.error('There does not appear to be a daemon running.')
示例6: daemon_command
def daemon_command(self, options):
"""
Fires events:
* manager.daemon.started
* manager.daemon.completed
:param options: argparse options
"""
if options.action == 'start':
if options.daemonize:
self.daemonize()
with self.acquire_lock():
signal.signal(signal.SIGTERM, self._handle_sigterm)
self.ipc_server.start()
fire_event('manager.daemon.started', self)
self.scheduler.start()
try:
self.scheduler.wait()
except KeyboardInterrupt:
log.info('Got ctrl-c, shutting down.')
fire_event('manager.daemon.completed', self)
self.shutdown(finish_queue=False)
elif options.action == 'status':
ipc_info = self.check_ipc_info()
if ipc_info:
log.info('Daemon running. (PID: %s)' % ipc_info['pid'])
else:
log.info('No daemon appears to be running for this config.')
elif options.action in ['stop', 'reload']:
ipc_info = self.check_ipc_info()
if ipc_info:
try:
client = IPCClient(ipc_info['port'], ipc_info['password'])
except ValueError as e:
log.error(e)
else:
if options.action == 'stop':
client.shutdown()
elif options.action == 'reload':
client.reload()
self.shutdown()
else:
log.error('There does not appear to be a daemon running.')
示例7: start
def start(self):
"""
Starting point when executing from commandline, dispatch execution to correct destination.
If there is a FlexGet process with an ipc server already running, the command will be sent there for execution
and results will be streamed back.
If not, this will attempt to obtain a lock, initialize the manager, and run the command here.
"""
# When we are in test mode, we use a different lock file and db
if self.options.test:
self.lockfile = os.path.join(self.config_base, ".test-%s-lock" % self.config_name)
# If another process is started, send the execution to the running process
ipc_info = self.check_ipc_info()
if ipc_info:
console("There is a FlexGet process already running for this config, sending execution there.")
log.debug("Sending command to running FlexGet process: %s" % self.args)
try:
client = IPCClient(ipc_info["port"], ipc_info["password"])
except ValueError as e:
log.error(e)
else:
try:
client.handle_cli(self.args)
except KeyboardInterrupt:
log.error(
"Disconnecting from daemon due to ctrl-c. Executions will still continue in the " "background."
)
except EOFError:
log.error("Connection from daemon was severed.")
return
if self.options.test:
log.info("Test mode, creating a copy from database ...")
db_test_filename = os.path.join(self.config_base, "test-%s.sqlite" % self.config_name)
if os.path.exists(self.db_filename):
shutil.copy(self.db_filename, db_test_filename)
log.info("Test database created")
self.db_filename = db_test_filename
# No running process, we start our own to handle command
with self.acquire_lock():
self.initialize()
self.handle_cli()
self._shutdown()