Beispiel #1
0
def choose_file_manager():
    if not xbmc.getCondVisibility('System.HasAddon(script.kodi.android.update)'):
        from resources.libs.gui import addon_menu
        addon_menu.install_from_kodi('script.kodi.android.update')
    
    try:
        updater = xbmcaddon.Addon('script.kodi.android.update')
    except RuntimeError as e:
        return False
        
    updater.setSetting('File_Manager', '1')
    
    CONFIG.open_settings('script.kodi.android.update', 0, 4, True)
Beispiel #2
0
    def dispatch(self, handle, paramstring):
        self._log_params(paramstring)

        mode = self.params['mode'] if 'mode' in self.params else None
        url = self.params['url'] if 'url' in self.params else None
        name = self.params['name'] if 'name' in self.params else None
        action = self.params['action'] if 'action' in self.params else None

        # MAIN MENU
        if mode is None:
            from resources.libs.gui.main_menu import MainMenu
            MainMenu().get_listing()
            self._finish(handle)

        # SETTINGS
        elif mode == 'settings':  # OpenWizard settings
            CONFIG.open_settings(name)
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'opensettings':  # Open other addons' settings
            settings_id = eval(url.upper() + 'ID')[name]['plugin']
            CONFIG.open_settings(settings_id)
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'togglesetting':  # Toggle a setting
            CONFIG.set_setting(name, 'false' if CONFIG.get_setting(name) == 'true' else 'true')
            xbmc.executebuiltin('Container.Refresh()')

        # MENU SECTIONS
        elif mode == 'builds':  # Builds
            from resources.libs.gui.build_menu import BuildMenu
            BuildMenu().get_listing()
            self._finish(handle)
        elif mode == 'viewbuild':  # Builds -> "Your Build"
            from resources.libs.gui.build_menu import BuildMenu
            BuildMenu().view_build(name)
            self._finish(handle)
        elif mode == 'buildinfo':  # Builds -> Build Info
            from resources.libs.gui.build_menu import BuildMenu
            BuildMenu().build_info(name)
        elif mode == 'buildpreview':  # Builds -> Build Preview
            from resources.libs.gui.build_menu import BuildMenu
            BuildMenu().build_video(name)
        elif mode == 'install':  # Builds -> Fresh Install/Standard Install/Apply guifix
            from resources.libs.wizard import Wizard

            if action == 'build':
                Wizard().build(name)
            elif action == 'gui':
                Wizard().gui(name)
            elif action == 'theme':  # Builds -> "Your Build" -> "Your Theme"
                Wizard().theme(name, url)

        elif mode == 'maint':  # Maintenance + Maintenance -> any "Tools" section
            from resources.libs.gui.maintenance_menu import MaintenanceMenu

            if name == 'clean':
                MaintenanceMenu().clean_menu()
            elif name == 'addon':
                MaintenanceMenu().addon_menu()
            elif name == 'misc':
                MaintenanceMenu().misc_menu()
            elif name == 'backup':
                MaintenanceMenu().backup_menu()
            elif name == 'tweaks':
                MaintenanceMenu().tweaks_menu()
            elif name == 'logging':
                MaintenanceMenu().logging_menu()
            elif name is None:
                MaintenanceMenu().get_listing()
                
            self._finish(handle)

        elif mode == 'enableaddons':  # Maintenance - > Addon Tools -> Enable/Disable Addons
            menu.enable_addons()
            self._finish(handle)
        elif mode == 'toggleaddon':
            from resources.libs import db
            db.toggle_addon(name, url)
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'forceupdate':
            from resources.libs import db
            db.force_check_updates(auto=action)
        elif mode == 'togglecache':
            from resources.libs import clear
            clear.toggle_cache(name)
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'changefreq':  # Maintenance - Auto Clean Frequency
            menu.change_freq()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'systeminfo':  # Maintenance -> System Tweaks/Fixes -> System Information
            menu.system_info()
            self._finish(handle)
        elif mode == 'nettools':  # Maintenance -> Misc Maintenance -> Network Tools
            menu.net_tools()
            self._finish(handle)
        elif mode == 'runspeedtest':  # Maintenance -> Misc Maintenance -> Network Tools -> Speed Test -> Run Speed Test
            menu.run_speed_test()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'clearspeedtest':  # Maintenance -> Misc Maintenance -> Network Tools -> Speed Test -> Clear Results
            menu.clear_speed_test()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'viewspeedtest':  # Maintenance -> Misc Maintenance -> Network Tools -> Speed Test -> any previous test
            menu.view_speed_test(name)
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'viewIP':  # Maintenance -> Misc Maintenance -> Network Tools -> View IP Address & MAC Address
            menu.view_ip()
            self._finish(handle)
        elif mode == 'speedtest':  # Maintenance -> Misc Maintenance -> Network Tools -> Speed Test
            menu.speed_test()
            self._finish(handle)
        elif mode == 'apk':  # APK Installer
            menu.apk_menu(url)
            self._finish(handle)
        elif mode == 'kodiapk':  # APK Installer -> Official Kodi APK's
            xbmc.executebuiltin('RunScript(script.kodi.android.update)')
        elif mode == 'fmchoose':
            from resources.libs import install
            install.choose_file_manager()
        elif mode == 'apkinstall':
            from resources.libs import install
            install.install_apk(name, url)
        elif mode == 'removeaddondata':  # Maintenance - > Addon Tools -> Remove Addon Data
            menu.remove_addon_data_menu()
            self._finish(handle)
        elif mode == 'savedata':  # Save Data + Builds -> Save Data Menu
            menu.save_menu()
            self._finish(handle)
        elif mode == 'youtube':  # "YouTube Section"
            menu.youtube_menu(url)
            self._finish(handle)
        elif mode == 'viewVideo':  # View  Video
            from resources.libs import yt
            yt.play_video(url)
        elif mode == 'trakt':  # Save Data -> Keep Trakt Data
            menu.trakt_menu()
            self._finish(handle)
        elif mode == 'realdebrid':  # Save Data -> Keep Debrid
            menu.debrid_menu()
            self._finish(handle)
        elif mode == 'login':  # Save Data -> Keep Login Info
            menu.login_menu()
            self._finish(handle)
        elif mode == 'developer':  # Developer  Menu
            menu.developer()
            self._finish(handle)

        # MAINTENANCE FUNCTIONS
        elif mode == 'kodi17fix':  # Misc Maintenance -> Kodi 17 Fix
            from resources.libs import db
            db.kodi_17_fix()
        elif mode == 'unknownsources':  # Misc Maintenance -> Enable Unknown Sources
            from resources.libs import skin
            skin.swap_us()
        elif mode == 'enabledebug':  # Misc Maintenance -> Enable Debug Logging
            logging.swap_debug()
        elif mode == 'toggleupdates':  # Misc Maintenance -> Toggle Addon Updates
            from resources.libs import update
            update.toggle_addon_updates()
        elif mode == 'asciicheck':  # System Tweaks -> Scan for Non-Ascii Files
            from resources.libs.common import tools
            tools.ascii_check()
        elif mode == 'convertpath':  # System Tweaks -> Convert Special Paths
            from resources.libs.common import tools
            tools.convert_special(CONFIG.HOME)
        elif mode == 'forceprofile':  # Misc Maintenance -> Reload Profile
            from resources.libs.common import tools
            tools.reload_profile(tools.get_info_label('System.ProfileName'))
        elif mode == 'forceclose':  # Misc Maintenance -> Force Close Kodi
            from resources.libs.common import tools
            tools.kill_kodi()
        elif mode == 'forceskin':  # Misc Maintenance -> Reload Skin
            xbmc.executebuiltin("ReloadSkin()")
            xbmc.executebuiltin('Container.Refresh()')
        # elif mode == 'hidepassword':  # Addon Tools -> Hide Passwords on Keyboard Entry
        #     from resources.libs import db
        #     db.hide_password()
        # elif mode == 'unhidepassword':  # Addon Tools -> Unhide Passwords on Keyboard Entry
        #     from resources.libs import db
        #     db.unhide_password()
        elif mode == 'checksources':  # System Tweaks -> Scan source for broken links
            from resources.libs import check
            check.check_sources()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'checkrepos':  # System Tweaks -> Scan for broken repositories
            from resources.libs import check
            check.check_repos()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'whitelist':  # Whitelist Functions
            from resources.libs import whitelist
            whitelist.whitelist(name)

        #  CLEANING
        elif mode == 'oldThumbs':  # Cleaning Tools -> Clear Old Thumbnails
            from resources.libs import clear
            clear.old_thumbs()
        elif mode == 'clearbackup':  # Backup/Restore -> Clean Up Back Up Folder
            from resources.libs import backup
            backup.cleanup_backup()
        elif mode == 'fullclean':  # Cleaning Tools -> Total Cleanup
            from resources.libs import clear
            clear.total_clean()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'clearcache':  # Cleaning Tools -> Clear Cache
            from resources.libs import clear
            clear.clear_cache()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'clearfunctioncache':  # Cleaning Tools -> Clear Function Caches
            from resources.libs import clear
            clear.clear_function_cache()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'clearpackages':  # Cleaning Tools -> Clear Packages
            from resources.libs import clear
            clear.clear_packages()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'clearcrash':  # Cleaning Tools -> Clear Crash Logs
            from resources.libs import clear
            clear.clear_crash()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'clearthumb':  # Cleaning Tools -> Clear Thumbnails
            from resources.libs import clear
            clear.clear_thumbs()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'cleararchive':  # Cleaning Tools -> Clear Archive Cache
            from resources.libs import clear
            clear.clear_archive()
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'freshstart':  # Cleaning Tools -> Fresh Start
            from resources.libs import install
            install.fresh_start()
        elif mode == 'purgedb':  # Cleaning Tools -> Purge Databases
            from resources.libs import db
            db.purge_db()
        elif mode == 'removeaddons':  # Addon Tools -> Remove Addons
            from resources.libs import clear
            clear.remove_addon_menu()
        elif mode == 'removedata':  # Addon Tools -> Remove Addon Data
            from resources.libs import clear
            clear.remove_addon_data(name)
        elif mode == 'resetaddon':  # Addon Tools -> Remove Addon Data -> Remove  Wizard Addon Data
            from resources.libs.common import tools

            tools.clean_house(CONFIG.ADDON_DATA, ignore=True)
            logging.log_notify("[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, CONFIG.ADDONTITLE),
                               "[COLOR {0}]Addon_Data reset[/COLOR]".format(CONFIG.COLOR2))
        # BACKUP / RESTORE
        elif mode == 'backup' and action:
            from resources.libs import backup
            backup.backup(action)
        elif mode == 'restore' and action:
            from resources.libs import restore
            restore.restore(action, external=name == 'external')

        elif mode == 'wizardupdate':  # Wizard Update
            from resources.libs import update
            update.wizard_update()

        # LOGGING
        elif mode == 'uploadlog':  # Upload Log File
            logging.upload_log()
        elif mode == 'viewlog':  # View kodi.log
            logging.view_log_file()
        elif mode == 'viewwizlog':  # View wizard.log
            from resources.libs.gui import window
            window.show_log_viewer(log_file=CONFIG.WIZLOG)
        elif mode == 'viewerrorlog':  # View errors in log
            logging.error_checking()
        elif mode == 'viewerrorlast':  # View last error in log
            logging.error_checking(last=True)
        elif mode == 'clearwizlog':  # Clear wizard.log
            from resources.libs.common import tools
            tools.remove_file(CONFIG.WIZLOG)
            logging.log_notify("[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, CONFIG.ADDONTITLE),
                               "[COLOR {0}]Wizard Log Cleared![/COLOR]".format(CONFIG.COLOR2))

        # ADVANCED SETTINGS
        elif mode == advanced_settings_mode:
            from resources.libs import advanced

            self.route = advanced.AdvancedMenu()
            advanced_settings_actions = ['quick_configure', 'view_current', 'remove_current', 'write_advanced', 'set_setting', 'show_section']

            category = self.params['category'] if 'category' in self.params else None
            tag = self.params['tag'] if 'tag' in self.params else None
            value = self.params['value'] if 'value' in self.params else None
            tags = self.params['tags'] if 'tags' in self.params else None

            if not action:
                self.route.show_menu(url=url)
                self._finish(handle)
            elif action == advanced_settings_actions[0]:  # Advanced Settings Quick Configure
                self.route.quick_configure()
                self._finish(handle)
            elif action == advanced_settings_actions[1]:  # View Current Advanced Settings
                advanced.view_current()
            elif action == advanced_settings_actions[2]:  # Remove Current Advanced Settings
                advanced.remove_current()
            elif action == advanced_settings_actions[3] and url:  # Write New Advanced Settings
                self.route.write_advanced(name, url)
            elif action == advanced_settings_actions[4]:  # Set a Setting
                self.route.set_setting(category, tag, value)
            elif action == advanced_settings_actions[5]:  # Open a Section
                self.route.show_section(tags)
                self._finish(handle)
                
        # ADDON INSTALLER
        elif mode == addon_installer_mode:
            from resources.libs.gui import addon_menu
            
            self.route = addon_menu.AddonMenu()
            addon_installer_actions = ['addon', 'skin', 'addonpack']

            addonurl = self.params['addonurl'] if 'addonurl' in self.params else None
            repository = self.params['repository'] if 'repository' in self.params else None
            repositoryurl = self.params['repositoryurl'] if 'repositoryurl' in self.params else None
            repositoryxml = self.params['repositoryxml'] if 'repositoryxml' in self.params else None
            urls = [addonurl, repository, repositoryurl, repositoryxml]
            
            if not action:
                self.route.show_menu(url=url)
                self._finish(handle)
            elif action == addon_installer_actions[0]:
                self.route.install_addon(name, urls)
            elif action == addon_installer_actions[1]:
                pass
                # self.route.install_skin(name, url)
            elif action == addon_installer_actions[2]:
                pass
                # self.route.install_addon_pack(name, url)
            
        # SAVE DATA
        elif mode == 'managedata':
            from resources.libs import save

            if name == 'import':
                save.import_save_data()
            elif name == 'export':
                save.export_save_data()

        # TRAKT
        elif mode == 'savetrakt':  # Save Trakt Data
            from resources.libs import traktit
            traktit.trakt_it('update', name)
        elif mode == 'restoretrakt':  # Recover All Saved Trakt Data
            from resources.libs import traktit
            traktit.trakt_it('restore', name)
        elif mode == 'addontrakt':  # Clear All Addon Trakt Data
            from resources.libs import traktit
            traktit.trakt_it('clearaddon', name)
        elif mode == 'cleartrakt':  # Clear All Saved Trakt Data
            from resources.libs import traktit
            traktit.clear_saved(name)
        elif mode == 'authtrakt':  # Authorize Trakt
            from resources.libs import traktit
            traktit.activate_trakt(name)
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'updatetrakt':  # Update Saved Trakt Data
            from resources.libs import traktit
            traktit.auto_update('all')
        elif mode == 'importtrakt':  # Import Saved Trakt Data
            from resources.libs import traktit
            traktit.import_list(name)
            xbmc.executebuiltin('Container.Refresh()')

        # DEBRID
        elif mode == 'savedebrid':  # Save Debrid Data
            from resources.libs import debridit
            debridit.debrid_it('update', name)
        elif mode == 'restoredebrid':  # Recover All Saved Debrid Data
            from resources.libs import debridit
            debridit.debrid_it('restore', name)
        elif mode == 'addondebrid':  # Clear All Addon Debrid Data
            from resources.libs import debridit
            debridit.debrid_it('clearaddon', name)
        elif mode == 'cleardebrid':  # Clear All Saved Debrid Data
            from resources.libs import debridit
            debridit.clear_saved(name)
        elif mode == 'authdebrid':  # Authorize Debrid
            from resources.libs import debridit
            debridit.activate_debrid(name)
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'updatedebrid':  # Update Saved Debrid Data
            from resources.libs import debridit
            debridit.auto_update('all')
        elif mode == 'importdebrid':  # Import Saved Debrid Data
            from resources.libs import debridit
            debridit.import_list(name)
            xbmc.executebuiltin('Container.Refresh()')

        # LOGIN
        elif mode == 'savelogin':  # Save Login Data
            from resources.libs import loginit
            loginit.login_it('update', name)
        elif mode == 'restorelogin':  # Recover All Saved Login Data
            from resources.libs import loginit
            loginit.login_it('restore', name)
        elif mode == 'addonlogin':  # Clear All Addon Login Data
            from resources.libs import loginit
            loginit.login_it('clearaddon', name)
        elif mode == 'clearlogin':  # Clear All Saved Login Data
            from resources.libs import loginit
            loginit.clear_saved(name)
        elif mode == 'authlogin':  # "Authorize" Login
            from resources.libs import loginit
            loginit.activate_login(name)
            xbmc.executebuiltin('Container.Refresh()')
        elif mode == 'updatelogin':  # Update Saved Login Data
            from resources.libs import loginit
            loginit.auto_update('all')
        elif mode == 'importlogin':  # Import Saved Login Data
            from resources.libs import loginit
            loginit.import_list(name)
            xbmc.executebuiltin('Container.Refresh()')

        # DEVELOPER MENU
        elif mode == 'createqr':  # Developer Menu -> Create QR Code
            from resources.libs import qr
            qr.create_code()
        elif mode == 'testnotify':  # Developer Menu -> Test Notify
            from resources.libs import test
            test.test_notify()
        elif mode == 'testupdate':  # Developer Menu -> Test Update
            from resources.libs import test
            test.test_update()
        elif mode == 'testsavedata':  # Developer Menu -> Test Save Data Settings
            from resources.libs import test
            test.test_save_data_settings()
        elif mode == 'testbuildprompt':  # Developer Menu -> Test Build Prompt
            from resources.libs import test
            test.test_first_run()
        elif mode == 'binarycheck':
            from resources.libs import db
            db.find_binary_addons()
        elif mode == 'contact':  # Contact
            from resources.libs.gui import window
            window.show_contact(CONFIG.CONTACT)
Beispiel #3
0
def _backup_addon_data(name=""):
    dialog = xbmcgui.Dialog()
    progress_dialog = xbmcgui.DialogProgress()

    if dialog.yesno(CONFIG.ADDONTITLE, "[COLOR {0}]Are you sure you wish to backup the current addon_data?[/COLOR]".format(CONFIG.COLOR2),
                    nolabel="[B][COLOR red]Cancel Backup[/COLOR][/B]",
                    yeslabel="[B][COLOR springgreen]Backup Addon_Data[/COLOR][/B]"):
        if name == "":
            name = tools.get_keyboard("", "Please enter a name for the addon_data zip")
            if not name:
                return False
            name = quote_plus(name)
        name = '{0}_addondata.zip'.format(name)
        tempzipname = ''
        zipname = os.path.join(CONFIG.MYBUILDS, name)
        try:
            zipf = zipfile.ZipFile(xbmc.translatePath(zipname), mode='w')
        except:
            try:
                tempzipname = os.path.join(CONFIG.PACKAGES, '{0}.zip'.format(name))
                zipf = zipfile.ZipFile(tempzipname, mode='w')
            except:
                logging.log("Unable to create {0}_addondata.zip".format(name), level=xbmc.LOGERROR)
                if dialog.yesno(CONFIG.ADDONTITLE,
                                "[COLOR {0}]We are unable to write to the current backup directory, would you like to change the location?[/COLOR]".format(CONFIG.COLOR2),
                                yeslabel="[B][COLOR springgreen]Change Directory[/COLOR][/B]",
                                nolabel="[B][COLOR red]Cancel[/COLOR][/B]"):
                    CONFIG.open_settings()
                    return
                else:
                    return
        for_progress = 0
        ITEM = []
        tools.convert_special(CONFIG.ADDON_DATA, True)
        tools.ascii_check(CONFIG.ADDON_DATA, True)
        progress_dialog.create("[COLOR {0}]{1}[/COLOR][COLOR {2}]: Creating Zip[/COLOR]".format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                  "[COLOR {0}]Creating back up zip".format(CONFIG.COLOR2), "", "Please Wait...[/COLOR]")
        for base, dirs, files in os.walk(CONFIG.ADDON_DATA):
            dirs[:] = [d for d in dirs if d not in CONFIG.EXCLUDE_DIRS]
            files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
            for file in files:
                ITEM.append(file)
        N_ITEM = len(ITEM)

        bad_files = [
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.exodusredux', 'cache.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.exodusredux', 'cache.meta.5.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.exodusredux', 'cache.providers.13.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.thecrew', 'cache.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.thecrew', 'cache.meta.5.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.thecrew', 'cache.providers.13.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.yoda', 'cache.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.yoda', 'cache.meta.5.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.yoda', 'cache.providers.13.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.scrubsv2', 'cache.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.scrubsv2', 'cache.meta.5.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.scrubsv2', 'cache.providers.13.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.gaia', 'cache.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.gaia', 'meta.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.seren', 'cache.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'plugin.video.seren', 'torrentScrape.db')),
            (os.path.join(CONFIG.ADDON_DATA, 'script.module.simplecache', 'simplecache.db'))]

        for base, dirs, files in os.walk(CONFIG.ADDON_DATA):
            dirs[:] = [d for d in dirs if d not in CONFIG.EXCLUDE_DIRS]
            files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
            for file in files:
                try:
                    for_progress += 1
                    progress = tools.percentage(for_progress, N_ITEM)
                    progress_dialog.update(int(progress),
                              '[COLOR {0}]Creating back up zip: [COLOR{1}]{2}[/COLOR] / [COLOR{3}]{4}[/COLOR]'.format(
                              CONFIG.COLOR2, CONFIG.COLOR1, for_progress, CONFIG.COLOR1, N_ITEM),
                                  '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1, file),
                              '')
                    fn = os.path.join(base, file)
                    if file in CONFIG.LOGFILES:
                        logging.log("[Back Up] Type = addon_data: Ignore {0} - Log Files".format(file))
                        continue
                    elif os.path.join(base, file) in bad_files:
                        logging.log("[Back Up] Type = addon_data: Ignore {0} - Cache Files".format(file))
                        continue
                    elif os.path.join('addons', 'packages') in fn:
                        logging.log("[Back Up] Type = addon_data: Ignore {0} - Packages Folder".format(file))
                        continue
                    elif file.endswith('.csv'):
                        logging.log("[Back Up] Type = addon_data: Ignore {0} - CSV File".format(file))
                        continue
                    elif file.endswith('.db') and 'Database' in base:
                        temp = file.replace('.db', '')
                        temp = ''.join([i for i in temp if not i.isdigit()])
                        if temp in CONFIG.DB_FILES:
                            if not file == db.latest_db(temp):
                                logging.log("[Back Up] Type = addon_data: Ignore {0} - Database Files".format(file))
                                continue
                    try:
                        zipf.write(fn, fn[len(CONFIG.ADDON_DATA):], zipfile.ZIP_DEFLATED)
                    except Exception as e:
                        logging.log("[Back Up] Type = addon_data: Unable to backup {0}".format(file))
                        logging.log("Backup Error: {0}".format(str(e)))
                except Exception as e:
                    logging.log("[Back Up] Type = addon_data: Unable to backup {0}".format(file))
                    logging.log("Backup Error: {0}".format(str(e)))
        zipf.close()
        if not tempzipname == '':
            success = xbmcvfs.rename(tempzipname, zipname)
            if success == 0:
                xbmcvfs.copy(tempzipname, zipname)
                xbmcvfs.delete(tempzipname)
        progress_dialog.close()
        dialog.ok(CONFIG.ADDONTITLE, "[COLOR {0}]{1}[/COLOR] [COLOR {2}]backup successful:[/COLOR]".format(CONFIG.COLOR1, name, CONFIG.COLOR2),
                  "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, zipname))
Beispiel #4
0
def _backup_theme(name=""):
    dialog = xbmcgui.Dialog()

    if not dialog.yesno('[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                        "[COLOR {0}]Would you like to create a theme backup?[/COLOR]".format(CONFIG.COLOR2),
                        yeslabel="[B][COLOR springgreen]Continue[/COLOR][/B]",
                        nolabel="[B][COLOR red]No Cancel[/COLOR][/B]"):
        logging.log_notify("Theme Backup", "Cancelled!")
        return False
    if name == "":
        themename = tools.get_keyboard("", "Please enter a name for the theme zip")
        if not themename:
            return False
    else:
        themename = name
    themename = quote_plus(themename)
    tempzipname = ''
    zipname = os.path.join(CONFIG.MYBUILDS, '{0}.zip'.format(themename))
    try:
        zipf = zipfile.ZipFile(zipname, mode='w')
    except:
        try:
            tempzipname = os.path.join(CONFIG.PACKAGES, '{0}.zip'.format(themename))
            zipf = zipfile.ZipFile(tempzipname, mode='w')
        except:
            logging.log("Unable to create {0}.zip".format(themename), level=xbmc.LOGERROR)
            if dialog.yesno(CONFIG.ADDONTITLE,
                            "[COLOR {0}]We are unable to write to the current backup directory, would you like to change the location?[/COLOR]".format(CONFIG.COLOR2),
                            yeslabel="[B][COLOR springgreen]Change Directory[/COLOR][/B]",
                            nolabel="[B][COLOR red]Cancel[/COLOR][/B]"):
                CONFIG.open_settings()
                return
            else:
                return
    tools.convert_special(CONFIG.USERDATA, True)
    tools.ascii_check(CONFIG.USERDATA, True)
    try:
        if not CONFIG.SKIN not in ['skin.confluence', 'skin.estuary', 'skin.estouchy']:
            skinfold = os.path.join(CONFIG.SKIN, 'media')
            match2 = glob.glob(os.path.join(skinfold, '*.xbt'))
            if len(match2) > 1:
                if dialog.yesno('[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                                "[COLOR {0}]Would you like to go through the Texture Files for?[/COLOR]".format(CONFIG.COLOR2),
                                "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, CONFIG.SKIN),
                                yeslabel="[B][COLOR springgreen]Add Textures[/COLOR][/B]",
                                nolabel="[B][COLOR red]Skip Textures[/COLOR][/B]"):
                    for xbt in match2:
                        if dialog.yesno(
                                '[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                                "[COLOR {0}]Would you like to add the Texture File [COLOR {1}]{2}[/COLOR]?".format(
                                CONFIG.COLOR1, CONFIG.COLOR2, xbt.replace(skinfold, "")[1:]),
                                "from [COLOR {0}]{1}[/COLOR][/COLOR]".format(CONFIG.COLOR1, CONFIG.SKIN),
                                yeslabel="[B][COLOR springgreen]Add Textures[/COLOR][/B]",
                                nolabel="[B][COLOR red]Skip Textures[/COLOR][/B]"):
                            fn = xbt
                            fn2 = fn.replace(CONFIG.HOME, "")
                            zipf.write(fn, fn2, zipfile.ZIP_DEFLATED)
            else:
                for xbt in match2:
                    if dialog.yesno(
                            '[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                            "[COLOR {0}]Would you like to add the Texture File [COLOR {1}]{2}[/COLOR]?".format(
                            CONFIG.COLOR2, CONFIG.COLOR1, xbt.replace(skinfold, "")[1:]),
                            "from [COLOR {0}]{1}[/COLOR][/COLOR]".format(CONFIG.COLOR1, CONFIG.SKIN),
                            yeslabel="[B][COLOR springgreen]Add Textures[/COLOR][/B]",
                            nolabel="[B][COLOR red]Skip Textures[/COLOR][/B]"):
                        fn = xbt
                        fn2 = fn.replace(CONFIG.HOME, "")
                        zipf.write(fn, fn2, zipfile.ZIP_DEFLATED)
            ad_skin = os.path.join(CONFIG.ADDON_DATA, CONFIG.SKIN, 'settings.xml')
            if os.path.exists(ad_skin):
                if dialog.yesno('[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                                "[COLOR {0}]Would you like to go add the [COLOR {1}]settings.xml[/COLOR] in [COLOR {2}]/addon_data/[/COLOR] for?".format(
                                CONFIG.COLOR2, CONFIG.COLOR1, CONFIG.COLOR1), "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, CONFIG.SKIN),
                                yeslabel="[B][COLOR springgreen]Add Settings[/COLOR][/B]",
                                nolabel="[B][COLOR red]Skip Settings[/COLOR][/B]"):
                    ad_skin2 = ad_skin.replace(CONFIG.HOME, "")
                    zipf.write(ad_skin, ad_skin2, zipfile.ZIP_DEFLATED)
            match = tools.parse_dom(tools.read_from_file(os.path.join(CONFIG.SKIN, 'addon.xml')), 'import', ret='addon')
            if 'script.skinshortcuts' in match:
                if dialog.yesno('[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                                "[COLOR {0}]Would you like to go add the [COLOR {1}]settings.xml[/COLOR] for [COLOR {2}]script.skinshortcuts[/COLOR]?".format(
                                CONFIG.COLOR2, CONFIG.COLOR1, CONFIG.COLOR1),
                                    yeslabel="[B][COLOR springgreen]Add Settings[/COLOR][/B]",
                                nolabel="[B][COLOR red]Skip Settings[/COLOR][/B]"):
                    for base, dirs, files in os.walk(os.path.join(CONFIG.ADDON_DATA, 'script.skinshortcuts')):
                        files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                        for file in files:
                            fn = os.path.join(base, file)
                            zipf.write(fn, fn[len(CONFIG.HOME):], zipfile.ZIP_DEFLATED)
        if dialog.yesno('[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                        "[COLOR {0}]Would you like to include a [COLOR {1}]Backgrounds[/COLOR] folder?[/COLOR]".format(
                        CONFIG.COLOR2, CONFIG.COLOR1),
                            yeslabel="[B][COLOR springgreen]Yes Include[/COLOR][/B]",
                        nolabel="[B][COLOR red]No Continue[/COLOR][/B]"):
            fn = dialog.browse(0, 'Select location of backgrounds', 'files', '', True, False, CONFIG.HOME, False)
            if not fn == CONFIG.HOME:
                for base, dirs, files in os.walk(fn):
                    dirs[:] = [d for d in dirs if d not in CONFIG.EXCLUDE_DIRS]
                    files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                    for file in files:
                        try:
                            fn2 = os.path.join(base, file)
                            zipf.write(fn2, fn2[len(CONFIG.HOME):], zipfile.ZIP_DEFLATED)
                        except Exception as e:
                            logging.log("[Back Up] Type = theme: Unable to backup {0}".format(file))
                            logging.log("Backup Error: {0}".format(str(e)))
            text = db.latest_db('Textures')
            if dialog.yesno('[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                            "[COLOR {0}]Would you like to include the [COLOR {1}]{2}[/COLOR]?[/COLOR]".format(
                            CONFIG.COLOR2, CONFIG.COLOR1, text),
                                yeslabel="[B][COLOR springgreen]Yes Include[/COLOR][/B]",
                            nolabel="[B][COLOR red]No Continue[/COLOR][/B]"):
                zipf.write(os.path.join(CONFIG.DATABASE, text), '/userdata/Database/{0}'.format(text), zipfile.ZIP_DEFLATED)
        if dialog.yesno('[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                        "[COLOR {0}]Would you like to include any addons?[/COLOR]".format(CONFIG.COLOR2),
                        yeslabel="[B][COLOR springgreen]Yes Include[/COLOR][/B]",
                        nolabel="[B][COLOR red]No Continue[/COLOR][/B]"):
            fold = glob.glob(os.path.join(CONFIG.ADDONS, '*/'))
            addonnames = []
            addonfolds = []
            for folder in sorted(fold, key=lambda x: x):
                foldername = os.path.split(folder[:-1])[1]
                if foldername in CONFIG.EXCLUDES:
                    continue
                elif foldername in CONFIG.DEFAULTPLUGINS:
                    continue
                elif foldername == 'packages':
                    continue
                xml = os.path.join(folder, 'addon.xml')
                if os.path.exists(xml):
                    match = tools.parse_dom(tools.read_from_file(xml), 'addon', ret='name')
                    if len(match) > 0:
                        addonnames.append(match[0])
                        addonfolds.append(foldername)
                    else:
                        addonnames.append(foldername)
                        addonfolds.append(foldername)
            selected = dialog.multiselect("{0}: Select the add-ons you wish to add to the zip.".format(CONFIG.ADDONTITLE), addonnames)
            if selected is None:
                selected = []
            if len(selected) > 0:
                added = []
                for item in selected:
                    added.append(addonfolds[item])
                    for base, dirs, files in os.walk(os.path.join(CONFIG.ADDONS, addonfolds[item])):
                        files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                        for file in files:
                            if file.endswith('.pyo'):
                                continue
                            fn = os.path.join(base, file)
                            zipf.write(fn, fn[len(CONFIG.HOME):], zipfile.ZIP_DEFLATED)
                    dep = os.path.join(CONFIG.ADDONS, addonfolds[item], 'addon.xml')
                    if os.path.exists(dep):
                        match = tools.parse_dom(tools.read_from_file(dep), 'import', ret='addon')
                        for depends in match:
                            if 'xbmc.python' in depends:
                                continue
                            if depends in added:
                                continue
                            for base, dirs, files in os.walk(os.path.join(CONFIG.ADDONS, depends)):
                                files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                                for file in files:
                                    if file.endswith('.pyo'):
                                        continue
                                    fn = os.path.join(base, file)
                                    zipf.write(fn, fn[len(CONFIG.HOME):], zipfile.ZIP_DEFLATED)
                                    added.append(depends)
        if dialog.yesno('[COLOR {0}]{1}[/COLOR][COLOR {2}]: Theme Backup[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                        "[COLOR {0}]Would you like to include the [COLOR {1}]guisettings.xml[/COLOR]?[/COLOR]".format(
                        CONFIG.COLOR2, CONFIG.COLOR1),
                            yeslabel="[B][COLOR springgreen]Yes Include[/COLOR][/B]",
                        nolabel="[B][COLOR red]No Continue[/COLOR][/B]"):
            zipf.write(CONFIG.GUISETTINGS, '/userdata/guisettings.xml', zipfile.ZIP_DEFLATED)
    except Exception as e:
        zipf.close()
        logging.log("[Back Up] Type = theme: {0}".format(str(e)))
        dialog.ok(CONFIG.ADDONTITLE, "[COLOR {0}]{1}[/COLOR][COLOR {2}] theme zip failed:[/COLOR]".format(CONFIG.COLOR1, themename, CONFIG.COLOR2),
                  "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, str(e)))
        if not tempzipname == '':
            try:
                os.remove(tempzipname)
            except Exception as e:
                logging.log(str(e))
        else:
            try:
                os.remove(zipname)
            except Exception as e:
                logging.log(str(e))
        return
    zipf.close()
    if not tempzipname == '':
        success = xbmcvfs.rename(tempzipname, zipname)
        if success == 0:
            xbmcvfs.copy(tempzipname, zipname)
            xbmcvfs.delete(tempzipname)
    dialog.ok(CONFIG.ADDONTITLE, "[COLOR {0}]{1}[/COLOR][COLOR {2}] theme zip successful:[/COLOR]".format(CONFIG.COLOR1, themename, CONFIG.COLOR2),
              "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, zipname))
Beispiel #5
0
def _backup_guifix(name=""):
    dialog = xbmcgui.Dialog()

    if name == "":
        guiname = tools.get_keyboard("", "Please enter a name for the GUI Fix zip")
        if not guiname:
            return False
        tools.convert_special(CONFIG.USERDATA, True)
        tools.ascii_check(CONFIG.USERDATA, True)
    else:
        guiname = name
    guiname = quote_plus(guiname)
    tempguizipname = ''
    guizipname = os.path.join(CONFIG.MYBUILDS, '{0}_guisettings.zip'.format(guiname))
    if os.path.exists(CONFIG.GUISETTINGS):
        try:
            zipf = zipfile.ZipFile(guizipname, mode='w')
        except:
            try:
                tempguizipname = os.path.join(CONFIG.PACKAGES, '{0}_guisettings.zip'.format(guiname))
                zipf = zipfile.ZipFile(tempguizipname, mode='w')
            except:
                logging.log("Unable to create {0}_guisettings.zip".format(guiname), level=xbmc.LOGERROR)
                if dialog.yesno(CONFIG.ADDONTITLE,
                                "[COLOR {0}]We are unable to write to the current backup directory, would you like to change the location?[/COLOR]".format(CONFIG.COLOR2),
                                yeslabel="[B][COLOR springgreen]Change Directory[/COLOR][/B]",
                                nolabel="[B][COLOR red]Cancel[/COLOR][/B]"):
                    CONFIG.open_settings()
                    return
                else:
                    return
        try:
            zipf.write(CONFIG.GUISETTINGS, 'guisettings.xml', zipfile.ZIP_DEFLATED)
            zipf.write(CONFIG.PROFILES, 'profiles.xml', zipfile.ZIP_DEFLATED)
            match = glob.glob(os.path.join(CONFIG.ADDON_DATA, 'skin.*', ''))
            for fold in match:
                fd = os.path.split(fold[:-1])[1]
                if fd not in ['skin.confluence', 'skin.estuary', 'skin.estouchy']:
                    if dialog.yesno(CONFIG.ADDONTITLE,
                                    "[COLOR {0}]Would you like to add the following skin folder to the GUI Fix Zip File?[/COLOR]".format(CONFIG.COLOR2),
                                    "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, fd),
                                    yeslabel="[B][COLOR springgreen]Add Skin[/COLOR][/B]",
                                    nolabel="[B][COLOR red]Skip Skin[/COLOR][/B]"):
                        for base, dirs, files in os.walk(os.path.join(CONFIG.ADDON_DATA, fold)):
                            files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                            for file in files:
                                fn = os.path.join(base, file)
                                zipf.write(fn, fn[len(CONFIG.USERDATA):], zipfile.ZIP_DEFLATED)
                        xml = os.path.join(CONFIG.ADDONS, fd, 'addon.xml')
                        if os.path.exists(xml):
                            matchxml = tools.parse_dom(tools.read_from_file(xml), 'import', ret='addon')
                            if 'script.skinshortcuts' in matchxml:
                                for base, dirs, files in os.walk(os.path.join(CONFIG.ADDON_DATA, 'script.skinshortcuts')):
                                    files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                                    for file in files:
                                        fn = os.path.join(base, file)
                                        zipf.write(fn, fn[len(CONFIG.USERDATA):], zipfile.ZIP_DEFLATED)
                    else:
                        logging.log("[Back Up] Type = guifix: {0} ignored".format(fold))
        except Exception as e:
            logging.log("[Back Up] Type = guifix: {0}".format(e))
            pass
        zipf.close()
        if not tempguizipname == '':
            success = xbmcvfs.rename(tempguizipname, guizipname)
            if success == 0:
                xbmcvfs.copy(tempguizipname, guizipname)
                xbmcvfs.delete(tempguizipname)
    else:
        logging.log("[Back Up] Type = guifix: guisettings.xml not found")
    if name == "":
        dialog.ok(CONFIG.ADDONTITLE, "[COLOR {0}]GUI Fix backup successful:[/COLOR]".format(CONFIG.COLOR2),
                  "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, guizipname))
Beispiel #6
0
def _backup_build(name=""):
    dialog = xbmcgui.Dialog()
    progress_dialog = xbmcgui.DialogProgress()

    if dialog.yesno(CONFIG.ADDONTITLE,
                        "[COLOR {0}]Are you sure you wish to backup the current build?[/COLOR]".format(CONFIG.COLOR2),
                    nolabel="[B][COLOR red]Cancel Backup[/COLOR][/B]",
                    yeslabel="[B][COLOR springgreen]Backup Build[/COLOR][/B]"):
        if name == "":
            name = tools.get_keyboard("", "Please enter a name for the build zip")
            if not name:
                return False
            name = name.replace('\\', '').replace('/', '').replace(':', '').replace('*', '').replace('?', '').replace(
                '"', '').replace('<', '').replace('>', '').replace('|', '')
        name = quote_plus(name)
        tempzipname = ''
        zipname = os.path.join(CONFIG.MYBUILDS, '{0}.zip'.format(name))
        for_progress = 0
        ITEM = []
        exclude_dirs = CONFIG.EXCLUDE_DIRS

        if not dialog.yesno(CONFIG.ADDONTITLE,
                                "[COLOR {0}]Do you want to include your addon_data folder?".format(CONFIG.COLOR2),
                                "This contains [COLOR {0}]ALL[/COLOR] add-on settings including passwords but may also contain important information such as skin shortcuts. We recommend [COLOR {0}]MANUALLY[/COLOR] removing the addon_data folders that aren\'t required.".format(CONFIG.COLOR1, CONFIG.COLOR1),
                                "[COLOR {0}]{1}[/COLOR] addon_data is ignored[/COLOR]".format(CONFIG.COLOR1, CONFIG.ADDON_ID),
                            yeslabel='[B][COLOR springgreen]Include data[/COLOR][/B]',
                            nolabel='[B][COLOR red]Don\'t Include[/COLOR][/B]'):
            exclude_dirs.append('addon_data')

        tools.convert_special(CONFIG.HOME, True)
        # tools.ascii_check(CONFIG.HOME, True)
        extractsize = 0
        try:
            zipf = zipfile.ZipFile(xbmc.translatePath(zipname), mode='w')
        except:
            try:
                tempzipname = os.path.join(CONFIG.PACKAGES, '{0}.zip'.format(name))
                zipf = zipfile.ZipFile(tempzipname, mode='w')
            except:
                logging.log("Unable to create {0}.zip".format(name), level=xbmc.LOGERROR)
                if dialog.yesno(CONFIG.ADDONTITLE,
                                "[COLOR {0}]We are unable to write to the current backup directory, would you like to change the location?[/COLOR]".format(CONFIG.COLOR2),
                                yeslabel="[B][COLOR springgreen]Change Directory[/COLOR][/B]",
                                nolabel="[B][COLOR red]Cancel[/COLOR][/B]"):
                    CONFIG.open_settings()
                    return
                else:
                    return
        progress_dialog.create("[COLOR {0}]{1}[/COLOR][COLOR {2}]: Creating Zip[/COLOR]".format(CONFIG.COLOR1, CONFIG.ADDONTITLE, CONFIG.COLOR2),
                  "[COLOR {0}]Creating backup zip".format(CONFIG.COLOR2), "", "Please Wait...[/COLOR]")

        for base, dirs, files in os.walk(CONFIG.HOME):
            dirs[:] = [d for d in dirs if d not in exclude_dirs]
            files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
            for file in files:
                ITEM.append(file)

        N_ITEM = len(ITEM)
        picture = []
        music = []
        video = []
        programs = []
        repos = []
        scripts = []
        skins = []
        fold = glob.glob(os.path.join(CONFIG.ADDONS, '*/'))
        idlist = []
        
        binaries = []
        binidlist = []

        for folder in sorted(fold, key=lambda x: x):
            foldername = os.path.split(folder[:-1])[1]
            if foldername == 'packages':
                continue
                
            binaryid, binaryname = db.find_binary_addons(addon=foldername)
            
            if binaryid:
                binaries.append(binaryname)
                binidlist.append(binaryid)     
                
            xml = os.path.join(folder, 'addon.xml')
            if os.path.exists(xml):
                a = tools.read_from_file(xml)
                prov = re.compile("<provides>(.+?)</provides>").findall(a)
                match = tools.parse_dom(prov, 'addon', ret='id')

                addid = foldername if len(match) == 0 else match[0]
                if addid in idlist:
                    continue
                idlist.append(addid)
                try:
                    add = xbmcaddon.Addon(id=addid)
                    aname = add.getAddonInfo('name')
                    aname = aname.replace('[', '<').replace(']', '>')
                    aname = str(re.sub('<[^<]+?>', '', aname)).lstrip()
                except:
                    aname = foldername
                if len(prov) == 0:
                    if foldername.startswith('skin'):
                        skins.append(aname)
                    elif foldername.startswith('repo'):
                        repos.append(aname)
                    else:
                        scripts.append(aname)
                    continue
                if not (prov[0]).find('executable') == -1:
                    programs.append(aname)
                if not (prov[0]).find('video') == -1:
                    video.append(aname)
                if not (prov[0]).find('audio') == -1:
                    music.append(aname)
                if not (prov[0]).find('image') == -1:
                    picture.append(aname)
        db.fix_metas()
        
        binarytxt = _backup_binaries(binidlist)

        for base, dirs, files in os.walk(CONFIG.HOME):
            dirs[:] = [d for d in dirs if d not in exclude_dirs]
            files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
            for file in files:
                try:
                    for_progress += 1
                    progress = tools.percentage(for_progress, N_ITEM)
                    progress_dialog.update(int(progress),
                              '[COLOR {0}]Creating backup zip: [COLOR {1}]{2}[/COLOR] / [COLOR {3}]{4}[/COLOR]'.format(
                              CONFIG.COLOR2, CONFIG.COLOR1, for_progress, CONFIG.COLOR1, N_ITEM),
                                  '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1, file), '')
                    fn = os.path.join(base, file)
                    if file in CONFIG.LOGFILES:
                        logging.log("[Back Up] Type = build: Ignore {0} - Log File".format(file))
                        continue
                    elif os.path.join(base, file) in CONFIG.EXCLUDE_FILES:
                        logging.log("[Back Up] Type = build: Ignore {0} - Excluded File".format(file))
                        continue
                    elif os.path.join('addons', 'packages') in fn:
                        logging.log("[Back Up] Type = build: Ignore {0} - Packages Folder".format(file))
                        continue
                    elif file.endswith('.csv'):
                        logging.log("[Back Up] Type = build: Ignore {0} - CSV File".format(file))
                        continue
                    elif file.endswith('.pyo'):
                        continue
                    elif file.endswith('.db') and 'Database' in base:
                        temp = file.replace('.db', '')
                        temp = ''.join([i for i in temp if not i.isdigit()])
                        if temp in CONFIG.DB_FILES:
                            if not file == db.latest_db(temp):
                                logging.log("[Back Up] Type = build: Ignore {0} - DB File".format(file))
                                continue
                                
                    skipbinary = False 
                    if len(binidlist) > 0: 
                        for id in binidlist: 
                            id = os.path.join(CONFIG.ADDONS, id) 
                            if id in fn: 
                                skipbinary = True 
                             
                    if skipbinary: 
                        logging.log("[Back Up] Type = build: Ignore {0} - Binary Add-on".format(file)) 
                        continue
                        
                    try:
                        zipf.write(fn, fn[len(CONFIG.HOME):], zipfile.ZIP_DEFLATED)
                        extractsize += os.path.getsize(fn)
                    except Exception as e:
                        logging.log("[Back Up] Type = build: Unable to backup {0}".format(file))
                        logging.log("{0} / {1}".format(Exception, e))
                    if progress_dialog.iscanceled():
                        progress_dialog.close()
                        logging.log_notify("[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, CONFIG.ADDONTITLE),
                                  "[COLOR {0}]Backup Cancelled[/COLOR]".format(CONFIG.COLOR2))
                        sys.exit()
                except Exception as e:
                    logging.log("[Back Up] Type = build: Unable to backup {0}".format(file))
                    logging.log("Build Backup Error: {0}".format(str(e)))
                    
        if 'addon_data' in exclude_dirs:
            match = glob.glob(os.path.join(CONFIG.ADDON_DATA, 'skin.*', ''))
            for fold in match:
                fd = os.path.split(fold[:-1])[1]
                if fd not in ['skin.confluence', 'skin.estuary', 'skin.estouchy']:
                    for base, dirs, files in os.walk(os.path.join(CONFIG.ADDON_DATA, fold)):
                        files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                        for file in files:
                            fn = os.path.join(base, file)
                            zipf.write(fn, fn[len(CONFIG.HOME):], zipfile.ZIP_DEFLATED)
                            extractsize += os.path.getsize(fn)
                    xml = os.path.join(CONFIG.ADDONS, fd, 'addon.xml')
                    if os.path.exists(xml):
                        matchxml = tools.parse_dom(tools.read_from_file(xml), 'import', ret='addon')
                        if 'script.skinshortcuts' in matchxml:
                            for base, dirs, files in os.walk(os.path.join(CONFIG.ADDON_DATA, 'script.skinshortcuts')):
                                files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                                for file in files:
                                    fn = os.path.join(base, file)
                                    zipf.write(fn, fn[len(CONFIG.HOME):], zipfile.ZIP_DEFLATED)
                                    extractsize += os.path.getsize(fn)
        zipf.close()
        xbmc.sleep(500)
        progress_dialog.close()

        backup('guifix', name)

        if not tempzipname == '':
            success = xbmcvfs.rename(tempzipname, zipname)
            if success == 0:
                xbmcvfs.copy(tempzipname, zipname)
                xbmcvfs.delete(tempzipname)
                
        if binarytxt is not None:
            bintxtpath = os.path.join(CONFIG.USERDATA, binarytxt)
            xbmcvfs.delete(bintxtpath)
         
        _backup_info(name, extractsize, programs, video, music, picture, repos, scripts, binaries)

        if len(binaries) > 0:
            dialog.ok(CONFIG.ADDONTITLE, "[COLOR {0}]The following add-ons were excluded from the backup because they are platform specific:[/COLOR]".format(CONFIG.COLOR2), "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, ', '.join(binaries)))
        
        dialog.ok(CONFIG.ADDONTITLE, "[COLOR {0}]{1}[/COLOR] [COLOR {2}]Backup successful:[/COLOR]".format(CONFIG.COLOR1, name, CONFIG.COLOR2), "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, zipname))
Beispiel #7
0
def _backup_addon_pack(name=""):
    dialog = xbmcgui.Dialog()
    progress_dialog = xbmcgui.DialogProgress()
    
    if dialog.yesno(CONFIG.ADDONTITLE,
                        "[COLOR {0}]Are you sure you wish to create an Addon Pack?[/COLOR]".format(CONFIG.COLOR2),
                        nolabel="[B][COLOR red]Cancel Backup[/COLOR][/B]",
                        yeslabel="[B][COLOR springgreen]Create Pack[/COLOR][/B]"):
        if name == "":
            name = tools.get_keyboard("", "Please enter a name for the add-on pack zip")
            if not name:
                return False
            name = quote_plus(name)
        name = '{0}.zip'.format(name)
        tempzipname = ''
        zipname = os.path.join(CONFIG.MYBUILDS, name)
        try:
            zipf = zipfile.ZipFile(xbmc.translatePath(zipname), mode='w')
        except:
            try:
                tempzipname = os.path.join(CONFIG.PACKAGES, '{0}.zip'.format(name))
                zipf = zipfile.ZipFile(tempzipname, mode='w')
            except:
                logging.log("Unable to create {0}.zip".format(name), level=xbmc.LOGERROR)
                if dialog.yesno(CONFIG.ADDONTITLE,
                                    "[COLOR {0}]We are unable to write to the current backup directory, would you like to change the location?[/COLOR]".format(
                                        CONFIG.COLOR2),
                                    yeslabel="[B][COLOR springgreen]Change Directory[/COLOR][/B]",
                                    nolabel="[B][COLOR red]Cancel[/COLOR][/B]"):
                    CONFIG.open_settings()
                    return
                else:
                    return
        fold = glob.glob(os.path.join(CONFIG.ADDONS, '*/'))
        addonnames = []
        addonfolds = []
        for folder in sorted(fold, key=lambda x: x):
            foldername = os.path.split(folder[:-1])[1]
            if foldername in CONFIG.EXCLUDES:
                continue
            elif foldername in CONFIG.DEFAULTPLUGINS:
                continue
            elif foldername == 'packages':
                continue
            xml = os.path.join(folder, 'addon.xml')
            if os.path.exists(xml):
                match = tools.parse_dom(tools.read_from_file(xml), 'addon', ret='name')
                if len(match) > 0:
                    addonnames.append(match[0])
                    addonfolds.append(foldername)
                else:
                    addonnames.append(foldername)
                    addonfolds.append(foldername)

        selected = dialog.multiselect(
            "{0}: Select the add-ons you wish to add to the zip.".format(CONFIG.ADDONTITLE), addonnames)
        if selected is None:
            selected = []

        logging.log(selected)
        progress_dialog.create(CONFIG.ADDONTITLE,
                      '[COLOR {0}][B]Creating Zip File:[/B][/COLOR]'.format(CONFIG.COLOR2), '', 'Please Wait')
        if len(selected) > 0:
            added = []
            for item in selected:
                added.append(addonfolds[item])
                progress_dialog.update(0, "", "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, addonfolds[item]))
                for base, dirs, files in os.walk(os.path.join(CONFIG.ADDONS, addonfolds[item])):
                    files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                    for file in files:
                        if file.endswith('.pyo'):
                            continue
                        progress_dialog.update(0, "", "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, addonfolds[item]),
                                      "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, file))
                        fn = os.path.join(base, file)
                        zipf.write(fn, fn[len(CONFIG.ADDONS):], zipfile.ZIP_DEFLATED)
                dep = os.path.join(CONFIG.ADDONS, addonfolds[item], 'addon.xml')
                if os.path.exists(dep):
                    match = tools.parse_dom(tools.read_from_file(dep), 'import', ret='addon')
                    for depends in match:
                        if 'xbmc.python' in depends:
                            continue
                        if depends in added:
                            continue
                        progress_dialog.update(0, "", "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, depends))
                        for base, dirs, files in os.walk(os.path.join(CONFIG.ADDONS, depends)):
                            files[:] = [f for f in files if f not in CONFIG.EXCLUDE_FILES]
                            for file in files:
                                if file.endswith('.pyo'):
                                    continue
                                progress_dialog.update(0, "", "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, depends),
                                              "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, file))
                                fn = os.path.join(base, file)
                                zipf.write(fn, fn[len(CONFIG.ADDONS):], zipfile.ZIP_DEFLATED)
                                added.append(depends)
        dialog.ok(CONFIG.ADDONTITLE,
                      "[COLOR {0}]{1}[/COLOR] [COLOR {2}]Backup successful:[/COLOR]".format(CONFIG.COLOR1, name,
                                                                                            CONFIG.COLOR2),
                      "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, zipname))