mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-15 04:45:49 +01:00
Added progress bar and "silent" for running via the RunScript() xbmc function
This commit is contained in:
parent
76bd9ca529
commit
27265ad340
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<addon id="script.xbmcbackup"
|
<addon id="script.xbmcbackup"
|
||||||
name="XBMC Backup" version="0.0.2" provider-name="robweber">
|
name="XBMC Backup" version="0.0.3" provider-name="robweber">
|
||||||
<requires>
|
<requires>
|
||||||
<import addon="xbmc.python" version="2.0"/>
|
<import addon="xbmc.python" version="2.0"/>
|
||||||
</requires>
|
</requires>
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
[b]Version 0.0.2[/b]
|
[b]Version 0.0.2[/b]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
First version, should backup directories as needed
|
First version, should backup directories as needed
|
||||||
|
|
||||||
|
[b]Version 0.0.3[/b]
|
||||||
|
|
||||||
|
Added progress bar and "silent" option for running on startup or as a script
|
70
default.py
70
default.py
@ -10,6 +10,11 @@ class XbmcBackup:
|
|||||||
local_path = ''
|
local_path = ''
|
||||||
remote_path = ''
|
remote_path = ''
|
||||||
|
|
||||||
|
#for the progress bar
|
||||||
|
progressBar = None
|
||||||
|
dirsLeft = 0
|
||||||
|
dirsTotal = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.local_path = xbmc.translatePath("special://home")
|
self.local_path = xbmc.translatePath("special://home")
|
||||||
|
|
||||||
@ -28,49 +33,80 @@ class XbmcBackup:
|
|||||||
|
|
||||||
xbmcvfs.mkdir(self.remote_path)
|
xbmcvfs.mkdir(self.remote_path)
|
||||||
|
|
||||||
|
if(self.Addon.getSetting('run_silent') == 'false'):
|
||||||
|
self.progressBar = xbmcgui.DialogProgress()
|
||||||
|
self.progressBar.create('XBMC Backup','Running......')
|
||||||
|
self.updateProgress(1)
|
||||||
|
|
||||||
#figure out which syncing options to run
|
#figure out which syncing options to run
|
||||||
if(self.Addon.getSetting('backup_addons') == 'true'):
|
if(self.Addon.getSetting('backup_addons') == 'true' and not self.checkCancel()):
|
||||||
xbmcvfs.mkdir(self.remote_path + "addons")
|
xbmcvfs.mkdir(self.remote_path + "addons")
|
||||||
self.walkTree(self.local_path + "addons/")
|
self.walkTree(self.local_path + "addons/")
|
||||||
|
|
||||||
xbmcvfs.mkdir(self.remote_path + "userdata")
|
xbmcvfs.mkdir(self.remote_path + "userdata")
|
||||||
if(self.Addon.getSetting('backup_addon_data') == 'true'):
|
if(self.Addon.getSetting('backup_addon_data') == 'true' and not self.checkCancel()):
|
||||||
xbmcvfs.mkdir(self.remote_path + "userdata/addon_data")
|
xbmcvfs.mkdir(self.remote_path + "userdata/addon_data")
|
||||||
self.walkTree(self.local_path + "userdata/addon_data/")
|
self.walkTree(self.local_path + "userdata/addon_data/")
|
||||||
|
|
||||||
if(self.Addon.getSetting('backup_database') == 'true'):
|
if(self.Addon.getSetting('backup_database') == 'true' and not self.checkCancel()):
|
||||||
xbmcvfs.mkdir(self.remote_path + "userdata/Database")
|
xbmcvfs.mkdir(self.remote_path + "userdata/Database")
|
||||||
self.walkTree(self.local_path + "userdata/Database")
|
self.walkTree(self.local_path + "userdata/Database")
|
||||||
|
|
||||||
if(self.Addon.getSetting("backup_playlists") == 'true'):
|
if(self.Addon.getSetting("backup_playlists") == 'true' and not self.checkCancel()):
|
||||||
xbmcvfs.mkdir(self.remote_path + "userdata/playlists")
|
xbmcvfs.mkdir(self.remote_path + "userdata/playlists")
|
||||||
self.walkTree(self.local_path + "userdata/playlists")
|
self.walkTree(self.local_path + "userdata/playlists")
|
||||||
|
|
||||||
if(self.Addon.getSetting("backup_thumbnails") == "true"):
|
if(self.Addon.getSetting("backup_thumbnails") == "true" and not self.checkCancel()):
|
||||||
xbmcvfs.mkdir(self.remote_path + "userdata/Thumbnails")
|
xbmcvfs.mkdir(self.remote_path + "userdata/Thumbnails")
|
||||||
self.walkTree(self.local_path + "userdata/Thumbnails")
|
self.walkTree(self.local_path + "userdata/Thumbnails")
|
||||||
|
|
||||||
if(self.Addon.getSetting("backup_config") == "true"):
|
if(self.Addon.getSetting("backup_config") == "true" and not self.checkCancel()):
|
||||||
#this on is an oddity
|
#this one is an oddity
|
||||||
configFiles = os.listdir(self.local_path + "userdata/")
|
configFiles = os.listdir(self.local_path + "userdata/")
|
||||||
for aFile in configFiles:
|
for aFile in configFiles:
|
||||||
if(aFile.endswith(".xml")):
|
if(aFile.endswith(".xml")):
|
||||||
self.log("Copying: " + self.local_path + "userdata/" + aFile)
|
self.log("Copying: " + self.local_path + "userdata/" + aFile)
|
||||||
xbmcvfs.copy(self.local_path + "userdata/" + aFile,self.remote_path + "userdata/" + aFile)
|
xbmcvfs.copy(self.local_path + "userdata/" + aFile,self.remote_path + "userdata/" + aFile)
|
||||||
|
|
||||||
|
if(self.Addon.getSetting('run_silent') == 'false'):
|
||||||
|
self.progressBar.close()
|
||||||
|
|
||||||
|
|
||||||
def walkTree(self,directory):
|
def walkTree(self,directory):
|
||||||
for (path, dirs, files) in os.walk(directory):
|
for (path, dirs, files) in os.walk(directory):
|
||||||
#get the relative part of this path
|
if(not self.checkCancel()):
|
||||||
path = path[len(self.local_path):]
|
#get the relative part of this path
|
||||||
|
path = path[len(self.local_path):]
|
||||||
|
|
||||||
#create all the subdirs first
|
#subtract one from total
|
||||||
for aDir in dirs:
|
self.dirsLeft = self.dirsLeft - 1
|
||||||
xbmcvfs.mkdir(self.remote_path + os.sep + path + os.sep + aDir)
|
self.updateProgress(len(dirs),"Copying: " + path)
|
||||||
#copy all the files
|
|
||||||
for aFile in files:
|
#create all the subdirs first
|
||||||
filePath = path + os.sep + aFile
|
for aDir in dirs:
|
||||||
self.log("copying: " + self.local_path + filePath)
|
xbmcvfs.mkdir(self.remote_path + os.sep + path + os.sep + aDir)
|
||||||
xbmcvfs.copy(self.local_path + filePath,self.remote_path + filePath)
|
#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 updateProgress(self,dirCount,message=''):
|
||||||
|
#add to the total
|
||||||
|
self.dirsTotal = self.dirsTotal + dirCount
|
||||||
|
self.dirsLeft = self.dirsLeft + dirCount
|
||||||
|
|
||||||
|
#update the progress bar
|
||||||
|
if(self.progressBar != None):
|
||||||
|
self.progressBar.update((float(self.dirsTotal - self.dirsLeft)/float(self.dirsTotal)) * 100,message)
|
||||||
|
|
||||||
|
def checkCancel(self):
|
||||||
|
result = False
|
||||||
|
|
||||||
|
if(self.progressBar != None):
|
||||||
|
result = self.progressBar.iscanceled()
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def log(self,message):
|
def log(self,message):
|
||||||
xbmc.log(self.__addon_id__ + ": " + message)
|
xbmc.log(self.__addon_id__ + ": " + message)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
<string id="30020">Remote Path</string>
|
<string id="30020">Remote Path</string>
|
||||||
<string id="30021">Backup Folder Name</string>
|
<string id="30021">Backup Folder Name</string>
|
||||||
|
<string id="30022">Run Silent</string>
|
||||||
|
|
||||||
<string id="30030">User Addons</string>
|
<string id="30030">User Addons</string>
|
||||||
<string id="30031">Addon Data</string>
|
<string id="30031">Addon Data</string>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<category id="general" label="30011">
|
<category id="general" label="30011">
|
||||||
<setting id="remote_path" type="folder" label="30020" />
|
<setting id="remote_path" type="folder" label="30020" />
|
||||||
<setting id="backup_name" type="text" label="30021" default="xbmc_backup"/>
|
<setting id="backup_name" type="text" label="30021" default="xbmc_backup"/>
|
||||||
|
<setting id="run_silent" type="bool" label="30022" default="false" />
|
||||||
</category>
|
</category>
|
||||||
<category id="selection" label="30012">
|
<category id="selection" label="30012">
|
||||||
<setting id="backup_addons" type="bool" label="30030" default="true" />
|
<setting id="backup_addons" type="bool" label="30030" default="true" />
|
||||||
|
Loading…
Reference in New Issue
Block a user