mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
used xbmcvfs to use xbmc functions for actual file copy
added options to selectively copy certain folders
This commit is contained in:
parent
c39b5d540a
commit
3fa30e407a
70
default.py
70
default.py
@ -1,19 +1,67 @@
|
||||
import xbmc
|
||||
import xbmcaddon
|
||||
import xbmcgui
|
||||
import xbmcvfs
|
||||
import shutil
|
||||
import os
|
||||
|
||||
#get the addon class
|
||||
__addon_id__ = 'script.xbmcbackup'
|
||||
Addon = xbmcaddon.Addon(__addon_id__)
|
||||
class XbmcBackup:
|
||||
__addon_id__ = 'script.xbmcbackup'
|
||||
Addon = xbmcaddon.Addon(__addon_id__)
|
||||
local_path = ''
|
||||
remote_path = ''
|
||||
|
||||
def syncFiles():
|
||||
xbmc.log(xbmc.translatePath("special://profile"))
|
||||
xbmc.log(Addon.getSetting("remote_path"))
|
||||
def __init__(self):
|
||||
self.local_path = xbmc.translatePath("special://home")
|
||||
|
||||
if(xbmcvfs.exists(Addon.getSetting("remote_path") + "profile")):
|
||||
shutil.rmtree(Addon.getSetting("remote_path") + "profile")
|
||||
if(self.Addon.getSetting('remote_path') != '' and self.Addon.getSetting("backup_name") != ''):
|
||||
self.remote_path = self.Addon.getSetting("remote_path") + self.Addon.getSetting('backup_name') + "/"
|
||||
|
||||
shutil.copytree(xbmc.translatePath("special://profile"),Addon.getSetting("remote_path") + "profile")
|
||||
self.log("Starting")
|
||||
self.log('Local Dir: ' + self.local_path)
|
||||
self.log('Remote Dir: ' + self.remote_path)
|
||||
|
||||
syncFiles()
|
||||
def syncFiles(self):
|
||||
|
||||
if(xbmcvfs.exists(self.remote_path)):
|
||||
#this will fail - need a disclaimer here
|
||||
self.log("Remote Path exists - may have old files in it!")
|
||||
|
||||
xbmcvfs.mkdir(self.remote_path)
|
||||
|
||||
#figure out which syncing options to run
|
||||
if(self.Addon.getSetting('backup_addons') == 'true'):
|
||||
xbmcvfs.mkdir(self.remote_path + "addons")
|
||||
self.walkTree(self.local_path + "addons/")
|
||||
|
||||
xbmcvfs.mkdir(self.remote_path + "userdata")
|
||||
if(self.Addon.getSetting('backup_addon_data') == 'true'):
|
||||
xbmcvfs.mkdir(self.remote_path + "userdata/addon_data")
|
||||
self.walkTree(self.local_path + "userdata/addon_data/")
|
||||
|
||||
def walkTree(self,directory):
|
||||
for (path, dirs, files) in os.walk(directory):
|
||||
#get the relative part of this path
|
||||
path = path[len(self.local_path):]
|
||||
|
||||
#create all the subdirs first
|
||||
for aDir in dirs:
|
||||
xbmcvfs.mkdir(self.remote_path + os.sep + path + os.sep + aDir)
|
||||
#copy all the files
|
||||
for aFile in files:
|
||||
filePath = path + os.sep + aFile
|
||||
self.log("copying: " + self.local_path + filePath)
|
||||
xbmcvfs.copy(self.local_path + filePath,self.remote_path + filePath)
|
||||
|
||||
def log(self,message):
|
||||
xbmc.log(self.__addon_id__ + ": " + message)
|
||||
|
||||
def isReady(self):
|
||||
return True if self.remote_path != '' else False
|
||||
|
||||
#run the profile backup
|
||||
backup = XbmcBackup()
|
||||
|
||||
if(backup.isReady()):
|
||||
backup.syncFiles()
|
||||
else:
|
||||
xbmcgui.Dialog().ok('XBMC Backup','Error: Remote path cannot be empty')
|
||||
|
@ -2,5 +2,14 @@
|
||||
<settings>
|
||||
<category id="general" label="30000">
|
||||
<setting id="remote_path" type="folder" label="Remote Path" />
|
||||
<setting id="backup_name" type="text" label="Backup Folder Name" default="xbmc_backup"/>
|
||||
</category>
|
||||
<category id="selection" label="Backup Selection">
|
||||
<setting id="backup_addons" type="bool" label="User Addons" default="true" />
|
||||
<setting id="backup_addon_data" type="bool" label="Addon Data" default="false" />
|
||||
<setting id="backup_database" type="bool" label="Database" default="true" />
|
||||
<setting id="backup_playlists" type="bool" label="Playlists" default="true" />
|
||||
<setting id="backup_thumbnails" type="bool" label="Thumbnails/Fanart" default="true" />
|
||||
<setting id="backup_config" type="bool" label="Config Files" default="true" />
|
||||
</category>
|
||||
</settings>
|
||||
|
Loading…
Reference in New Issue
Block a user