diff options
Diffstat (limited to 'mediagoblin/gmg_commands/addmedia.py')
-rw-r--r-- | mediagoblin/gmg_commands/addmedia.py | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/mediagoblin/gmg_commands/addmedia.py b/mediagoblin/gmg_commands/addmedia.py index 2f095760..babc6ed7 100644 --- a/mediagoblin/gmg_commands/addmedia.py +++ b/mediagoblin/gmg_commands/addmedia.py @@ -14,8 +14,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from __future__ import print_function + import os +import six + +from mediagoblin.db.models import LocalUser from mediagoblin.gmg_commands import util as commands_util from mediagoblin.submit.lib import ( submit_media, get_upload_file_limits, @@ -71,41 +76,41 @@ def addmedia(args): app = commands_util.setup_app(args) # get the user - user = app.db.User.query.filter_by(username=args.username.lower()).first() + user = app.db.LocalUser.query.filter( + LocalUser.username==args.username.lower() + ).first() if user is None: - print "Sorry, no user by username '%s'" % args.username + print("Sorry, no user by username '%s'" % args.username) return - + # check for the file, if it exists... filename = os.path.split(args.filename)[-1] abs_filename = os.path.abspath(args.filename) if not os.path.exists(abs_filename): - print "Can't find a file with filename '%s'" % args.filename + print("Can't find a file with filename '%s'" % args.filename) return - upload_limit, max_file_size = get_upload_file_limits(user) - def maybe_unicodeify(some_string): # this is kinda terrible if some_string is None: return None - else: - return unicode(some_string) + if six.PY2: + return six.text_type(some_string, 'utf-8') + return some_string try: submit_media( mg_app=app, user=user, - submitted_file=file(abs_filename, 'r'), filename=filename, + submitted_file=open(abs_filename, 'rb'), filename=filename, title=maybe_unicodeify(args.title), description=maybe_unicodeify(args.description), collection_slug=args.collection_slug, license=maybe_unicodeify(args.license), - tags_string=maybe_unicodeify(args.tags) or u"", - upload_limit=upload_limit, max_file_size=max_file_size) + tags_string=maybe_unicodeify(args.tags) or u"") except FileUploadLimit: - print "This file is larger than the upload limits for this site." + print("This file is larger than the upload limits for this site.") except UserUploadLimit: - print "This file will put this user past their upload limits." + print("This file will put this user past their upload limits.") except UserPastUploadLimit: - print "This user is already past their upload limits." + print("This user is already past their upload limits.") |