Add backup option

This commit is contained in:
angelblue05 2016-09-18 02:53:52 -05:00
parent c58e4d84e7
commit 4c0ef2fe7a
5 changed files with 59 additions and 3 deletions

View file

@ -95,7 +95,8 @@ class Main(object):
'refreshplaylist': entrypoint.refreshPlaylist, 'refreshplaylist': entrypoint.refreshPlaylist,
'deviceid': entrypoint.resetDeviceId, 'deviceid': entrypoint.resetDeviceId,
'delete': entrypoint.deleteItem, 'delete': entrypoint.deleteItem,
'connect': entrypoint.emby_connect 'connect': entrypoint.emby_connect,
'backup': entrypoint.emby_backup
} }
if mode in modes: if mode in modes:
# Simple functions # Simple functions

View file

@ -342,5 +342,10 @@
<string id="33086">Remove all cached artwork?</string> <string id="33086">Remove all cached artwork?</string>
<string id="33087">Reset all Emby add-on settings?</string> <string id="33087">Reset all Emby add-on settings?</string>
<string id="33088">Database reset has completed, Kodi will now restart to apply the changes.</string> <string id="33088">Database reset has completed, Kodi will now restart to apply the changes.</string>
<string id="33089">Enter folder name for backup</string>
<string id="33090">Replace existing backup?</string>
<string id="33091">Create backup at:</string>
<string id="33092">Create a backup</string>
<string id="33093">Backup folder</string>
</strings> </strings>

View file

@ -5,6 +5,7 @@
import json import json
import logging import logging
import os import os
import shutil
import sys import sys
import urlparse import urlparse
@ -113,6 +114,9 @@ def doMainListing():
addDirectoryItem(lang(33059), "plugin://plugin.video.emby/?mode=texturecache") addDirectoryItem(lang(33059), "plugin://plugin.video.emby/?mode=texturecache")
addDirectoryItem(lang(33060), "plugin://plugin.video.emby/?mode=thememedia") addDirectoryItem(lang(33060), "plugin://plugin.video.emby/?mode=thememedia")
if settings('backupPath'):
addDirectoryItem(lang(33092), "plugin://plugin.video.emby/?mode=backup")
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(int(sys.argv[1]))
def emby_connect(): def emby_connect():
@ -135,6 +139,50 @@ def emby_connect():
settings('connectUsername', value=username) settings('connectUsername', value=username)
def emby_backup():
# Create a backup at specified location
path = settings('backupPath')
# filename
default_value = "Kodi%s.%s" % (xbmc.getInfoLabel('System.BuildVersion')[:2],
xbmc.getInfoLabel('System.Date(dd-mm-yy)'))
filename = dialog(type_="input",
heading=lang(33089),
defaultt=default_value)
if not filename:
return
backup = os.path.join(path, filename)
log.info("Backup: %s", backup)
# Create directory
if xbmcvfs.exists(backup+"\\"):
log.info("Existing directory!")
if not dialog(type_="yesno",
heading="{emby}",
line1=lang(33090)):
return emby_backup()
shutil.rmtree(backup)
# Addon_data
shutil.copytree(src=xbmc.translatePath(
"special://profile/addon_data/plugin.video.emby").decode('utf-8'),
dst=os.path.join(backup, "addon_data", "plugin.video.emby"))
# Database files
xbmcvfs.mkdir(os.path.join(backup, "Database"))
shutil.copy(src=utils.getKodiVideoDBPath(),
dst=os.path.join(backup, "Database"))
if settings('enableMusic') == "true":
shutil.copy(src=utils.getKodiMusicDBPath(),
dst=os.path.join(backup, "Database"))
dialog(type_="ok",
heading="{emby}",
line1="%s: %s" % (lang(33091), backup))
##### Generate a new deviceId ##### Generate a new deviceId
def resetDeviceId(): def resetDeviceId():

View file

@ -50,7 +50,7 @@ def language(string_id):
# Central string retrieval - unicode # Central string retrieval - unicode
return xbmcaddon.Addon(id='plugin.video.emby').getLocalizedString(string_id) return xbmcaddon.Addon(id='plugin.video.emby').getLocalizedString(string_id)
def dialog(type_, **kwargs): def dialog(type_, *args, **kwargs):
d = xbmcgui.Dialog() d = xbmcgui.Dialog()
@ -68,7 +68,7 @@ def dialog(type_, **kwargs):
'select': d.select, 'select': d.select,
'numeric': d.numeric 'numeric': d.numeric
} }
return types[type_](**kwargs) return types[type_](*args, **kwargs)
class JSONRPC(object): class JSONRPC(object):

View file

@ -80,5 +80,7 @@
<setting id="startupDelay" type="number" label="30529" default="0" option="int" /> <setting id="startupDelay" type="number" label="30529" default="0" option="int" />
<setting label="30239" type="action" action="RunPlugin(plugin://plugin.video.emby?mode=reset)" option="close" /> <setting label="30239" type="action" action="RunPlugin(plugin://plugin.video.emby?mode=reset)" option="close" />
<setting label="30535" type="action" action="RunPlugin(plugin://plugin.video.emby?mode=deviceid)" /> <setting label="30535" type="action" action="RunPlugin(plugin://plugin.video.emby?mode=deviceid)" />
<setting label="33093" type="folder" id="backupPath" option="writeable" />
<setting label="33092" type="action" action="RunPlugin(plugin://plugin.video.emby?mode=backup)" visible="!eq(-1,)" option="close" />
</category> </category>
</settings> </settings>