Advertisement
Guest User

LazyTV_Manual_Cloner

a guest
Mar 17th, 2015
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. import os
  2. import sys
  3. import shutil
  4. from xml.etree import ElementTree as et
  5. import fileinput
  6.  
  7.  
  8. CLONE_NAME = 'YOUR_NAME_HERE'
  9. ADDON_PATH = '/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/'
  10.  
  11.  
  12. SAN_NAME = 'script.lazytv.' + CLONE_NAME
  13.  
  14. SCRIPT_PATH = os.path.join(ADDON_PATH, 'script.lazytv')
  15.  
  16. NEW_PATH = os.path.join(ADDON_PATH, SAN_NAME)
  17.  
  18. # copy current addon to new location
  19. IGNORE_PATTERNS = ('.pyc','CVS','.git','tmp','.svn')
  20. shutil.copytree(SCRIPT_PATH,NEW_PATH, ignore=shutil.ignore_patterns(*IGNORE_PATTERNS))
  21.  
  22. # remove the unneeded files
  23. ADDON_FILE = os.path.join(NEW_PATH,'addon.xml')
  24.  
  25. os.remove(os.path.join(NEW_PATH,'service.py'))
  26. os.remove(ADDON_FILE)
  27. os.remove(os.path.join(NEW_PATH,'resources','settings.xml'))
  28. os.remove(os.path.join(NEW_PATH,'resources','clone.py'))
  29.  
  30. # replace the settings file and addon file with the truncated one
  31. shutil.move( os.path.join(NEW_PATH,'resources','addon_clone.xml') , ADDON_FILE )
  32. shutil.move( os.path.join(NEW_PATH,'resources','settings_clone.xml') , os.path.join(NEW_PATH,'resources','settings.xml') )
  33.  
  34. # edit the addon.xml to point to the right folder
  35. tree = et.parse(ADDON_FILE)
  36. root = tree.getroot()
  37. root.set('id', SAN_NAME)
  38. root.set('name', CLONE_NAME)
  39. tree.find('.//summary').text = CLONE_NAME
  40. tree.write(ADDON_FILE)
  41.  
  42. # replace the id on these files, avoids Access Violation
  43. py_files = [os.path.join(NEW_PATH,'resources','selector.py') , os.path.join(NEW_PATH,'resources','playlists.py'),os.path.join(NEW_PATH,'resources','update_clone.py'),os.path.join(NEW_PATH,'resources','episode_exporter.py')]
  44.  
  45. for py in py_files:
  46.     for line in fileinput.input(py, inplace = 1): # Does a list of files, and writes redirects STDOUT to the file in question
  47.         print line.replace('script.lazytv',SAN_NAME),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement