def restore(self, filename="", silent=False):
        '''restore skin settings from file'''

        if not filename:
            filename = self.get_restorefilename()

        #skip if filename is not a zip file
        if not filename.endswith("zip"):
            return

        progressdialog = None
        if not silent:
            progressdialog = xbmcgui.DialogProgress(
                self.addon.getLocalizedString(32006))
            progressdialog.create(self.addon.getLocalizedString(32007))

        if filename and xbmcvfs.exists(filename):
            # create temp path
            temp_path = self.create_temp()
            if not filename.endswith("zip"):
                # assume that passed filename is actually a skinsettings file
                skinsettingsfile = filename
            else:
                # copy zip to temp directory and unzip
                skinsettingsfile = temp_path + "guisettings.txt"
                if progressdialog:
                    progressdialog.update(0, "unpacking backup...")
                zip_temp = try_encode(
                    '%sskinbackup-%s.zip' %
                    (ADDON_DATA, datetime.now().strftime('%Y-%m-%d-%H-%M')))
                copy_file(filename, zip_temp, True)
                unzip_fromfile(zip_temp, temp_path)
                delete_file(zip_temp)
                # copy skinshortcuts preferences
                self.restore_skinshortcuts(temp_path)
                # restore any custom skin images or themes
                for directory in ["custom_images/", "themes/"]:
                    custom_images_folder = try_encode(
                        "special://profile/addon_data/%s/%s" %
                        (xbmc.getSkinDir(), directory))
                    custom_images_folder_temp = temp_path + directory
                    if xbmcvfs.exists(custom_images_folder_temp):
                        for file in xbmcvfs.listdir(
                                custom_images_folder_temp)[1]:
                            xbmcvfs.copy(custom_images_folder_temp + file,
                                         custom_images_folder + file)
            # restore guisettings
            if xbmcvfs.exists(skinsettingsfile):
                self.restore_guisettings(skinsettingsfile, progressdialog)

            # cleanup temp
            recursive_delete_dir(temp_path)
            progressdialog.close()
        if not silent:
            xbmcgui.Dialog().ok(self.addon.getLocalizedString(32006),
                                self.addon.getLocalizedString(32009))
예제 #2
0
 def clean_oldbackups(self):
     backuppath = self.addon.getSetting("backup_path")
     max_backups = self.addon.getSetting("max_old_backups")
     if max_backups:
         max_backups = int(max_backups)
         all_files = []
         for filename in xbmcvfs.listdir(backuppath)[1]:
             if ".zip" in filename and "Skinbackup" in filename:
                 filename = filename
                 filepath = backuppath + filename
                 filestat = xbmcvfs.Stat(filepath)
                 modified = filestat.st_mtime()
                 del filestat
                 log_msg(modified)
                 all_files.append((filepath, modified))
         if len(all_files) > max_backups:
             from operator import itemgetter
             old_files = sorted(all_files, key=itemgetter(1), reverse=True)[max_backups - 1:]
             for backupfile in old_files:
                 delete_file(backupfile[0])