b4573pin

installer.py

Dec 28th, 2018
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. def zip(_in, _out, exclusions):
  2.     pout = _out.replace('\\','/')
  3.     zout = pout.split('/')[-1]
  4.     true_parent_folder = pout.replace(zout,'')
  5.     kodi.log('Source: ' +true_parent_folder)
  6.     zip_file = zipfile.ZipFile(_out, 'w', zipfile.ZIP_DEFLATED)
  7.     try:
  8.         for zin in _in:
  9.             p_folder = os.path.dirname(zin)
  10.             parent_folder = p_folder.replace('\\','/')
  11.             for root, folders, files in os.walk(zin):
  12.                 r = root.replace('\\','/')
  13.                 # Include all subfolders, including empty ones.
  14.                 for folder_name in folders:
  15.                     foldern = folder_name.replace('\\','/')
  16.                     absolute_path = os.path.join(r, foldern)
  17.                     relative_path = absolute_path.replace(true_parent_folder, '')
  18.                     if not any(e in relative_path for e in exclusions):
  19.                         kodi.log("Adding '%s' to archive." % relative_path)
  20.                         zip_file.write(absolute_path, relative_path)
  21.                     else:
  22.                         kodi.log("Excluding '%s' from the archive." % relative_path)
  23.                 for file_name in files:
  24.                     filen = file_name.replace('\\','/')
  25.                     abs_path = os.path.join(r, filen)
  26.                     absolute_path = abs_path.replace('\\','/')
  27.                     relative_path = absolute_path.replace(true_parent_folder, '')
  28.                     if not any(e in relative_path for e in exclusions):
  29.                         kodi.log("Adding '%s' to archive." % relative_path)
  30.                         dp.update(100, 'Archiving: '+zout,
  31.                                          '',
  32.                                          '[B]' + relative_path + '[/B]')
  33.                         zip_file.write(absolute_path, relative_path)
  34.                     else:
  35.                         kodi.log("Excluding '%s' from the archive." % relative_path)
  36.  
  37.         return True
  38.  
  39.     except IOError, e:
  40.         kodi.log(str(e))
  41.         return False
  42.     except OSError, e:
  43.         kodi.log(str(e))
  44.         return False
  45.     except zipfile.BadZipfile, e:
  46.         kodi.log(str(e))
  47.         return False
  48.     finally:
  49.         zip_file.close()
Advertisement
Add Comment
Please, Sign In to add comment