aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/files.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2012-07-06 08:52:35 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2012-07-06 08:52:35 -0500
commit46583ff4e695abe9734a18af6726354e8173ab40 (patch)
treed3b078cc484cb55aefd53c64e27d6ef892222e9b /mediagoblin/tools/files.py
parentf2e3a6a01c2a8c63064152fd92d58b4903222d18 (diff)
parent6d539afda68c5c3b14b744225b6037ce4ea11423 (diff)
downloadmediagoblin-46583ff4e695abe9734a18af6726354e8173ab40.tar.lz
mediagoblin-46583ff4e695abe9734a18af6726354e8173ab40.tar.xz
mediagoblin-46583ff4e695abe9734a18af6726354e8173ab40.zip
Merge remote-tracking branch 'refs/remotes/merge-requests/37'
Diffstat (limited to 'mediagoblin/tools/files.py')
-rw-r--r--mediagoblin/tools/files.py32
1 files changed, 28 insertions, 4 deletions
diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py
index 25c1a6e6..2b4ad4e4 100644
--- a/mediagoblin/tools/files.py
+++ b/mediagoblin/tools/files.py
@@ -16,6 +16,19 @@
from mediagoblin import mg_globals
+import os
+
+def _jointhat(thing):
+ if type(thing) == type(list()) or\
+ type(thing) == type(tuple()):
+ filepath = ""
+ for item in thing:
+ filepath = os.path.join(filepath, item)
+ return filepath
+ else:
+ raise TypeError, "expecting a list or tuple, {0} received".format(
+ str(type(thing)))
+
def delete_media_files(media):
"""
Delete all files associated with a MediaEntry
@@ -23,10 +36,21 @@ def delete_media_files(media):
Arguments:
- media: A MediaEntry document
"""
+ no_such_files = []
for listpath in media.media_files.itervalues():
- mg_globals.public_store.delete_file(
- listpath)
+ try:
+ mg_globals.public_store.delete_file(
+ listpath)
+ except OSError:
+ no_such_files.append(_jointhat(listpath))
for attachment in media.attachment_files:
- mg_globals.public_store.delete_file(
- attachment['filepath'])
+ try:
+ mg_globals.public_store.delete_file(
+ attachment['filepath'])
+ except OSError:
+ no_such_files.append(_jointhat(attachment))
+
+ if no_such_files:
+ # This breaks pep8 as far as I know
+ raise OSError, ", ".join(noSuchFiles)