kodi-community-addons / script.skin.helper.skinbackup

Kodi add-on to create skin backups and themes
GNU General Public License v2.0
7 stars 9 forks source link

skin backup issue #2

Open mgonzales71 opened 7 years ago

mgonzales71 commented 7 years ago

FYI running on latest krypton nightly under windows 10 pro x64

automatic skin backups still aren't working but noticed in the log script threw and exception even though GUI reported backup was successful.

This may be the cause of auto backups not working.. I noticed the settings for the script in addon_data updates the with a new date of last backup even though it never gets created.

2016-12-12_00-02-15

00:00:32.453 T:6940   ERROR: unmatched parentheses in Skin.HasSetting(subtitle))
00:00:47.209 T:6940   ERROR: XFILE::CFile::Delete - Error deleting file C:\Users\Mario\AppData\Roaming\Kodi\cache\skinbackup\skinshortcuts\skin.titan.kryptonbeta-background-plugin.video.genesis.png
00:00:47.209 T:6940   ERROR: XFILE::CFile::Delete - Error deleting file special://temp/skinbackup/skinshortcuts/skin.titan.kryptonbeta-background-plugin.video.genesis.png
00:00:47.274 T:6940   ERROR: XFILE::CDirectory::Remove - Error removing C:\Users\Mario\AppData\Roaming\Kodi\cache\skinbackup\skinshortcuts
00:00:47.274 T:6940   ERROR: XFILE::CDirectory::Remove - Error removing special://temp/skinbackup/skinshortcuts
00:00:47.292 T:11504   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.WindowsError'>
                                            Error Contents: (2, 'The system cannot find the file specified', 'C:\\Users\\Mario\\AppData\\Roaming\\Kodi\\cache\\skinbackup\\skinshortcuts\\skin.titan.kryptonbeta-background-plugin.video.salts-.jpg')
                                            Traceback (most recent call last):
                                              File "C:\Users\Mario\AppData\Roaming\Kodi\addons\script.skin.helper.skinbackup\service.py", line 49, in <module>
                                                Service().run()
                                              File "C:\Users\Mario\AppData\Roaming\Kodi\addons\script.skin.helper.skinbackup\service.py", line 39, in run
                                                self.backuprestore.check_autobackup()
                                              File "C:\Users\Mario\AppData\Roaming\Kodi\addons\script.skin.helper.skinbackup\resources\lib\backuprestore.py", line 413, in check_autobackup
                                                self.backup(backup_file=backupfile, silent=True)
                                              File "C:\Users\Mario\AppData\Roaming\Kodi\addons\script.skin.helper.skinbackup\resources\lib\backuprestore.py", line 57, in backup
                                                zip_tofile(temp_path, zip_temp)
                                              File "C:\Users\Mario\AppData\Roaming\Kodi\addons\script.skin.helper.skinbackup\resources\lib\utils.py", line 130, in zip_tofile
                                                zip_file = add_tozip(src, zip_file, abs_src)
                                              File "C:\Users\Mario\AppData\Roaming\Kodi\addons\script.skin.helper.skinbackup\resources\lib\utils.py", line 121, in add_tozip
                                                add_tozip(os.path.join(src, directory), zip_file, abs_src)
                                              File "C:\Users\Mario\AppData\Roaming\Kodi\addons\script.skin.helper.skinbackup\resources\lib\utils.py", line 119, in add_tozip
                                                zip_file.write(absname.encode("utf-8"), arcname.encode("utf-8"))
                                              File "C:\Program Files (x86)\Kodi\system\python\Lib\zipfile.py", line 1123, in write
                                                st = os.stat(filename)
                                            WindowsError: (2, 'The system cannot find the file specified', 'C:\\Users\\Mario\\AppData\\Roaming\\Kodi\\cache\\skinbackup\\skinshortcuts\\skin.titan.kryptonbeta-background-plugin.video.salts-.jpg')
                                            -->End of Python script error report<--
00:00:47.310 T:6940   ERROR: XFILE::CDirectory::Remove - Error removing C:\Users\Mario\AppData\Roaming\Kodi\cache\skinbackup\
00:00:47.310 T:6940   ERROR: XFILE::CDirectory::Remove - Error removing special://temp/skinbackup/

settings.xml.txt

let me know if I can do any testing for you with this issue.

Hope you are having a wonderful Holiday Season!

Mario

mgonzales71 commented 7 years ago

Marcel,

wanted to update you on the issue I am seeing with skinbackup (auto and manual it seems).

I commented the following out of the backuprestore python script:

# cleanup temp
        recursive_delete_dir(temp_path)
        xbmcvfs.delete(zip_temp)

because I was consistently seeing a skinbackup in cache being created and populated along with a zip file.

the issue I am seeing when the backup "fails" is that the created zip in cache does not get copied/moved to the destination directory and then the "cleanup" removes the backup files and the zip,

for some reason (and I can't seem to thrown and error to give me a clue (even with debug enabled)) the zip never makes it out of temp and then cleanup - well cleans it up :smile:

the odd thing is - I created a shortcut sub-menu to run the backup action over and over and the results are random for the success of the zip making it to the final destination but every time the script reports a success via dialog OK.

maybe this will help you see something I am missing?

I am on Windows 10 Pro x64 AE running latest Krypton nightly with latest repo copies of scripts/skin.

Thanks and Hope this finds you well!

Mario

mgonzales71 commented 7 years ago

Ok, I changed log_msg to use LOGNOTICE (instead of debug) and added several checks with log entries

I think I have narrowed down the problem to something that is keeping the zip file from being copied out of temp (race condition? also of note the most of the failures are at startup... kodi / system too busy?)

Anyway I think if you add a check to see if the temp.zip actually is copied and exists or not before cleanup that would help.

Something like if the copied zip does not exist at the expected destination maybe enter a delay with up to 3 retries to get it to copy before you throw an exception and log the error?

From what I am seeing is the temp dir always gets created. files always copied to the dir. and then the temp zip always get created but then that zip getting out of temp alive does not always happen.

I can't find the reason for it not... but hope that a check will help overcome that 😀

Just had a thought.... to avoid trying to do the backup at the usually pretty busy system at startup maybe consider adding a startup delay (or add a setting option) for the daily auto backup script run in addition to the check (and retry/delay) of a successful copy of temp_zip to the backup_dest. ?

Thanks again Marcel!

Have a great day - Mario

mgonzales71 commented 7 years ago

Hey Marcel,

Just wanted to follow up with you about this issue after the latest update you pushed.

Automatic backup is still doing the following:

As a test I used the add on Kodi Callbacks to run the python script below as a startup task and it works every time without fail.

I did notice the skinbackup script actually does the auto backup and "manual" backup with separate code and since I am not the best python script writer I wasn't sure if I was following your code right or not so wasn't able to catch anything obvious that was causing the difference.

import sys
import os
import xbmc
import xbmcgui
import xbmcaddon
import xbmcvfs
import unicodedata
import time
from datetime import datetime

SKIN_NAME = xbmc.getSkinDir().decode("utf-8").replace("skin.", "").replace(".kryptonbeta","").replace(".jarvisbeta","")

DEFAULT_IMG = xbmc.translatePath( os.path.join( "special://home/", "media", "skin-backup.png" ) )

BACKUP_FILE = xbmc.translatePath( os.path.join( "special://home/backups/"+SKIN_NAME.capitalize()+" SkinBackup ("+datetime.now().strftime('%Y-%m-%d %H.%M.%S')+").zip" ) )

time.sleep(60)

xbmc.executebuiltin("Notification(KODI CALLBACK:,Backing Up Skin Settings...,8000,"+DEFAULT_IMG+")")

xbmc.executebuiltin("RunScript(script.skin.helper.skinbackup,action=backup,silent="+BACKUP_FILE+")")
marcelveldt commented 7 years ago

Hi Mario can you test this again with the latest version ?

mgonzales71 commented 7 years ago

Sure thing. I had noticed the previous changes finally was creating backups without deleting the temp files before they could be moved but was not cleaning up old backups based on the setting. I will test the latest in a bit and let you know.

mgonzales71 commented 7 years ago

backups working fine now - but cleaning up old backups not working: