From fb2fbe2c0a0f6944696e3f1994a94f1be3ac0535 Mon Sep 17 00:00:00 2001 From: Jorge Araya Navarro Date: Thu, 28 Jun 2012 22:13:26 -0600 Subject: fixing bug #255 as Joar and CWebber ask me to do :) --- mediagoblin/tools/files.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'mediagoblin/tools/files.py') diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py index 25c1a6e6..31a7a972 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 """ + noSuchFiles = [] for listpath in media.media_files.itervalues(): - mg_globals.public_store.delete_file( - listpath) + try: + mg_globals.public_store.delete_file( + listpath) + except OSError: + noSuchFiles.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: + noSuchFiles.append(_jointhat(attachment)) + + if noSuchFiles: + # This breaks pep8 as far as I know + raise OSError, ", ".join(noSuchFiles) -- cgit v1.2.3 From 6d539afda68c5c3b14b744225b6037ce4ea11423 Mon Sep 17 00:00:00 2001 From: Jorge Araya Navarro Date: Thu, 5 Jul 2012 22:07:44 -0600 Subject: changing NoSuchFiles for no_such_files --- mediagoblin/tools/files.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mediagoblin/tools/files.py') diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py index 31a7a972..2b4ad4e4 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -36,21 +36,21 @@ def delete_media_files(media): Arguments: - media: A MediaEntry document """ - noSuchFiles = [] + no_such_files = [] for listpath in media.media_files.itervalues(): try: mg_globals.public_store.delete_file( listpath) except OSError: - noSuchFiles.append(_jointhat(listpath)) + no_such_files.append(_jointhat(listpath)) for attachment in media.attachment_files: try: mg_globals.public_store.delete_file( attachment['filepath']) except OSError: - noSuchFiles.append(_jointhat(attachment)) + no_such_files.append(_jointhat(attachment)) - if noSuchFiles: + if no_such_files: # This breaks pep8 as far as I know raise OSError, ", ".join(noSuchFiles) -- cgit v1.2.3 From a850b1e2a216fe9591cfab56ac56efd6126adb44 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 6 Jul 2012 09:02:24 -0500 Subject: one more noSuchFiles->no_such_files --- mediagoblin/tools/files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/tools/files.py') diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py index 2b4ad4e4..0e8dc1e9 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -53,4 +53,4 @@ def delete_media_files(media): if no_such_files: # This breaks pep8 as far as I know - raise OSError, ", ".join(noSuchFiles) + raise OSError, ", ".join(no_such_files) -- cgit v1.2.3 From 1ec85bb3de52ed67af176b76f0eda29df78c2193 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 6 Jul 2012 09:03:08 -0500 Subject: Removing _jointhat()... not really needed. --- mediagoblin/tools/files.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'mediagoblin/tools/files.py') diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py index 0e8dc1e9..315ff5e0 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -16,18 +16,6 @@ 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): """ @@ -42,14 +30,14 @@ def delete_media_files(media): mg_globals.public_store.delete_file( listpath) except OSError: - no_such_files.append(_jointhat(listpath)) + no_such_files.append("/".join(listpath)) for attachment in media.attachment_files: try: mg_globals.public_store.delete_file( attachment['filepath']) except OSError: - no_such_files.append(_jointhat(attachment)) + no_such_files.append("/".join(attachment)) if no_such_files: # This breaks pep8 as far as I know -- cgit v1.2.3 From 118bafbd815922b759ed619412411878ef8b69f6 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 6 Jul 2012 09:06:01 -0500 Subject: Switching the syntax of this exception-raise It's nicer to raise exceptions like raise Exception("foo") than raise Exception, "foo" --- mediagoblin/tools/files.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mediagoblin/tools/files.py') diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py index 315ff5e0..fd38f05e 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -40,5 +40,4 @@ def delete_media_files(media): no_such_files.append("/".join(attachment)) if no_such_files: - # This breaks pep8 as far as I know - raise OSError, ", ".join(no_such_files) + raise OSError(", ".join(no_such_files)) -- cgit v1.2.3