From 03ae172a60a87625e5281eb9766aa5bf3e37d0f4 Mon Sep 17 00:00:00 2001 From: Aaron Williamson Date: Sat, 1 Oct 2011 18:05:17 -0400 Subject: Finished splitting util.py into separate files. --- mediagoblin/tools/files.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 mediagoblin/tools/files.py (limited to 'mediagoblin/tools/files.py') diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py new file mode 100644 index 00000000..e0bf0569 --- /dev/null +++ b/mediagoblin/tools/files.py @@ -0,0 +1,32 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from mediagoblin import mg_globals + +def delete_media_files(media): + """ + Delete all files associated with a MediaEntry + + Arguments: + - media: A MediaEntry document + """ + for listpath in media['media_files'].itervalues(): + mg_globals.public_store.delete_file( + listpath) + + for attachment in media['attachment_files']: + mg_globals.public_store.delete_file( + attachment['filepath']) -- cgit v1.2.3 From 228c4470f40d66e8b9383321d44d89e2a1c0ecad Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 4 Jan 2012 11:57:08 +0100 Subject: Dot-Notation for MediaEntry.media_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 e0bf0569..10f1d994 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -23,7 +23,7 @@ def delete_media_files(media): Arguments: - media: A MediaEntry document """ - for listpath in media['media_files'].itervalues(): + for listpath in media.media_files.itervalues(): mg_globals.public_store.delete_file( listpath) -- cgit v1.2.3 From cf29e8a824e0ef4612f1144f079c80c1d20b89e5 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 2 Feb 2012 09:44:13 -0600 Subject: It's 2012 all up in here --- 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 10f1d994..b2f316b2 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by -- cgit v1.2.3 From 3502958113c09c80830b7bee63c3d82b5ff72eb9 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 25 Feb 2012 23:53:11 +0100 Subject: Attachment support in the SQL backend attachments working with the sql backend. - SQL Schema for attachment files, ordering attachments by their name, not by the submission order (as earlier). - Dot-Notation for attachments, where missing. - convert existing attachments over from mongo -> sql --- 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 b2f316b2..25c1a6e6 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -27,6 +27,6 @@ def delete_media_files(media): mg_globals.public_store.delete_file( listpath) - for attachment in media['attachment_files']: + for attachment in media.attachment_files: mg_globals.public_store.delete_file( attachment['filepath']) -- cgit v1.2.3 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 From df5b142ab9bfc590f17768079104f6cfa2cd7bba Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 18 Feb 2013 14:46:28 +0100 Subject: Fix deleting media with attachments. If one deletes a media with attachments, there have been various problems: 1) If the file in the storage did not exist any more (maybe because due to a previous deletion attempt?), the error propagation failed, because the wrong thing was gathered. 2) The attachment database entries were not deleted. Using cascade for this, for now. Also add a simple unit test, that tests both by having a broken attachment on a media. --- 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 fd38f05e..848c86f2 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -37,7 +37,7 @@ def delete_media_files(media): mg_globals.public_store.delete_file( attachment['filepath']) except OSError: - no_such_files.append("/".join(attachment)) + no_such_files.append("/".join(attachment['filepath'])) if no_such_files: raise OSError(", ".join(no_such_files)) -- cgit v1.2.3