def backup_skinshortcuts_properties(propertiesfile, dest_path):
     '''parse skinshortcuts properties file and translate images'''
     # look for any backgrounds and translate them
     propfile = xbmcvfs.File(propertiesfile)
     data = propfile.read()
     propfile.close()
     allprops = eval(data) if data else []
     for count, prop in enumerate(allprops):
         if prop[2] == "background":
             background = prop[3] if prop[3] else ""
             defaultid = prop[1]
             if background.endswith(".jpg") or background.endswith(
                     ".png") or background.endswith(".gif"):
                 background = get_clean_image(background)
                 extension = background.split(".")[-1]
                 newthumb = os.path.join(
                     dest_path, "%s-background-%s.%s" %
                     (xbmc.getSkinDir(), normalize_string(defaultid),
                      extension))
                 newthumb_vfs = "special://profile/addon_data/script.skinshortcuts/%s-background-%s.%s" % (
                     xbmc.getSkinDir(), normalize_string(defaultid),
                     extension)
                 if xbmcvfs.exists(background):
                     copy_file(background, newthumb)
                     allprops[count] = [
                         prop[0], prop[1], prop[2], newthumb_vfs
                     ]
     # write updated properties file
     propfile = xbmcvfs.File(propertiesfile, "w")
     propfile.write(repr(allprops))
     propfile.close()
Ejemplo n.º 2
0
 def backup_skinshortcuts_images(shortcutfile, dest_path):
     shortcutfile = xbmcvfs.translatePath(shortcutfile)
     doc = parse(shortcutfile)
     listing = doc.documentElement.getElementsByTagName('shortcut')
     for shortcut in listing:
         defaultid = shortcut.getElementsByTagName('defaultID')
         if defaultid:
             defaultid = defaultid[0].firstChild
             if defaultid:
                 defaultid = defaultid.data
             if not defaultid:
                 defaultid = shortcut.getElementsByTagName('label')[0].firstChild.data
             thumb = shortcut.getElementsByTagName('thumb')
             if thumb:
                 thumb = thumb[0].firstChild
                 if thumb:
                     thumb = thumb.data
                     if thumb and (thumb.endswith(".jpg") or thumb.endswith(".png") or thumb.endswith(".gif")):
                         thumb = get_clean_image(thumb)
                         extension = thumb.split(".")[-1]
                         newthumb = os.path.join(dest_path, "%s-thumb-%s.%s" %
                                                 (xbmc.getSkinDir(), normalize_string(defaultid), extension))
                         newthumb_vfs = "special://profile/addon_data/script.skinshortcuts/%s-thumb-%s.%s" % (
                             xbmc.getSkinDir(), normalize_string(defaultid), extension)
                         if xbmcvfs.exists(thumb):
                             copy_file(thumb, newthumb)
                             shortcut.getElementsByTagName('thumb')[0].firstChild.data = newthumb_vfs
     # write changes to skinshortcuts file
     shortcuts_file = xbmcvfs.File(shortcutfile, "w")
     shortcuts_file.write(doc.toxml(encoding='utf-8'))
     shortcuts_file.close()
    def backup_skinshortcuts(self, dest_path):
        '''backup skinshortcuts including images'''
        source_path = try_encode(
            'special://profile/addon_data/script.skinshortcuts/')
        if not xbmcvfs.exists(dest_path):
            xbmcvfs.mkdir(dest_path)
        for file in xbmcvfs.listdir(source_path)[1]:
            file = file
            sourcefile = source_path + file
            destfile = dest_path + file
            if xbmc.getCondVisibility(
                    "SubString(Skin.String(skinshortcuts-sharedmenu),false)"):
                # User is not sharing menu, so strip the skin name out of the destination file
                destfile = destfile.replace("%s." % (xbmc.getSkinDir()), "")
            if (file.endswith(".DATA.xml") and
                (not xbmc.getCondVisibility(
                    "SubString(Skin.String(skinshortcuts-sharedmenu),false)")
                 or file.startswith(xbmc.getSkinDir()))):
                xbmcvfs.copy(sourcefile, destfile)
                # parse shortcuts file and look for any images - if found copy them to addon folder
                self.backup_skinshortcuts_images(destfile, dest_path)

            elif file.endswith(".properties") and xbmc.getSkinDir() in file:
                if xbmc.getSkinDir() in file:
                    destfile = dest_path + file.replace(
                        xbmc.getSkinDir(), "SKINPROPERTIES")
                    copy_file(sourcefile, destfile)
                    self.backup_skinshortcuts_properties(destfile, dest_path)
            else:
                # just copy the remaining files
                copy_file(sourcefile, destfile)
    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))
    def backup(self, filters=None, backup_file="", silent=False):
        '''create skin backup'''
        if not filters:
            filters = []

        if not backup_file:
            return

        # create temp path
        temp_path = self.create_temp()
        zip_temp = try_encode(
            '%sskinbackup-%s.zip' %
            (temp_path, datetime.now().strftime('%Y-%m-%d %H.%M')))
        temp_path = temp_path + "skinbackup/"

        # backup skinshortcuts preferences
        if not filters or (filters and "skinshortcuts" in filters):
            self.backup_skinshortcuts(temp_path + "skinshortcuts/")

        # backup skin settings
        if "skinshortcutsonly" not in filters:
            skinsettings_path = os.path.join(temp_path,
                                             try_encode("guisettings.txt"))
            self.backup_skinsettings(skinsettings_path, filters, temp_path)

        # zip the backup
        if sys.version_info.major == 3:
            zip_temp = try_decode(xbmcvfs.translatePath(zip_temp))
        else:
            zip_temp = try_decode(xbmc.translatePath(zip_temp))
        zip_tofile(temp_path, zip_temp)

        # copy file to destination - wait until it's really copied
        xbmc.log("Skin Helper Backup --> Saving Backup to %s" % backup_file,
                 level=xbmc.LOGINFO)
        copy_file(zip_temp, backup_file, True)
        if not xbmcvfs.exists(backup_file):
            if not silent:
                raise IOError('Failed to copy ' + zip_temp + " to " +
                              backup_file)

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

        # clean old backups
        self.clean_oldbackups()
        self.create_temp()

        # show success message
        if not silent:
            xbmcgui.Dialog().ok(self.addon.getLocalizedString(32004),
                                self.addon.getLocalizedString(32005))
Ejemplo n.º 6
0
 def restore_skinshortcuts(temp_path):
     source_path = temp_path + "skinshortcuts/"
     if xbmcvfs.exists(source_path):
         dest_path = u'special://profile/addon_data/script.skinshortcuts/'
         for filename in xbmcvfs.listdir(source_path)[1]:
             filename = filename
             sourcefile = source_path + filename
             destfile = dest_path + filename
             if filename == "SKINPROPERTIES.properties":
                 destfile = dest_path + filename.replace("SKINPROPERTIES", xbmc.getSkinDir())
             elif xbmc.getCondVisibility("SubString(Skin.String(skinshortcuts-sharedmenu),false)"):
                 destfile = "%s-" % (xbmc.getSkinDir())
             copy_file(sourcefile, destfile)
Ejemplo n.º 7
0
 def backup_skinsettings(self, dest_file, filters, temp_path):
     # save guisettings
     skinfile = xbmcvfs.File(dest_file, "w")
     skinsettings = self.get_skinsettings(filters)
     skinfile.write(repr(skinsettings))
     skinfile.close()
     # copy any custom skin images or themes
     for item in ["custom_images/", "themes/"]:
         custom_images_folder = "special://profile/addon_data/%s/%s" % (xbmc.getSkinDir(), item)
         if xbmcvfs.exists(custom_images_folder):
             custom_images_folder_temp = os.path.join(temp_path, item)
             for file in xbmcvfs.listdir(custom_images_folder)[1]:
                 source = os.path.join(custom_images_folder, file)
                 dest = os.path.join(custom_images_folder_temp, file)
                 copy_file(source, dest)
    def backup(self, filters=None, backup_file="", silent=False):
        '''create skin backup'''
        if not filters:
            filters = []

        if not backup_file:
            return

        # create temp path
        temp_path = self.create_temp()
        zip_temp = '%s/skinbackup-%s.zip' % (
            temp_path, datetime.now().strftime('%Y-%m-%d %H.%M'))
        temp_path = temp_path + "skinbackup/"

        # backup skinshortcuts preferences
        if not filters or (filters and "skinshortcuts" in filters):
            self.backup_skinshortcuts(temp_path + "skinshortcuts/")

        # backup skin settings
        if "skinshortcutsonly" not in filters:
            skinsettings_path = os.path.join(temp_path, "guisettings.txt")
            self.backup_skinsettings(skinsettings_path, filters, temp_path)

        # zip the backup
        zip_temp = xbmcvfs.translatePath(zip_temp)
        zip_tofile(temp_path, zip_temp)

        # copy file to destination - wait untill it's really copied
        copy_file(zip_temp, backup_file, True)

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

        # show success message
        if not silent:
            xbmcgui.Dialog().ok(self.addon.getLocalizedString(32004),
                                self.addon.getLocalizedString(32005))