Skip to content

Commit 970c502

Browse files
committed
fix local and network paths
1 parent 24528ed commit 970c502

File tree

1 file changed

+27
-35
lines changed

1 file changed

+27
-35
lines changed

default.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -140,38 +140,30 @@ def dis_or_enable_addon(addon_id, enable="true"):
140140
xbmc.log("### Disabled %s, response = %s" % (addon_id, response))
141141
return xbmc.executebuiltin('Container.Update(%s)' % xbmc.getInfoLabel('Container.FolderPath'))
142142

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()
175167

176168
def dvr_param_load(dvr_uuid_sel):
177169
dvr_url = 'http://' + tvh_url + ':' + tvh_port + '/api/idnode/load?uuid=' + dvr_uuid_sel
@@ -1709,7 +1701,7 @@ def tvh():
17091701
tvh_addon = xbmcaddon.Addon(id='service.tvheadend42')
17101702
tvh_userdata_path = xbmc.translatePath(tvh_addon.getAddonInfo('profile'))
17111703
else:
1712-
tvh_userdata_path = '//' + tvh_url + '/userdata/addon_data/service.tvheadend42'
1704+
tvh_userdata_path = '//' + tvh_url + '/userdata/addon_data/service.tvheadend42/'
17131705
try:
17141706
tvh_json_url = 'http://' + tvh_url + ':8080/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{"addonid":"service.tvheadend42","enabled":false}}'
17151707
tvh_json_load = requests.get(tvh_json_url).json()
@@ -1719,9 +1711,9 @@ def tvh():
17191711
return
17201712
if tvh_stop == "OK":
17211713
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"
17231715
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)
17251717
dialog.ok("Tvheadend Userdata Backup Complete", "Tvheadend userdata has been backed up.", "Tvheadend service will be restarted.")
17261718
try:
17271719
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

Comments
 (0)