mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
use contextlib
This commit is contained in:
parent
05c53b7ed8
commit
9ecf706d63
@ -508,9 +508,8 @@ class XbmcBackup:
|
|||||||
else:
|
else:
|
||||||
self.xbmc_vfs.put(path + "xbmcbackup.val", xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
|
self.xbmc_vfs.put(path + "xbmcbackup.val", xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
|
||||||
|
|
||||||
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"), 'r')
|
with xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"), 'r') as vFile:
|
||||||
jsonString = vFile.read()
|
jsonString = vFile.read()
|
||||||
vFile.close()
|
|
||||||
|
|
||||||
# delete after checking
|
# delete after checking
|
||||||
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
|
xbmcvfs.delete(xbmc.translatePath(utils.data_dir() + "xbmcbackup_restore.val"))
|
||||||
|
@ -132,9 +132,8 @@ class BackupScheduler:
|
|||||||
utils.log("scheduler will run again on " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run), ['dateshort', 'time']))
|
utils.log("scheduler will run again on " + utils.getRegionalTimestamp(datetime.fromtimestamp(self.next_run), ['dateshort', 'time']))
|
||||||
|
|
||||||
# write the next time to a file
|
# write the next time to a file
|
||||||
fh = xbmcvfs.File(self.next_run_path, 'w')
|
with xbmcvfs.File(self.next_run_path, 'w') as fh:
|
||||||
fh.write(str(self.next_run))
|
fh.write(str(self.next_run))
|
||||||
fh.close()
|
|
||||||
|
|
||||||
# only show when not in silent mode
|
# only show when not in silent mode
|
||||||
if(progress_mode != 2):
|
if(progress_mode != 2):
|
||||||
|
@ -86,9 +86,8 @@ class XBMCFileSystem(Vfs):
|
|||||||
return xbmcvfs.exists(aFile)
|
return xbmcvfs.exists(aFile)
|
||||||
|
|
||||||
def fileSize(self, filename):
|
def fileSize(self, filename):
|
||||||
f = xbmcvfs.File(filename)
|
with xbmcvfs.File(filename) as f:
|
||||||
result = f.size() / 1024 # bytes to kilobytes
|
result = f.size() / 1024 # bytes to kilobytes
|
||||||
f.close()
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user