@@ -140,38 +140,30 @@ def dis_or_enable_addon(addon_id, enable="true"):
140
140
xbmc .log ("### Disabled %s, response = %s" % (addon_id , response ))
141
141
return xbmc .executebuiltin ('Container.Update(%s)' % xbmc .getInfoLabel ('Container.FolderPath' ))
142
142
143
- def zipfolder (foldername , target_dir ):
144
- zipobj = zipfile .ZipFile (foldername + '.zip' , 'w' , zipfile .ZIP_DEFLATED )
145
- rootlen = len (target_dir ) + 1
146
- for base , dirs , files in os .walk (target_dir ):
147
- for file in files :
148
- fn = os .path .join (base , file )
149
- zipobj .write (fn , fn [rootlen :])
150
-
151
- def zipdir (dirPath = None , zipFilePath = None , includeDirInZip = True ):
152
- if not zipFilePath :
153
- zipFilePath = dirPath + ".zip"
154
- if not os .path .isdir (dirPath ):
155
- raise OSError ("dirPath argument must point to a directory. "
156
- "'%s' does not." % dirPath )
157
- parentDir , dirToZip = os .path .split (dirPath )
158
- def trimPath (path ):
159
- archivePath = path .replace (parentDir , "" , 1 )
160
- if parentDir :
161
- archivePath = archivePath .replace (os .path .sep , "" , 1 )
162
- if not includeDirInZip :
163
- archivePath = archivePath .replace (dirToZip + os .path .sep , "" , 1 )
164
- return os .path .normcase (archivePath )
165
- outFile = zipfile .ZipFile (zipFilePath , "w" ,
166
- compression = zipfile .ZIP_DEFLATED )
167
- for (archiveDirPath , dirNames , fileNames ) in os .walk (dirPath ):
168
- for fileName in fileNames :
169
- filePath = os .path .join (archiveDirPath , fileName )
170
- outFile .write (filePath , trimPath (filePath ))
171
- if not fileNames and not dirNames :
172
- zipInfo = zipfile .ZipInfo (trimPath (archiveDirPath ) + "/" )
173
- outFile .writestr (zipInfo , "" )
174
- outFile .close ()
143
+ def ZipDir (inputDir , outputZip ):
144
+ zipOut = zipfile .ZipFile (outputZip , 'w' , compression = zipfile .ZIP_DEFLATED )
145
+ rootLen = len (os .path .dirname (inputDir ))
146
+ def _ArchiveDirectory (parentDirectory ):
147
+ contents = os .listdir (parentDirectory )
148
+ if not contents :
149
+ archiveRoot = parentDirectory [rootLen :].replace ('\\ ' , '/' ).lstrip ('/' )
150
+ zipInfo = zipfile .ZipInfo (archiveRoot + '/' )
151
+ zipOut .writestr (zipInfo , '' )
152
+ for item in contents :
153
+ fullPath = os .path .join (parentDirectory , item )
154
+ if os .path .isdir (fullPath ) and not os .path .islink (fullPath ):
155
+ _ArchiveDirectory (fullPath )
156
+ else :
157
+ archiveRoot = fullPath [rootLen :].replace ('\\ ' , '/' ).lstrip ('/' )
158
+ if os .path .islink (fullPath ):
159
+ zipInfo = zipfile .ZipInfo (archiveRoot )
160
+ zipInfo .create_system = 3
161
+ zipInfo .external_attr = 2716663808L
162
+ zipOut .writestr (zipInfo , os .readlink (fullPath ))
163
+ else :
164
+ zipOut .write (fullPath , archiveRoot , zipfile .ZIP_DEFLATED )
165
+ _ArchiveDirectory (inputDir )
166
+ zipOut .close ()
175
167
176
168
def dvr_param_load (dvr_uuid_sel ):
177
169
dvr_url = 'http://' + tvh_url + ':' + tvh_port + '/api/idnode/load?uuid=' + dvr_uuid_sel
@@ -1709,7 +1701,7 @@ def tvh():
1709
1701
tvh_addon = xbmcaddon .Addon (id = 'service.tvheadend42' )
1710
1702
tvh_userdata_path = xbmc .translatePath (tvh_addon .getAddonInfo ('profile' ))
1711
1703
else :
1712
- tvh_userdata_path = '//' + tvh_url + '/userdata/addon_data/service.tvheadend42'
1704
+ tvh_userdata_path = '//' + tvh_url + '/userdata/addon_data/service.tvheadend42/ '
1713
1705
try :
1714
1706
tvh_json_url = 'http://' + tvh_url + ':8080/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{"addonid":"service.tvheadend42","enabled":false}}'
1715
1707
tvh_json_load = requests .get (tvh_json_url ).json ()
@@ -1719,9 +1711,9 @@ def tvh():
1719
1711
return
1720
1712
if tvh_stop == "OK" :
1721
1713
output_path = dialog .browse (3 , "Where would you like to save the Tvheadend Backup file?" , "files" )
1722
- output_name = output_path + "service.tvheadend42-backup-" + str (datetime .datetime .today ())
1714
+ output_name = output_path + "service.tvheadend42-backup-" + str (datetime .date .today ()) + ".zip"
1723
1715
if dialog .yesno ('Backup Tvheadend Userdata to Zip File' , 'Zip file will be created in the following location:' , str (output_path ), 'Select YES to create backup.' ):
1724
- zipfolder ( output_name , tvh_userdata_path )
1716
+ ZipDir ( tvh_userdata_path , output_name )
1725
1717
dialog .ok ("Tvheadend Userdata Backup Complete" , "Tvheadend userdata has been backed up." , "Tvheadend service will be restarted." )
1726
1718
try :
1727
1719
tvh_json_url = 'http://' + tvh_url + ':8080/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{"addonid":"service.tvheadend42","enabled":true}}'
0 commit comments