Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def zip(_in, _out, exclusions):
- pout = _out.replace('\\','/')
- zout = pout.split('/')[-1]
- true_parent_folder = pout.replace(zout,'')
- kodi.log('Source: ' +true_parent_folder)
- zip_file = zipfile.ZipFile(_out, 'w', zipfile.ZIP_DEFLATED)
- try:
- for zin in _in:
- p_folder = os.path.dirname(zin)
- parent_folder = p_folder.replace('\\','/')
- for root, folders, files in os.walk(zin):
- r = root.replace('\\','/')
- # Include all subfolders, including empty ones.
- for folder_name in folders:
- foldern = folder_name.replace('\\','/')
- absolute_path = os.path.join(r, foldern)
- relative_path = absolute_path.replace(true_parent_folder, '')
- if not any(e in relative_path for e in exclusions):
- kodi.log("Adding '%s' to archive." % relative_path)
- zip_file.write(absolute_path, relative_path)
- else:
- kodi.log("Excluding '%s' from the archive." % relative_path)
- for file_name in files:
- filen = file_name.replace('\\','/')
- abs_path = os.path.join(r, filen)
- absolute_path = abs_path.replace('\\','/')
- relative_path = absolute_path.replace(true_parent_folder, '')
- if not any(e in relative_path for e in exclusions):
- kodi.log("Adding '%s' to archive." % relative_path)
- dp.update(100, 'Archiving: '+zout,
- '',
- '[B]' + relative_path + '[/B]')
- zip_file.write(absolute_path, relative_path)
- else:
- kodi.log("Excluding '%s' from the archive." % relative_path)
- return True
- except IOError, e:
- kodi.log(str(e))
- return False
- except OSError, e:
- kodi.log(str(e))
- return False
- except zipfile.BadZipfile, e:
- kodi.log(str(e))
- return False
- finally:
- zip_file.close()
Advertisement
Add Comment
Please, Sign In to add comment