Skip to content

Commit

Permalink
Dir removal fix, added error handlers for alt file operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandenbroek committed Mar 9, 2016
1 parent 8db47d1 commit 914ddda
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.afterwatch" name="After Watch" version="0.9.3" provider-name="jvandenbroek">
<addon id="script.afterwatch" name="After Watch" version="0.9.4" provider-name="jvandenbroek">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
</requires>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.9.4 (2016-03-09):
* Directory removal fix alternate file method
* Added error handlers for alternate file method operations

0.9.3 (2016-03-08):
* Delete or move all files matching video filename minus the extension.

Expand Down
4 changes: 4 additions & 0 deletions resources/language/English/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@
<string id="30608">No internet connection</string>
<string id="30609">Canceled due to quantity of files</string>
<string id="30610">You do not have permissions to move/delete this file</string>
<string id="30611">Error creating folder</string>
<string id="30612">Error removing folder</string>
<string id="30613">Error removing file</string>
<string id="30614">Error copying</string>
</strings>
24 changes: 16 additions & 8 deletions resources/lib/utilfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,47 +81,55 @@ def __delete_files(source, match, del_empty):

def __copy_directory_alt(source, destination):
destination = os.path.join(destination, os.path.basename(source))
xbmcvfs.mkdirs(destination) # todo error if exists?
if not xbmcvfs.mkdirs(destination):
raise ValueError('xbmcvfs.mkdirs', destination)
dirs, files = xbmcvfs.listdir(source)
for f in files:
src = os.path.join(source, f)
dest = os.path.join(destination, f)
xbmcvfs.copy(src, dest)
if not xbmcvfs.copy(src, dest):
raise ValueError('xbmcvfs.copy', src, dest)
for d in dirs:
d = os.path.join(source, d)
__copy_directory(d, destination)

def __copy_files_alt(source, destination, match):
# create directories if needed
xbmcvfs.mkdirs(destination)
if not xbmcvfs.mkdirs(destination):
raise ValueError('xbmcvfs.mkdirs', destination)
# move files from source to destination if match
dirs, files = xbmcvfs.listdir(source)
for f in files:
if os.path.splitext(f)[0].startswith(match):
src = os.path.join(source, f)
dest = os.path.join(destination, f)
xbmcvfs.copy(src, dest) # todo error
if not xbmcvfs.copy(src, dest):
raise ValueError('xbmcvfs.copy', src, dest)

def __delete_directory_alt(source):
dirs, files = xbmcvfs.listdir(source)
for d in dirs:
d = os.path.join(source, d)
__delete_directory(d)
if not xbmcvfs.rmdir(d):
raise ValueError('xbmcvfs.rmdir', d)
for f in files:
f = os.path.join(source, f)
xbmcvfs.delete(f)
xbmcvfs.rmdir(source)
if not xbmcvfs.rmdir(source):
raise ValueError('xbmcvfs.rmdir', source)

def __delete_files_alt(source, match, del_empty):
# delete files from source if match
dirs, files = xbmcvfs.listdir(source)
for f in files:
if os.path.splitext(f)[0].startswith(match):
f = os.path.join(source, f)
xbmcvfs.delete(f)
if not xbmcvfs.delete(f):
raise ValueError('xbmcvfs.delete', f)
# delete source directory if empty
if del_empty and len(xbmcvfs.listdir(source)) == 0:
xbmcvfs.rmdir(source)
if not xbmcvfs.rmdir(source):
raise ValueError('xbmcvfs.rmdir', source)

## PRIVATE COUNT
def __count_manage_directory(source):
Expand Down
22 changes: 22 additions & 0 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ def dialog_rating(title):
rating = 10 - i
return rating

def ValueErrorHandler(err):
if err[0] == 'xbmcvfs.mkdirs':
log("ValueError Exception: Error creating folder: %s" % err[1])
dialog_error(lang(30611) + ' %s' % err[1])
if err[0] == 'xbmcvfs.rmdir':
log("ValueError Exception: Error removing folder: %s" % err[1])
dialog_error(lang(30612) + ' %s' % err[1])
if err[0] == 'xbmcvfs.delete':
log("ValueError Exception: Error removing file: %s" % err[1])
dialog_error(lang(30613) + ' %s' % err[1])
if err[0] == 'xbmcvfs.copy':
log("ValueError Exception: Error copying %s to %s" % (err[1], err[2]))
dialog_error(lang(30614) + ' %s -> %s' % (err[1], err[2]))

## PROGRESS
class Progress:
def __init__(self, steps):
Expand Down Expand Up @@ -195,6 +209,8 @@ def __move(self, progress):
utilxbmc.set_movie_playcount(self.movieid, self.playcount+1)
except OSError:
dialog_error(lang(30610))
except ValueError as err:
ValueErrorHandler(err)
except Exception, e:
dialog_error(e.message)
finally:
Expand Down Expand Up @@ -227,6 +243,8 @@ def __delete(self, progress):
self.path = None
except OSError:
dialog_error(lang(30610))
except ValueError as err:
ValueErrorHandler(err)
except Exception, e:
dialog_error(e.message)
finally:
Expand Down Expand Up @@ -444,6 +462,8 @@ def __move(self, progress):
utilxbmc.set_episode_playcount(self.episodeid, self.playcount+1)
except OSError:
dialog_error(lang(30610))
except ValueError as err:
ValueErrorHandler(err)
except Exception, e:
dialog_error(e.message)
finally:
Expand All @@ -470,6 +490,8 @@ def __delete(self, progress):
self.path = None
except OSError:
dialog_error(lang(30610))
except ValueError as err:
ValueErrorHandler(err)
except Exception, e:
dialog_error(e.message)
finally:
Expand Down

0 comments on commit 914ddda

Please sign in to comment.