Advertisement
Guest User

godev_clean

a guest
Feb 23rd, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 26.08 KB | None | 0 0
  1. import threading,xbmc,xbmcplugin,xbmcgui,re,os,xbmcaddon,sys
  2. import shutil
  3. import glob
  4. import zipfile
  5. import urlparse
  6. import xbmcgui
  7. import time
  8. import extract
  9. global debuglog
  10.  
  11. ADDON          =  xbmcaddon.Addon(id='plugin.program.Legacy')
  12. dialog         =  xbmcgui.Dialog()
  13. dialogprocess  =  xbmcgui.DialogProgress()
  14. log_path       =  xbmc.translatePath('special://logpath/')
  15. zip            =  ADDON.getSetting('zip')
  16. USERDATA       =  xbmc.translatePath(os.path.join('special://home/userdata',''))
  17. GUI            =  xbmc.translatePath(os.path.join(USERDATA,'guisettings.xml'))
  18. GUIFIX         =  xbmc.translatePath(os.path.join(USERDATA,'guifix.xml'))
  19. INSTALL        =  xbmc.translatePath(os.path.join(USERDATA,'install.xml'))
  20. FAVS           =  xbmc.translatePath(os.path.join(USERDATA,'favourites.xml'))
  21. SOURCE         =  xbmc.translatePath(os.path.join(USERDATA,'sources.xml'))
  22. ADVANCED       =  xbmc.translatePath(os.path.join(USERDATA,'advancedsettings.xml'))
  23. PROFILES       =  xbmc.translatePath(os.path.join(USERDATA,'profiles.xml'))
  24. RSS            =  xbmc.translatePath(os.path.join(USERDATA,'RssFeeds.xml'))
  25. KEYMAPS        =  xbmc.translatePath(os.path.join(USERDATA,'keymaps','keyboard.xml'))
  26. HOME           =  xbmc.translatePath('special://home/')
  27. USB            =  xbmc.translatePath(os.path.join(zip))
  28. homedir        =  xbmc.translatePath('special://home/')
  29. packagesfolder =  xbmc.translatePath(os.path.join('special://home/addons','packages'))
  30. thumbsfolder   =  xbmc.translatePath(os.path.join('special://home/userdata','Thumbnails'))
  31. addondatafolder=  xbmc.translatePath(os.path.join('special://home/userdata','addon_data'))
  32. addondir       =  xbmc.translatePath('special://home/addons/script.areswizard')
  33. mainaddondir   =  xbmc.translatePath('special://home/addons')
  34. temp1          =  xbmc.translatePath('special://home/userdata')
  35. temp2          =  xbmc.translatePath('special://temp')
  36. images_path    =  os.path.join(addondir, 'resources/images')
  37. skin           =  xbmc.getSkinDir()
  38.  
  39. try:
  40.     from sqlite3 import dbapi2 as database
  41. except:
  42.     from pysqlite2 import dbapi2 as database
  43.  
  44. def freshstart():
  45.  
  46.     choice = xbmcgui.Dialog().yesno('[COLOR lime][B]Legacy[/COLOR][/B][COLOR orange][B]Wizard[/COLOR][/B]  [COLOR=red][B]WARNING !!![/COLOR][/B]', 'This will erase all data and reset Kodi to defaults!','  Kodi will try to force close after the process is complete.', '[COLOR=red][B]Do you want to continue?[/COLOR][/B]', nolabel='Nope',yeslabel='YES')
  47.     if choice == 0:
  48.         return
  49.     elif choice == 1:
  50.         pass
  51.  
  52.         dp = xbmcgui.DialogProgress()
  53.     dp.create("Legacy Wizard","Please Wait")
  54.     dp.update(1)
  55.  
  56.    
  57.     path  = xbmc.translatePath('special://Database')
  58.     files = glob.glob(os.path.join(path, 'Textures*.db'))
  59.     for f in files:    
  60.         try:
  61.             os.remove(f)
  62.         except:
  63.             Shrink(f)
  64.  
  65.  
  66.  
  67.     for root, dirs, files in os.walk(homedir):
  68.             for f in files:
  69.                             try:
  70.                                     if f == "kodi.log" or f == "build.zip":
  71.                                         pass
  72.                                     else:
  73.                                         path = os.path.join(root, f)
  74.                                         if 'repository.Legacy' not in path and 'plugin.program.Legacy' not in path and 'script.module.elementtree' not in path and 'script.module.requests' not in path:
  75.                                             dp.update(1, '', '', 'Deleting: ' + f)
  76.                                             os.unlink(path)
  77.                                             print 'from HOMEDIR deleted: ' + root + f
  78.                             except:
  79.                                     pass
  80.             for d in dirs:
  81.                             try:
  82.                                     if d == "Database" or d == "addon_data" or d == "userdata" or d == "packages" or d == "addons" or d == "Thumbnails" or d == "temp" or d == "repository.Legacy" or d == "plugin.program.Legacy" or d == "script.module.elementtree" or d== "script.module.requests":
  83.                                         pass
  84.                                     else:
  85.                                         path = os.path.join(root, d)
  86.                                         if 'repository.Legacy' not in path and 'plugin.program.Legacy' not in path and 'script.module.elementtree' not in path and 'script.module.requests' not in path:
  87.                                             dp.update(1, '', '', 'Deleting: ' + d)
  88.                                             shutil.rmtree(os.path.join(root, d))
  89.                                             print 'from HOMEDIR removed folder: ' + os.path.join(root, d)
  90.                             except:
  91.                                     pass
  92.                                            
  93.            
  94.     dp.update(30)
  95.  
  96.  
  97.  
  98.            
  99.            
  100.     for root, dirs, files in os.walk(addondatafolder):
  101.             for f in files:
  102.                             try:
  103.                                     dp.update(30, '', '', 'Deleting: ' + f)
  104.                                     path = os.path.join(root, f)
  105.                                     if 'repository.Legacy' not in path:
  106.                                         os.unlink(os.path.join(root, f))
  107.                                         print 'from ADDONDATA deleted: ' + root + f
  108.                             except:
  109.                                     pass
  110.             for d in dirs:
  111.                             try:
  112.                                     dp.update(30, '', '', 'Deleting: ' + d)
  113.                                     path = os.path.join(root, d)
  114.                                     if 'repository.Legacy' not in path:
  115.                                         shutil.rmtree(os.path.join(root, d))
  116.                                         print 'from ADDONDATA removed folder: ' + os.path.join(root, d)
  117.                             except:
  118.                                                 pass       
  119.                
  120.            
  121.     dp.update(50)
  122.  
  123.  
  124.     for root, dirs, files in os.walk(temp1):
  125.             for f in files:
  126.                             try:
  127.                                     dp.update(50, '', '', 'Deleting: ' + f)
  128.                                     path = os.path.join(root, f)
  129.                                     if 'repository.Legacy' not in path:
  130.                                         os.unlink(os.path.join(root, f))
  131.                                         print 'from TEMP1 deleted: ' + root + f
  132.                             except:
  133.                                     pass
  134.             for d in dirs:
  135.                             try:
  136.                                     if d == "Database" or d == "addon_data" or d == "Thumbnails":
  137.                                         pass
  138.                                     else:
  139.                                         dp.update(50, '', '', 'Deleting: ' + d)
  140.                                         path = os.path.join(root, d)
  141.                                         if 'repository.Legacy' not in path :
  142.                                             shutil.rmtree(os.path.join(root, d))
  143.                                             print 'from TEMP1 removed folder: ' + os.path.join(root, d)
  144.                             except:
  145.                                     pass   
  146.  
  147.  
  148.     dp.update(65)
  149.  
  150.  
  151.  
  152.     for root, dirs, files in os.walk(temp2):
  153.             for f in files:
  154.                             try:
  155.                                     if f == "kodi.log" or f == "build.zip":
  156.                                         pass
  157.                                     else:
  158.                                         dp.update(50, '', '', 'Deleting: ' + f)
  159.                                         os.unlink(os.path.join(root, f))
  160.                                         print 'from TEMP1 deleted: ' + root + f
  161.                             except:
  162.                                     pass
  163.             for d in dirs:
  164.                             try:
  165.                                     dp.update(50, '', '', 'Deleting: ' + d)
  166.                                     shutil.rmtree(os.path.join(root, d))
  167.                                     print 'from TEMP2 removed folder: ' + os.path.join(root, d)
  168.                             except:
  169.                                     pass   
  170.  
  171.  
  172.     dp.update(70)
  173.  
  174.  
  175.  
  176.  
  177.     for root, dirs, files in os.walk(packagesfolder):
  178.         for f in files:
  179.                         try:
  180.                                 if f == "kodi.log" or f == "build.zip":
  181.                                     pass
  182.                                 else:
  183.                                     dp.update(50, '', '', 'Deleting: ' + f)
  184.                                     os.unlink(os.path.join(root, f))
  185.                                     print 'from PACKAGES deleted: ' + root + f
  186.                         except:
  187.                                 pass
  188.         for d in dirs:
  189.                         try:
  190.                                 dp.update(50, '', '', 'Deleting: ' + d)
  191.                                 shutil.rmtree(os.path.join(root, d))
  192.                                 print 'from PACKAGES removed folder: ' + os.path.join(root, d)
  193.                         except:
  194.                                 pass   
  195.  
  196.  
  197.     dp.update(75)
  198.  
  199.  
  200.     for root, dirs, files in os.walk(thumbsfolder):
  201.             for f in files:
  202.                             try:
  203.                                     dp.update(75, '', '', 'Deleting: ' + f)
  204.                                     os.unlink(os.path.join(root, f))
  205.                                     print 'from THUMBS deleted: ' + root + f
  206.                             except:
  207.                                     pass
  208.             for d in dirs:
  209.                             try:
  210.                                     dp.update(75, '', '', 'Deleting: ' + d)
  211.                                     shutil.rmtree(os.path.join(root, d))
  212.                                     print 'from THUMBS removed folder: ' + os.path.join(root, d)
  213.                             except:
  214.                                     pass   
  215.  
  216.            
  217.            
  218.     dp.update(85)
  219.  
  220.  
  221.     for root, dirs, files in os.walk(mainaddondir):
  222.             for f in files:
  223.                             try:
  224.                                     if f == "kodi.log" or f == "build.zip":
  225.                                         pass
  226.                                     else:
  227.                                         path = os.path.join(root, f)
  228.                                         if 'repository.Legacy' not in path and 'plugin.program.Legacy' not in path and 'script.module.elementtree' not in path and 'script.module.requests' not in path:
  229.                                             dp.update(85, '', '', 'Deleting: ' + f)
  230.                                             os.unlink(path)
  231.                                             print 'from MAINADDONDIR deleted: ' + root + f
  232.                             except:
  233.                                     pass
  234.             for d in dirs:
  235.                             try:
  236.                                     if d == "packages" or d == "repository.Legacy" or d == "plugin.program.Legacy" or d == "script.module.elementtree" or d== "script.module.requests":
  237.                                         pass
  238.                                     else:
  239.                                         if 'repository.Legacy' not in path and 'plugin.program.Legacy' not in path and 'script.module.elementtree' not in path and 'script.module.requests' not in path:
  240.                                             dp.update(85, '', '', 'Deleting: ' + d)
  241.                                             shutil.rmtree(os.path.join(root, d))
  242.                                             print 'from MAINADDONDIR removed folder: ' + os.path.join(root, d)
  243.                             except:
  244.                                     pass   
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.     dp.close
  252.  
  253.     xbmc.executebuiltin("ReloadSkin()")
  254.     xbmc.executebuiltin("UpdateLocalAddons")
  255.    
  256.     killkodi() 
  257.    
  258. def killkodi():
  259.  
  260.     myplatform = platform()
  261.     os._exit(1)
  262.     print "Platform: " + str(myplatform)
  263.     if myplatform == 'osx': # OSX
  264.         print "############   try osx force close  #################"
  265.         try: os.system('killall -9 XBMC')
  266.         except: pass
  267.         try: os.system('killall -9 Kodi')
  268.         except: pass
  269.         dialog.ok("[COLOR=red][B]WARNING  !!![/COLOR][/B]", "If you\'re seeing this message it means the force close", "was unsuccessful. Please force close XBMC/Kodi [COLOR=lime]DO NOT[/COLOR] exit cleanly via the menu.",'')
  270.     elif myplatform == 'linux': #Linux
  271.         print "############   try linux force close  #################"
  272.         try: os.system('killall XBMC')
  273.         except: pass
  274.         try: os.system('killall Kodi')
  275.         except: pass
  276.         try: os.system('killall -9 xbmc.bin')
  277.         except: pass
  278.         try: os.system('killall -9 kodi.bin')
  279.         except: pass
  280.         dialog.ok("[COLOR=red][B]WARNING  !!![/COLOR][/B]", "If you\'re seeing this message it means the force close", "was unsuccessful. Please force close XBMC/Kodi [COLOR=lime]DO NOT[/COLOR] exit cleanly via the menu.",'')
  281.     elif myplatform == 'android': # Android  
  282.         print "############   try android force close  #################"
  283.         try: os.system('adb shell am force-stop org.xbmc.kodi')
  284.         except: pass
  285.         try: os.system('adb shell am force-stop org.kodi')
  286.         except: pass
  287.         try: os.system('adb shell am force-stop org.xbmc.cemc')
  288.         except: pass
  289.         try: os.system('adb shell am force-stop org.xbmc.cemc_pro')
  290.         except: pass
  291.         try: os.system('adb shell am force-stop com.semperpax.spmc16')
  292.         except: pass
  293.         try: os.system('adb shell am force-stop org.lodi.mobi')
  294.         except: pass
  295.         try: os.system('adb shell am force-stop com.perfectzoneproductions.jesusboxmedia')
  296.         except: pass
  297.         try: os.system('adb shell am force-stop org.xbmc.xbmc')
  298.         except: pass
  299.         try: os.system('adb shell am force-stop org.xbmc')
  300.         except: pass
  301.         try: os.system('adb shell kill org.xbmc.kodi')
  302.         except: pass
  303.         try: os.system('adb shell kill org.kodi')
  304.         except: pass
  305.         try: os.system('adb shell kill org.xbmc.xbmc')
  306.         except: pass
  307.         try: os.system('adb shell kill org.xbmc')
  308.         except: pass
  309.         try: os.system('adb shell kill com.semperpax.spmc16')
  310.         except: pass
  311.         try: os.system('adb shell kill com.semperpax')
  312.         except: pass
  313.         try: os.system('adb shell kill com.perfectzoneproductions.jesusboxmedia')
  314.         except: pass
  315.         try: os.system('adb shell kill org.xbmc.cemc')
  316.         except: pass
  317.         try: os.system('adb shell kill org.xbmc.cemc_pro')
  318.         except: pass
  319.         try: os.system('adb shell kill org.lodi.mobi')
  320.         except: pass
  321.         try: os.system('adb shell kill com.semperpax')
  322.         except: pass
  323.         try: os.system('Process.killProcess(android.os.Process.org.xbmc,kodi());')
  324.         except: pass
  325.         try: os.system('Process.killProcess(android.os.Process.org.kodi());')
  326.         except: pass
  327.         try: os.system('Process.killProcess(android.os.Process.org.xbmc.xbmc());')
  328.         except: pass
  329.         try: os.system('Process.killProcess(android.os.Process.org.xbmc());')
  330.         except: pass
  331.         dialog.ok("[COLOR=red][B]WARNING  !!![/COLOR][/B]", "Your system has been detected as Android, you ", "[COLOR=yellow][B]MUST[/COLOR][/B] force close Kodi. [COLOR=lime]DO NOT[/COLOR] exit cleanly via the menu.","Pulling the power cable is the simplest method to force close.")
  332.     elif myplatform == 'windows': # Windows
  333.         print "############   try windows force close  #################"
  334.         try:
  335.             os.system('@ECHO off')
  336.             os.system('tskill XBMC.exe')
  337.         except: pass
  338.         try:
  339.             os.system('@ECHO off')
  340.             os.system('tskill Kodi.exe')
  341.         except: pass
  342.         try:
  343.             os.system('@ECHO off')
  344.             os.system('tskill SMC.exe')
  345.         except: pass
  346.         try:
  347.             os.system('@ECHO off')
  348.             os.system('TASKKILL /im Kodi.exe /f')
  349.         except: pass
  350.         try:
  351.             os.system('@ECHO off')
  352.             os.system('TASKKILL /im SMC.exe /f')
  353.         except: pass
  354.         try:
  355.             os.system('@ECHO off')
  356.             os.system('TASKKILL /im XBMC.exe /f')
  357.         except: pass
  358.         dialog.ok("[COLOR=red][B]WARNING  !!![/COLOR][/B]", "If you\'re seeing this message it means the force close", "was unsuccessful. Please force close XBMC/Kodi [COLOR=lime]DO NOT[/COLOR] exit cleanly via the menu.","Use task manager and NOT ALT F4")
  359.     else: #ATV
  360.         print "############   try atv force close  #################"
  361.         try: os.system('killall AppleTV')
  362.         except: pass
  363.         print "############   try raspbmc force close  #################" #OSMC / Raspbmc
  364.         try: os.system('sudo initctl stop kodi')
  365.         except: pass
  366.         try: os.system('sudo initctl stop xbmc')
  367.         except: pass
  368.         dialog.ok("[COLOR=red][B]WARNING  !!![/COLOR][/B]", "If you\'re seeing this message it means the force close", "was unsuccessful. Please force close XBMC/Kodi [COLOR=lime]DO NOT[/COLOR] exit via the menu.","Your platform could not be detected so just pull the power cable.")   
  369.        
  370. def platform():
  371.     if xbmc.getCondVisibility('system.platform.android'):
  372.         return 'android'
  373.     elif xbmc.getCondVisibility('system.platform.linux'):
  374.         return 'linux'
  375.     elif xbmc.getCondVisibility('system.platform.windows'):
  376.         return 'windows'
  377.     elif xbmc.getCondVisibility('system.platform.osx'):
  378.         return 'osx'
  379.     elif xbmc.getCondVisibility('system.platform.atv2'):
  380.         return 'atv2'
  381.     elif xbmc.getCondVisibility('system.platform.ios'):
  382.         return 'ios'
  383.        
  384. try:
  385.     debuglog = xbmcplugin.getSetting(int(sys.argv[1]), 'debuglog')
  386. except:
  387.     debuglog = "0" 
  388.        
  389. def Add_Directory_Item(handle, url, listitem, isFolder):
  390.     xbmcplugin.addDirectoryItem(handle, url, listitem, isFolder)
  391. def Read_Zip(url):
  392.     z = zipfile.ZipFile(url, "r")
  393.     for filename in z.namelist():
  394.         if 'guisettings.xml' in filename:
  395.             a = z.read(filename)
  396.             r='<setting type="(.+?)" name="%s.(.+?)">(.+?)</setting>'% skin
  397.             match=re.compile(r).findall(a)
  398.             for type,string,setting in match:
  399.                 setting=setting.replace('&quot;','') .replace('&amp;','&')
  400.                 xbmc.executebuiltin("Skin.Set%s(%s,%s)"%(type.title(),string,setting))
  401.         if 'favourites.xml' in filename:
  402.             a = z.read(filename)
  403.             f = open(FAVS, mode='w')
  404.             f.write(a)
  405.             f.close()
  406.         if 'sources.xml' in filename:
  407.             a = z.read(filename)
  408.             f = open(SOURCE, mode='w')
  409.             f.write(a)
  410.             f.close()
  411.         if 'advancedsettings.xml' in filename:
  412.             a = z.read(filename)
  413.             f = open(ADVANCED, mode='w')
  414.             f.write(a)
  415.             f.close()
  416.         if 'RssFeeds.xml' in filename:
  417.             a = z.read(filename)
  418.             f = open(RSS, mode='w')
  419.             f.write(a)
  420.             f.close()
  421.         if 'keyboard.xml' in filename:
  422.             a = z.read(filename)
  423.             f = open(KEYMAPS, mode='w')
  424.             f.write(a)
  425.             f.close()  
  426. def Archive_File(sourcefile, destfile):
  427.     zipobj = zipfile.ZipFile(destfile , 'w', zipfile.ZIP_DEFLATED)
  428.     rootlen = len(sourcefile)
  429.     for_progress = []
  430.     ITEM =[]
  431.     dialogprocess.create("Legacy","Archiving...",'', 'Please Wait')
  432.     for base, dirs, files in os.walk(sourcefile):
  433.         for file in files:
  434.             ITEM.append(file)
  435.     N_ITEM =len(ITEM)
  436.     for base, dirs, files in os.walk(sourcefile):
  437.         for file in files:
  438.             for_progress.append(file)
  439.             progress = len(for_progress) / float(N_ITEM) * 100  
  440.             dialogprocess.update(int(progress),"Backing Up",'[COLOR yellow]%s[/COLOR]'%file, 'Please Wait')
  441.             dialogprocess.update(int(progress),"Backing Up",'[COLOR yellow]%s[/COLOR]'%file, 'Please Wait')
  442.             fn = os.path.join(base, file)
  443.             if not 'temp' in dirs:
  444.                 if not 'plugin.program.Legacy' in dirs:
  445.                    import time
  446.                    FORCE= '1/1/1980'
  447.                    FILE_DATE=time.strftime('%d/%m/%Y', time.gmtime(os.path.getmtime(fn)))
  448.                    if FILE_DATE > FORCE:
  449.                        zipobj.write(fn, fn[rootlen:])  
  450.     zipobj.close()
  451.     dialogprocess.close()  
  452. def Delete_Packages():
  453.     print 'DELETING PACKAGES'
  454.     packages_cache_path = xbmc.translatePath(os.path.join('special://home/addons/packages', ''))
  455.     for root, dirs, files in os.walk(packages_cache_path):
  456.         file_count = 0
  457.         file_count += len(files)
  458.     # Count files and give option to delete
  459.         if file_count > 0:
  460.             for f in files:
  461.                 os.unlink(os.path.join(root, f))
  462.             for d in dirs:
  463.                 shutil.rmtree(os.path.join(root, d))
  464. def Delete_Logs():  
  465.     for infile in glob.glob(os.path.join(log_path, 'xbmc_crashlog*.*')):
  466.          File=infile
  467.          print infile
  468.          os.remove(infile)
  469.          dialog = xbmcgui.Dialog()
  470.    
  471. def Wipe_Cache():
  472.     xbmc_cache_path = os.path.join(xbmc.translatePath('special://home'), 'cache')
  473.     if os.path.exists(xbmc_cache_path)==True:
  474.         for root, dirs, files in os.walk(xbmc_cache_path):
  475.             file_count = 0
  476.             file_count += len(files)
  477.             if file_count > 0:
  478.                 for f in files:
  479.                     try:
  480.                         os.unlink(os.path.join(root, f))
  481.                     except:
  482.                         pass
  483.                 for d in dirs:
  484.                     try:
  485.                         shutil.rmtree(os.path.join(root, d))
  486.                     except:
  487.                         pass
  488.     if xbmc.getCondVisibility('system.platform.ATV2'):
  489.         atv2_cache_a = os.path.join('/private/var/mobile/Library/Caches/AppleTV/Video/', 'Other')
  490.         for root, dirs, files in os.walk(atv2_cache_a):
  491.             file_count = 0
  492.             file_count += len(files)
  493.             if file_count > 0:
  494.                 for f in files:
  495.                     os.unlink(os.path.join(root, f))
  496.                 for d in dirs:
  497.                     shutil.rmtree(os.path.join(root, d))
  498.         atv2_cache_b = os.path.join('/private/var/mobile/Library/Caches/AppleTV/Video/', 'LocalAndRental')     
  499.         for root, dirs, files in os.walk(atv2_cache_b):
  500.             file_count = 0
  501.             file_count += len(files)
  502.             if file_count > 0:
  503.                 for f in files:
  504.                     os.unlink(os.path.join(root, f))
  505.                 for d in dirs:
  506.                     shutil.rmtree(os.path.join(root, d))
  507.     # Set path to script.module.simple.downloader cache files
  508.     downloader_cache_path = os.path.join(xbmc.translatePath('special://profile/addon_data/script.module.simple.downloader'), '')
  509.     if os.path.exists(downloader_cache_path)==True:
  510.         for root, dirs, files in os.walk(downloader_cache_path):
  511.             file_count = 0
  512.             file_count += len(files)
  513.             if file_count > 0:
  514.                 for f in files:
  515.                     os.unlink(os.path.join(root, f))
  516.                 for d in dirs:
  517.                     shutil.rmtree(os.path.join(root, d))
  518.     # Set path to script.image.music.slideshow cache files
  519.     imageslideshow_cache_path = os.path.join(xbmc.translatePath('special://profile/addon_data/script.image.music.slideshow/cache'), '')
  520.     if os.path.exists(imageslideshow_cache_path)==True:
  521.         for root, dirs, files in os.walk(imageslideshow_cache_path):
  522.             file_count = 0
  523.             file_count += len(files)
  524.             if file_count > 0:
  525.                 for f in files:
  526.                     os.unlink(os.path.join(root, f))
  527.                 for d in dirs:
  528.                     shutil.rmtree(os.path.join(root, d))
  529.     # Set path to BBC iPlayer cache files
  530.     iplayer_cache_path= os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.iplayer/iplayer_http_cache'), '')
  531.     if os.path.exists(iplayer_cache_path)==True:   
  532.         for root, dirs, files in os.walk(iplayer_cache_path):
  533.             file_count = 0
  534.             file_count += len(files)
  535.             if file_count > 0:
  536.                 for f in files:
  537.                     os.unlink(os.path.join(root, f))
  538.                 for d in dirs:
  539.                     shutil.rmtree(os.path.join(root, d))
  540.     itv_cache_path = os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.itv/Images'), '')
  541.     if os.path.exists(itv_cache_path)==True:   
  542.         for root, dirs, files in os.walk(itv_cache_path):
  543.             file_count = 0
  544.             file_count += len(files)
  545.             if file_count > 0:
  546.                 for f in files:
  547.                     os.unlink(os.path.join(root, f))
  548.                 for d in dirs:
  549.                     shutil.rmtree(os.path.join(root, d))
  550.     navix_cache_path= os.path.join(xbmc.translatePath('special://profile/addon_data/script.navi-x/cache'), '')
  551.     if os.path.exists(navix_cache_path)==True
  552.         for root, dirs, files in os.walk(navix_cache_path):
  553.             file_count = 0
  554.             file_count += len(files)
  555.             if file_count > 0:
  556.                 for f in files:
  557.                     os.unlink(os.path.join(root, f))
  558.                 for d in dirs:
  559.                     shutil.rmtree(os.path.join(root, d))
  560.     phoenix_cache_path= os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.phstreams/Cache'), '')
  561.     if os.path.exists(phoenix_cache_path)==True:   
  562.         for root, dirs, files in os.walk(phoenix_cache_path):
  563.             file_count = 0
  564.             file_count += len(files)
  565.             if file_count > 0:
  566.                 for f in files:
  567.                     os.unlink(os.path.join(root, f))
  568.                 for d in dirs:
  569.                     shutil.rmtree(os.path.join(root, d))
  570.     ramfm_cache_path= os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.audio.ramfm/cache'), '')
  571.     if os.path.exists(ramfm_cache_path)==True
  572.         for root, dirs, files in os.walk(ramfm_cache_path):
  573.             file_count = 0
  574.             file_count += len(files)
  575.             if file_count > 0:
  576.                 for f in files:
  577.                     os.unlink(os.path.join(root, f))
  578.                 for d in dirs:
  579.                     shutil.rmtree(os.path.join(root, d))
  580.     wtf_cache_path = os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.whatthefurk/cache'), '')
  581.     if os.path.exists(wtf_cache_path)==True:   
  582.         for root, dirs, files in os.walk(wtf_cache_path):
  583.             file_count = 0
  584.             file_count += len(files)
  585.             if file_count > 0:
  586.                 for f in files:
  587.                     os.unlink(os.path.join(root, f))
  588.                 for d in dirs:
  589.                     shutil.rmtree(os.path.join(root, d))
  590.     try:
  591.         genesisCache = os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.genesis'), 'cache.db')
  592.         dbcon = database.connect(genesisCache)
  593.         dbcur = dbcon.cursor()
  594.         dbcur.execute("DROP TABLE IF EXISTS rel_list")
  595.         dbcur.execute("VACUUM")
  596.         dbcon.commit()
  597.         dbcur.execute("DROP TABLE IF EXISTS rel_lib")
  598.         dbcur.execute("VACUUM")
  599.         dbcon.commit()
  600.     except:
  601.         pass
  602. def Destroy_Path(path):
  603.     dialogprocess.create("Legacy","Cleaning...",'', 'Please Wait')
  604.     shutil.rmtree(path, ignore_errors=True)
  605. def Remove_Textures():
  606.     textures     =  xbmc.translatePath('special://home/userdata/Database/Textures13.db')
  607.     try:
  608.         dbcon = database.connect(textures)
  609.         dbcur = dbcon.cursor()
  610.         dbcur.execute("DROP TABLE IF EXISTS path")
  611.         dbcur.execute("VACUUM")
  612.         dbcon.commit()
  613.         dbcur.execute("DROP TABLE IF EXISTS sizes")
  614.         dbcur.execute("VACUUM")
  615.         dbcon.commit()
  616.         dbcur.execute("DROP TABLE IF EXISTS texture")
  617.         dbcur.execute("VACUUM")
  618.         dbcon.commit()
  619.         dbcur.execute("""CREATE TABLE path (id integer, url text, type text, texture text, primary key(id))""")
  620.         dbcon.commit()
  621.         dbcur.execute("""CREATE TABLE sizes (idtexture integer,size integer, width integer, height integer, usecount integer, lastusetime text)""")
  622.         dbcon.commit()
  623.         dbcur.execute("""CREATE TABLE texture (id integer, url text, cachedurl text, imagehash text, lasthashcheck text, PRIMARY KEY(id))""")
  624.         dbcon.commit()
  625.     except:
  626.         pass
  627. def Read_Zip(url):
  628.     import zipfile
  629.     z = zipfile.ZipFile(url, "r")
  630.     for filename in z.namelist():
  631.         if 'guisettings.xml' in filename:
  632.             a = z.read(filename)
  633.             r='<setting type="(.+?)" name="%s.(.+?)">(.+?)</setting>'% skin
  634.            
  635.             match=re.compile(r).findall(a)
  636.             print match
  637.             for type,string,setting in match:
  638.                 setting=setting.replace('&quot;','') .replace('&amp;','&')
  639.                 xbmc.executebuiltin("Skin.Set%s(%s,%s)"%(type.title(),string,setting)) 
  640.                
  641.         if 'favourites.xml' in filename:
  642.             a = z.read(filename)
  643.             f = open(FAVS, mode='w')
  644.             f.write(a)
  645.             f.close()  
  646.                              
  647.         if 'sources.xml' in filename:
  648.             a = z.read(filename)
  649.             f = open(SOURCE, mode='w')
  650.             f.write(a)
  651.             f.close()  
  652.                          
  653.         if 'advancedsettings.xml' in filename:
  654.             a = z.read(filename)
  655.             f = open(ADVANCED, mode='w')
  656.             f.write(a)
  657.             f.close()                
  658.  
  659.         if 'RssFeeds.xml' in filename:
  660.             a = z.read(filename)
  661.             f = open(RSS, mode='w')
  662.             f.write(a)
  663.             f.close()                
  664.            
  665.         if 'keyboard.xml' in filename:
  666.             a = z.read(filename)
  667.             f = open(KEYMAPS, mode='w')
  668.             f.write(a)
  669.             f.close()              
  670. def Check_Path():
  671.     if zip=='':
  672.      if dialog.yesno("Legacy Wizard", "You Have Not Set Your Storage Path", 'Set The Storage Path Now ?',''):
  673.         ADDON.openSettings()
  674.         print '######### ZIP DIRECTORY #########'
  675.         for filename in os.listdir(USB):
  676.             print filename         
  677. def RestoreIt():
  678.     import time
  679.     dialog = xbmcgui.Dialog()
  680.     if zip == '':
  681.         dialog.ok('Legacy Wizard','You have not set your ZIP Folder.\nPlease update the addon settings and try again.','','')
  682.         ADDON.openSettings(sys.argv[0])
  683.     dialogprocess.create("Legacy Wizard","Restoring",'', 'Please Wait')  
  684.     lib=xbmc.translatePath(os.path.join(zip,'backup.zip'))
  685.     Read_Zip(lib)
  686.     dialogprocess.create("Legacy Wizard","Checking ",'', 'Please Wait')
  687.     HOME = xbmc.translatePath(os.path.join('special://','home'))
  688.     dialogprocess.update(0,"", "Extracting Zip Please Wait")
  689.     extract.all(lib,HOME,dialogprocess)
  690.     time.sleep(1)
  691.     xbmc.executebuiltin('UpdateLocalAddons ')  
  692.     xbmc.executebuiltin("UpdateAddonRepos")
  693.     time.sleep(1)
  694.     xbmc.executebuiltin('UnloadSkin()')
  695.     xbmc.executebuiltin('ReloadSkin()')
  696.     xbmc.executebuiltin("Loadialogprocessrofile(Master user)")
  697.     dialogprocess.close()
  698.     dialog.ok("Legacy Wizard", "All Done, DONT PRESS OK", "Wait a 5 minutes and pull the Power Cord then","")  
  699. def Backupzip():   
  700.     if zip == '':
  701.         dialog.ok('Legacy Wizard','You have not set your ZIP Folder.\nPlease update the addon settings and try again.','','')
  702.         ADDON.openSettings(sys.argv[0])
  703.     to_backup = xbmc.translatePath(os.path.join('special://','home'))
  704.     backup_zip = xbmc.translatePath(os.path.join(USB,'backup.zip'))
  705.     Delete_Packages()  
  706.     import zipfile
  707.    
  708.     dialogprocess.create("Legacy Wizard","Backing Up",'', 'Please Wait')
  709.     zipobj = zipfile.ZipFile(backup_zip , 'w', zipfile.ZIP_DEFLATED)
  710.     rootlen = len(to_backup)
  711.     for_progress = []
  712.     ITEM =[]
  713.     for base, dirs, files in os.walk(to_backup):
  714.         for file in files:
  715.             ITEM.append(file)
  716.     N_ITEM =len(ITEM)
  717.     for base, dirs, files in os.walk(to_backup):
  718.         for file in files:
  719.             for_progress.append(file)
  720.             progress = len(for_progress) / float(N_ITEM) * 100 
  721.             dialogprocess.update(int(progress),"Backing Up",'[COLOR yellow]%s[/COLOR]'%file, 'Please Wait')
  722.             fn = os.path.join(base, file)
  723.             if not 'temp' in dirs:
  724.                 if not 'plugin.program.Legacy' in dirs:
  725.                      import time
  726.                      Spaf= '1/1/1980'
  727.                      FILE_DATE=time.strftime('%d/%m/%Y', time.gmtime(os.path.getmtime(fn)))
  728.                      if FILE_DATE > Spaf:
  729.                          zipobj.write(fn, fn[rootlen:])
  730.     zipobj.close()
  731.     dialogprocess.close()
  732.     dialog.ok("Legacy Wizard", "You Are Now Backed Up", '','')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement