Commit 9f9fcaba authored by echel0n's avatar echel0n

Added `backup` call to API, allows you to specify the folder you wish to...

Added `backup` call to API, allows you to specify the folder you wish to backup your application data to.
parent 202e3599
# Changelog
- * 02fcf0a - 2018-11-16: Release v9.4.35
- * 616e1e5 - 2018-11-17: Added `backup` call to API, allows you to specify the folder you wish to backup your application data to.
- * c92467e - 2018-11-16: Release v9.4.35
- * 11ac4c6 - 2018-11-16: Fixed Mako error related to no imdb_info present. Refactored `episode_string_fallback` to list.
- * 70d42c2 - 2018-11-14: Release v9.4.34
- * 4478e39 - 2018-11-14: Release v9.4.33
......
......@@ -1002,6 +1002,9 @@ def backupSR(backupDir, keep_latest=False):
for f in sorted(glob.glob(os.path.join(backupDir, '*.zip')), key=os.path.getctime, reverse=True)[1:]:
os.remove(f)
if not os.path.exists(backupDir):
os.mkdir(backupDir)
if keep_latest:
_keep_latest_backup()
......
......@@ -47,7 +47,7 @@ from sickrage.core.common import ARCHIVED, DOWNLOADED, IGNORED, \
timeFormat
from sickrage.core.exceptions import CantUpdateShowException, CantRemoveShowException, CantRefreshShowException
from sickrage.core.helpers import chmod_as_parent, findCertainShow, makeDir, \
pretty_filesize, sanitizeFileName, srdatetime, try_int, readFileBuffered, app_statistics
pretty_filesize, sanitizeFileName, srdatetime, try_int, readFileBuffered, app_statistics, backupSR
from sickrage.core.media.banner import Banner
from sickrage.core.media.fanart import FanArt
from sickrage.core.media.network import Network
......@@ -627,6 +627,30 @@ class CMD_Help(ApiCall):
return out
class CMD_Backup(ApiCall):
_cmd = "backup"
_help = {
"desc": "Backup application data files",
"requiredParameters": {
"backup_dir": {"desc": "Directory to store backup files"},
}
}
def __init__(self, application, request, *args, **kwargs):
super(CMD_Backup, self).__init__(application, request, *args, **kwargs)
self.backup_dir, args = self.check_params("backup_dir", sickrage.app.data_dir, True, "string", [], *args,
**kwargs)
def run(self):
""" Performs application backup """
if backupSR(self.backup_dir):
response = _responds(RESULT_SUCCESS, msg='Backup successful')
else:
response = _responds(RESULT_FAILURE, msg='Backup failed')
return response
class CMD_ComingEpisodes(ApiCall):
_cmd = "future"
_help = {
......@@ -1754,9 +1778,12 @@ class CMD_Show(ApiCall):
return _responds(RESULT_FAILURE, msg="Show not found")
showDict = {
"season_list": CMD_ShowSeasonList(self.application, self.request, **{"indexerid": self.indexerid}).run()[
"data"],
"cache": CMD_ShowCache(self.application, self.request, **{"indexerid": self.indexerid}).run()["data"]
"season_list": CMD_ShowSeasonList(self.application, self.request, **{
"indexerid": self.indexerid
}).run()["data"],
"cache": CMD_ShowCache(self.application, self.request, **{
"indexerid": self.indexerid
}).run()["data"]
}
genreList = []
......@@ -1808,7 +1835,8 @@ class CMD_Show(ApiCall):
if try_int(showObj.next_aired, 1) > 693595:
dtEpisodeAirs = srdatetime.srDateTime(
sickrage.app.tz_updater.parse_date_time(showObj.next_aired, showDict['airs'], showDict['network']), convert=True).dt
sickrage.app.tz_updater.parse_date_time(showObj.next_aired, showDict['airs'], showDict['network']),
convert=True).dt
showDict['airs'] = srdatetime.srDateTime(dtEpisodeAirs).srftime(t_preset=timeFormat).lstrip('0').replace(
' 0', ' ')
showDict['next_ep_airdate'] = srdatetime.srDateTime(dtEpisodeAirs).srfdate(d_preset=dateFormat)
......@@ -2371,7 +2399,7 @@ class CMD_ShowSeasonList(ApiCall):
if not showObj:
return _responds(RESULT_FAILURE, msg="Show not found")
seasonList = sorted((x['season'] for x in sickrage.app.main_db.get_many('tv_episodes', self.indexerid)),
seasonList = sorted(set(x['season'] for x in sickrage.app.main_db.get_many('tv_episodes', self.indexerid)),
key=lambda d: d, reverse=not self.sort == "asc")
return _responds(RESULT_SUCCESS, seasonList)
......@@ -2411,7 +2439,8 @@ class CMD_ShowSeasons(ApiCall):
if try_int(row['airdate'], 1) > 693595: # 1900
dtEpisodeAirs = srdatetime.srDateTime(
sickrage.app.tz_updater.parse_date_time(row['airdate'], showObj.airs, showObj.network), convert=True).dt
sickrage.app.tz_updater.parse_date_time(row['airdate'], showObj.airs, showObj.network),
convert=True).dt
row['airdate'] = srdatetime.srDateTime(dtEpisodeAirs).srfdate(d_preset=dateFormat)
else:
row['airdate'] = 'Never'
......@@ -2443,7 +2472,8 @@ class CMD_ShowSeasons(ApiCall):
row["quality"] = get_quality_string(quality)
if try_int(row['airdate'], 1) > 693595: # 1900
dtEpisodeAirs = srdatetime.srDateTime(
sickrage.app.tz_updater.parse_date_time(row['airdate'], showObj.airs, showObj.network), convert=True).dt
sickrage.app.tz_updater.parse_date_time(row['airdate'], showObj.airs, showObj.network),
convert=True).dt
row['airdate'] = srdatetime.srDateTime(dtEpisodeAirs).srfdate(d_preset=dateFormat)
else:
row['airdate'] = 'Never'
......@@ -2691,7 +2721,8 @@ class CMD_Shows(ApiCall):
if try_int(curShow.next_aired, 1) > 693595: # 1900
dtEpisodeAirs = srdatetime.srDateTime(
sickrage.app.tz_updater.parse_date_time(curShow.next_aired, curShow.airs, showDict['network']), convert=True).dt
sickrage.app.tz_updater.parse_date_time(curShow.next_aired, curShow.airs, showDict['network']),
convert=True).dt
showDict['next_ep_airdate'] = srdatetime.srDateTime(dtEpisodeAirs).srfdate(d_preset=dateFormat)
else:
showDict['next_ep_airdate'] = ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment