aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/gmg_commands
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/gmg_commands')
-rw-r--r--mediagoblin/gmg_commands/__init__.py4
-rw-r--r--mediagoblin/gmg_commands/addmedia.py105
-rw-r--r--mediagoblin/gmg_commands/dbupdate.py10
-rw-r--r--mediagoblin/gmg_commands/users.py18
4 files changed, 128 insertions, 9 deletions
diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py
index 165a76fd..a1eb599d 100644
--- a/mediagoblin/gmg_commands/__init__.py
+++ b/mediagoblin/gmg_commands/__init__.py
@@ -49,6 +49,10 @@ SUBCOMMAND_MAP = {
'setup': 'mediagoblin.gmg_commands.reprocess:reprocess_parser_setup',
'func': 'mediagoblin.gmg_commands.reprocess:reprocess',
'help': 'Reprocess media entries'},
+ 'addmedia': {
+ 'setup': 'mediagoblin.gmg_commands.addmedia:parser_setup',
+ 'func': 'mediagoblin.gmg_commands.addmedia:addmedia',
+ 'help': 'Reprocess media entries'},
# 'theme': {
# 'setup': 'mediagoblin.gmg_commands.theme:theme_parser_setup',
# 'func': 'mediagoblin.gmg_commands.theme:theme',
diff --git a/mediagoblin/gmg_commands/addmedia.py b/mediagoblin/gmg_commands/addmedia.py
new file mode 100644
index 00000000..c33a8c56
--- /dev/null
+++ b/mediagoblin/gmg_commands/addmedia.py
@@ -0,0 +1,105 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# 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
+# 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 <http://www.gnu.org/licenses/>.
+
+import os
+
+from mediagoblin.gmg_commands import util as commands_util
+from mediagoblin.submit.lib import (
+ submit_media, get_upload_file_limits,
+ FileUploadLimit, UserUploadLimit, UserPastUploadLimit)
+
+from mediagoblin import mg_globals
+
+
+def parser_setup(subparser):
+ subparser.add_argument(
+ 'username',
+ help="Name of user this media entry belongs to")
+ subparser.add_argument(
+ 'filename',
+ help="Local file on filesystem")
+ subparser.add_argument(
+ "-d", "--description",
+ help="Description for this media entry")
+ subparser.add_argument(
+ "-t", "--title",
+ help="Title for this media entry")
+ subparser.add_argument(
+ "-l", "--license",
+ help=(
+ "License this media entry will be released under. "
+ "Should be a URL."))
+ subparser.add_argument(
+ "-T", "--tags",
+ help=(
+ "Comma separated list of tags for this media entry."))
+ subparser.add_argument(
+ "-s", "--slug",
+ help=(
+ "Slug for this media entry. "
+ "Will be autogenerated if unspecified."))
+
+ subparser.add_argument(
+ '--celery',
+ action='store_true',
+ help="Don't process eagerly, pass off to celery")
+
+
+def addmedia(args):
+ # Run eagerly unless explicetly set not to
+ if not args.celery:
+ os.environ['CELERY_ALWAYS_EAGER'] = 'true'
+
+ app = commands_util.setup_app(args)
+
+ # get the user
+ user = app.db.User.query.filter_by(username=args.username.lower()).first()
+ if user is None:
+ 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
+ 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)
+
+ try:
+ submit_media(
+ mg_app=app,
+ user=user,
+ submitted_file=file(abs_filename, 'r'), filename=filename,
+ title=maybe_unicodeify(args.title),
+ description=maybe_unicodeify(args.description),
+ license=maybe_unicodeify(args.license),
+ tags_string=maybe_unicodeify(args.tags) or u"",
+ upload_limit=upload_limit, max_file_size=max_file_size)
+ except FileUploadLimit:
+ 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."
+ except UserPastUploadLimit:
+ print "This user is already past their upload limits."
diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py
index 77eaf01d..27283a20 100644
--- a/mediagoblin/gmg_commands/dbupdate.py
+++ b/mediagoblin/gmg_commands/dbupdate.py
@@ -24,6 +24,10 @@ from mediagoblin.init import setup_global_and_app_config
from mediagoblin.tools.common import import_component
_log = logging.getLogger(__name__)
+logging.basicConfig()
+## Let's not set the level as debug by default to avoid confusing users :)
+# _log.setLevel(logging.DEBUG)
+
def dbupdate_parse_setup(subparser):
pass
@@ -90,14 +94,8 @@ forgotten to add it? ({1})'.format(plugin, exc))
try:
foundations = import_component('{0}.models:FOUNDATIONS'.format(plugin))
except ImportError as exc:
- _log.debug('No foundations found for {0}: {1}'.format(
- plugin,
- exc))
-
foundations = {}
except AttributeError as exc:
- _log.debug('Could not find FOUNDATIONS in {0}.models, have you \
-forgotten to add it? ({1})'.format(plugin, exc))
foundations = {}
if models:
diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py
index e44b0aa9..4a730d9e 100644
--- a/mediagoblin/gmg_commands/users.py
+++ b/mediagoblin/gmg_commands/users.py
@@ -53,8 +53,17 @@ def adduser(args):
entry.username = unicode(args.username.lower())
entry.email = unicode(args.email)
entry.pw_hash = auth.gen_password_hash(args.password)
- entry.status = u'active'
- entry.email_verified = True
+ default_privileges = [
+ db.Privilege.query.filter(
+ db.Privilege.privilege_name==u'commenter').one(),
+ db.Privilege.query.filter(
+ db.Privilege.privilege_name==u'uploader').one(),
+ db.Privilege.query.filter(
+ db.Privilege.privilege_name==u'reporter').one(),
+ db.Privilege.query.filter(
+ db.Privilege.privilege_name==u'active').one()
+ ]
+ entry.all_privileges = default_privileges
entry.save()
print "User created (and email marked as verified)"
@@ -74,7 +83,10 @@ def makeadmin(args):
user = db.User.query.filter_by(
username=unicode(args.username.lower())).one()
if user:
- user.is_admin = True
+ user.all_privileges.append(
+ db.Privilege.query.filter(
+ db.Privilege.privilege_name==u'admin').one()
+ )
user.save()
print 'The user is now Admin'
else: