本文整理汇总了Python中sickbeard.webserveInit.SRWebServer.shutDown方法的典型用法代码示例。如果您正苦于以下问题:Python SRWebServer.shutDown方法的具体用法?Python SRWebServer.shutDown怎么用?Python SRWebServer.shutDown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sickbeard.webserveInit.SRWebServer
的用法示例。
在下文中一共展示了SRWebServer.shutDown方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SickRage
# 需要导入模块: from sickbeard.webserveInit import SRWebServer [as 别名]
# 或者: from sickbeard.webserveInit.SRWebServer import shutDown [as 别名]
#.........这里部分代码省略.........
stdout = file(devnull, 'a+')
stderr = file(devnull, 'a+')
os.dup2(stdin.fileno(), getattr(sys.stdin, 'device', sys.stdin).fileno())
os.dup2(stdout.fileno(), getattr(sys.stdout, 'device', sys.stdout).fileno())
os.dup2(stderr.fileno(), getattr(sys.stderr, 'device', sys.stderr).fileno())
@staticmethod
def remove_pid_file(PIDFILE):
try:
if ek(os.path.exists, PIDFILE):
ek(os.remove, PIDFILE)
except (IOError, OSError):
return False
return True
@staticmethod
def loadShowsFromDB():
"""
Populates the showList with shows from the database
"""
logger.log(u"Loading initial show list", logger.DEBUG)
myDB = db.DBConnection()
sqlResults = myDB.select("SELECT indexer, indexer_id, location FROM tv_shows;")
sickbeard.showList = []
for sqlShow in sqlResults:
try:
curShow = TVShow(int(sqlShow["indexer"]), int(sqlShow["indexer_id"]))
curShow.nextEpisode()
sickbeard.showList.append(curShow)
except Exception as e:
logger.log(
u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'),
logger.ERROR)
logger.log(traceback.format_exc(), logger.DEBUG)
@staticmethod
def restoreDB(srcDir, dstDir):
try:
filesList = ['sickbeard.db', 'config.ini', 'failed.db', 'cache.db']
for filename in filesList:
srcFile = ek(os.path.join, srcDir, filename)
dstFile = ek(os.path.join, dstDir, filename)
bakFile = ek(os.path.join, dstDir, '{0}.bak-{1}'.format(filename, datetime.datetime.now().strftime('%Y%m%d_%H%M%S')))
if ek(os.path.isfile, dstFile):
shutil.move(dstFile, bakFile)
shutil.move(srcFile, dstFile)
return True
except Exception:
return False
def shutdown(self, event):
if sickbeard.started:
# stop all tasks
sickbeard.halt()
# save all shows to DB
sickbeard.saveAll()
# shutdown web server
if self.webserver:
logger.log(u"Shutting down Tornado")
self.webserver.shutDown()
try:
self.webserver.join(10)
except Exception:
pass
# if run as daemon delete the pidfile
if self.runAsDaemon and self.CREATEPID:
self.remove_pid_file(self.PIDFILE)
if event == sickbeard.event_queue.Events.SystemEvent.RESTART:
install_type = sickbeard.versionCheckScheduler.action.install_type
popen_list = []
if install_type in ('git', 'source'):
popen_list = [sys.executable, sickbeard.MY_FULLNAME]
elif install_type == 'win':
logger.log(u"You are using a binary Windows build of SickRage. Please switch to using git.", logger.ERROR)
if popen_list and not sickbeard.NO_RESTART:
popen_list += sickbeard.MY_ARGS
if '--nolaunch' not in popen_list:
popen_list += ['--nolaunch']
logger.log(u"Restarting SickRage with " + str(popen_list))
logger.shutdown() # shutdown the logger to make sure it's released the logfile BEFORE it restarts SR.
subprocess.Popen(popen_list, cwd=os.getcwd())
# system exit
logger.shutdown() # Make sure the logger has stopped, just in case
# pylint: disable=protected-access
# Access to a protected member of a client class
os._exit(0)
示例2: SickRage
# 需要导入模块: from sickbeard.webserveInit import SRWebServer [as 别名]
# 或者: from sickbeard.webserveInit.SRWebServer import shutDown [as 别名]
#.........这里部分代码省略.........
if ek(os.path.exists, pid_file):
ek(os.remove, pid_file)
except EnvironmentError:
return False
return True
@staticmethod
def load_shows_from_db():
"""
Populates the showList with shows from the database
"""
logger.log('Loading initial show list', logger.DEBUG)
main_db_con = db.DBConnection()
sql_results = main_db_con.select('SELECT indexer, indexer_id, location FROM tv_shows;')
sickbeard.showList = []
for sql_show in sql_results:
try:
cur_show = TVShow(sql_show[b'indexer'], sql_show[b'indexer_id'])
cur_show.nextEpisode()
sickbeard.showList.append(cur_show)
except Exception as error: # pylint: disable=broad-except
logger.log('There was an error creating the show in {0}: Error {1}'.format
(sql_show[b'location'], error), logger.ERROR)
logger.log(traceback.format_exc(), logger.DEBUG)
@staticmethod
def restore_db(src_dir, dst_dir):
"""
Restore the Database from a backup
:param src_dir: Directory containing backup
:param dst_dir: Directory to restore to
:return:
"""
try:
files_list = ['sickbeard.db', 'config.ini', 'failed.db', 'cache.db']
for filename in files_list:
src_file = ek(os.path.join, src_dir, filename)
dst_file = ek(os.path.join, dst_dir, filename)
bak_file = ek(os.path.join, dst_dir, '{0}.bak-{1}'.format(filename, datetime.datetime.now().strftime('%Y%m%d_%H%M%S')))
if ek(os.path.isfile, dst_file):
shutil.move(dst_file, bak_file)
shutil.move(src_file, dst_file)
return True
except Exception: # pylint: disable=broad-except
return False
def shutdown(self, event):
"""
Shut down SickRage
:param event: Type of shutdown event, used to see if restart required
"""
if sickbeard.started:
sickbeard.halt() # stop all tasks
sickbeard.saveAll() # save all shows to DB
# shutdown web server
if self.web_server:
logger.log('Shutting down Tornado')
self.web_server.shutDown()
try:
self.web_server.join(10)
except Exception: # pylint: disable=broad-except
pass
self.clear_cache() # Clean cache
# if run as daemon delete the pid file
if self.run_as_daemon and self.create_pid:
self.remove_pid_file(self.pid_file)
if event == sickbeard.event_queue.Events.SystemEvent.RESTART:
install_type = sickbeard.versionCheckScheduler.action.install_type
popen_list = []
if install_type in ('git', 'source'):
popen_list = [sys.executable, sickbeard.MY_FULLNAME]
elif install_type == 'win':
logger.log('You are using a binary Windows build of SickRage. '
'Please switch to using git.', logger.ERROR)
if popen_list and not sickbeard.NO_RESTART:
popen_list += sickbeard.MY_ARGS
if '--nolaunch' not in popen_list:
popen_list += ['--nolaunch']
logger.log('Restarting SickRage with {options}'.format(options=popen_list))
# shutdown the logger to make sure it's released the logfile BEFORE it restarts SR.
logger.shutdown()
subprocess.Popen(popen_list, cwd=os.getcwd())
# Make sure the logger has stopped, just in case
logger.shutdown()
os._exit(0) # pylint: disable=protected-access
示例3: SickRage
# 需要导入模块: from sickbeard.webserveInit import SRWebServer [as 别名]
# 或者: from sickbeard.webserveInit.SRWebServer import shutDown [as 别名]
#.........这里部分代码省略.........
def load_shows_from_db():
"""
Populates the showList with shows from the database
"""
logger.log("Loading initial show list", logger.DEBUG) # pylint: disable=no-member
main_db_con = db.DBConnection()
sql_results = main_db_con.select("SELECT indexer, indexer_id, location FROM tv_shows;")
sickbeard.showList = []
for sql_show in sql_results:
try:
cur_show = TVShow(sql_show[b"indexer"], sql_show[b"indexer_id"])
cur_show.nextEpisode()
sickbeard.showList.append(cur_show)
except Exception as error_msg: # pylint: disable=broad-except
logger.log(
"There was an error creating the show in %s: %s"
% (sql_show[b"location"], str(error_msg).decode()), # pylint: disable=no-member
logger.ERROR,
)
logger.log(traceback.format_exc(), logger.DEBUG) # pylint: disable=no-member
@staticmethod
def restore_db(src_dir, dst_dir):
"""
Restore the Database from a backup
:param src_dir: Directory containing backup
:param dst_dir: Directory to restore to
:return:
"""
try:
files_list = ["sickbeard.db", "config.ini", "failed.db", "cache.db"]
for filename in files_list:
src_file = ek(os.path.join, src_dir, filename)
dst_file = ek(os.path.join, dst_dir, filename)
bak_file = ek(
os.path.join, dst_dir, "%s.bak-%s" % (filename, datetime.datetime.now().strftime("%Y%m%d_%H%M%S"))
)
if ek(os.path.isfile, dst_file):
shutil.move(dst_file, bak_file)
shutil.move(src_file, dst_file)
return True
except Exception: # pylint: disable=broad-except
return False
def shutdown(self, event):
"""
Shut down SickRage
:param event: Type of shutdown event, used to see if restart required
"""
if sickbeard.started:
sickbeard.halt() # stop all tasks
sickbeard.saveAll() # save all shows to DB
# shutdown web server
if self.web_server:
logger.log("Shutting down Tornado") # pylint: disable=no-member
self.web_server.shutDown()
try:
self.web_server.join(10)
except Exception: # pylint: disable=broad-except
pass
self.clear_cache() # Clean cache
# if run as daemon delete the pid file
if self.run_as_daemon and self.create_pid:
self.remove_pid_file(self.pid_file)
if event == sickbeard.event_queue.Events.SystemEvent.RESTART:
install_type = sickbeard.versionCheckScheduler.action.install_type
popen_list = []
if install_type in ("git", "source"):
popen_list = [sys.executable, sickbeard.MY_FULLNAME]
elif install_type == "win":
logger.log(
"You are using a binary Windows build of SickRage. " # pylint: disable=no-member
"Please switch to using git.",
logger.ERROR,
)
if popen_list and not sickbeard.NO_RESTART:
popen_list += sickbeard.MY_ARGS
if "--nolaunch" not in popen_list:
popen_list += ["--nolaunch"]
logger.log("Restarting SickRage with %s" % popen_list) # pylint: disable=no-member
# shutdown the logger to make sure it's released the logfile BEFORE it restarts SR.
logger.shutdown() # pylint: disable=no-member
subprocess.Popen(popen_list, cwd=os.getcwd())
# Make sure the logger has stopped, just in case
logger.shutdown() # pylint: disable=no-member
os._exit(0) # pylint: disable=protected-access