Merge branch 'merge-python3-port'
Conflicts: setup.py
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import six
|
||||
|
||||
from mediagoblin.tools.common import import_component
|
||||
|
||||
|
||||
@@ -61,6 +63,10 @@ SUBCOMMAND_MAP = {
|
||||
'setup': 'mediagoblin.gmg_commands.deletemedia:parser_setup',
|
||||
'func': 'mediagoblin.gmg_commands.deletemedia:deletemedia',
|
||||
'help': 'Delete media entries'},
|
||||
'serve': {
|
||||
'setup': 'mediagoblin.gmg_commands.serve:parser_setup',
|
||||
'func': 'mediagoblin.gmg_commands.serve:serve',
|
||||
'help': 'PasteScript replacement'},
|
||||
'batchaddmedia': {
|
||||
'setup': 'mediagoblin.gmg_commands.batchaddmedia:parser_setup',
|
||||
'func': 'mediagoblin.gmg_commands.batchaddmedia:batchaddmedia',
|
||||
@@ -98,7 +104,7 @@ def main_cli():
|
||||
"otherwise mediagoblin.ini"))
|
||||
|
||||
subparsers = parser.add_subparsers(help='sub-command help')
|
||||
for command_name, command_struct in SUBCOMMAND_MAP.iteritems():
|
||||
for command_name, command_struct in six.iteritems(SUBCOMMAND_MAP):
|
||||
if 'help' in command_struct:
|
||||
subparser = subparsers.add_parser(
|
||||
command_name, help=command_struct['help'])
|
||||
|
||||
@@ -14,8 +14,12 @@
|
||||
# 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.gmg_commands import util as commands_util
|
||||
from mediagoblin.submit.lib import (
|
||||
submit_media, get_upload_file_limits,
|
||||
@@ -68,14 +72,14 @@ def addmedia(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
|
||||
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)
|
||||
@@ -85,21 +89,21 @@ def addmedia(args):
|
||||
if some_string is None:
|
||||
return None
|
||||
else:
|
||||
return unicode(some_string)
|
||||
return six.text_type(some_string)
|
||||
|
||||
try:
|
||||
submit_media(
|
||||
mg_app=app,
|
||||
user=user,
|
||||
submitted_file=file(abs_filename, 'r'), filename=filename,
|
||||
submitted_file=open(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."
|
||||
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.")
|
||||
|
||||
@@ -19,7 +19,7 @@ import logging
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from mediagoblin.db.open import setup_connection_and_db_from_config
|
||||
from mediagoblin.db.migration_tools import MigrationManager
|
||||
from mediagoblin.db.migration_tools import MigrationManager, AlembicMigrationManager
|
||||
from mediagoblin.init import setup_global_and_app_config
|
||||
from mediagoblin.tools.common import import_component
|
||||
|
||||
@@ -106,6 +106,13 @@ forgotten to add it? ({1})'.format(plugin, exc))
|
||||
return managed_dbdata
|
||||
|
||||
|
||||
def run_alembic_migrations(db, app_config, global_config):
|
||||
"""Initializes a database and runs all Alembic migrations."""
|
||||
Session = sessionmaker(bind=db.engine)
|
||||
manager = AlembicMigrationManager(Session())
|
||||
manager.init_or_migrate()
|
||||
|
||||
|
||||
def run_dbupdate(app_config, global_config):
|
||||
"""
|
||||
Initialize or migrate the database as specified by the config file.
|
||||
@@ -116,8 +123,9 @@ def run_dbupdate(app_config, global_config):
|
||||
|
||||
# Set up the database
|
||||
db = setup_connection_and_db_from_config(app_config, migrations=True)
|
||||
#Run the migrations
|
||||
# Run the migrations
|
||||
run_all_migrations(db, app_config, global_config)
|
||||
run_alembic_migrations(db, app_config, global_config)
|
||||
|
||||
|
||||
def run_all_migrations(db, app_config, global_config):
|
||||
@@ -131,7 +139,7 @@ def run_all_migrations(db, app_config, global_config):
|
||||
"""
|
||||
# Gather information from all media managers / projects
|
||||
dbdatas = gather_database_data(
|
||||
global_config.get('plugins', {}).keys())
|
||||
list(global_config.get('plugins', {}).keys()))
|
||||
|
||||
Session = sessionmaker(bind=db.engine)
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
# 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 sys
|
||||
|
||||
from mediagoblin.gmg_commands import util as commands_util
|
||||
@@ -37,8 +38,8 @@ def deletemedia(args):
|
||||
for media in medias:
|
||||
found_medias.add(media.id)
|
||||
media.delete()
|
||||
print 'Media ID %d has been deleted.' % media.id
|
||||
print('Media ID %d has been deleted.' % media.id)
|
||||
for media in media_ids - found_medias:
|
||||
print 'Can\'t find a media with ID %d.' % media
|
||||
print 'Done.'
|
||||
print('Can\'t find a media with ID %d.' % media)
|
||||
print('Done.')
|
||||
sys.exit(0)
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#
|
||||
# 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 argparse
|
||||
import os
|
||||
|
||||
@@ -143,7 +146,7 @@ def available(args):
|
||||
manager = get_processing_manager_for_type(media_type)
|
||||
except ProcessingManagerDoesNotExist:
|
||||
entry = MediaEntry.query.filter_by(id=args.id_or_type).first()
|
||||
print 'No such processing manager for {0}'.format(entry.media_type)
|
||||
print('No such processing manager for {0}'.format(entry.media_type))
|
||||
|
||||
if args.state:
|
||||
processors = manager.list_all_processors_by_state(args.state)
|
||||
@@ -152,25 +155,25 @@ def available(args):
|
||||
else:
|
||||
processors = manager.list_eligible_processors(media_entry)
|
||||
|
||||
print "Available processors:"
|
||||
print "====================="
|
||||
print ""
|
||||
print("Available processors:")
|
||||
print("=====================")
|
||||
print("")
|
||||
|
||||
if args.action_help:
|
||||
for processor in processors:
|
||||
print processor.name
|
||||
print "-" * len(processor.name)
|
||||
print(processor.name)
|
||||
print("-" * len(processor.name))
|
||||
|
||||
parser = processor.generate_parser()
|
||||
parser.print_help()
|
||||
print ""
|
||||
print("")
|
||||
|
||||
else:
|
||||
for processor in processors:
|
||||
if processor.description:
|
||||
print " - %s: %s" % (processor.name, processor.description)
|
||||
print(" - %s: %s" % (processor.name, processor.description))
|
||||
else:
|
||||
print " - %s" % processor.name
|
||||
print(" - %s" % processor.name)
|
||||
|
||||
|
||||
def run(args, media_id=None):
|
||||
@@ -185,12 +188,12 @@ def run(args, media_id=None):
|
||||
processor_class = manager.get_processor(
|
||||
args.reprocess_command, media_entry)
|
||||
except ProcessorDoesNotExist:
|
||||
print 'No such processor "%s" for media with id "%s"' % (
|
||||
args.reprocess_command, media_entry.id)
|
||||
print('No such processor "%s" for media with id "%s"' % (
|
||||
args.reprocess_command, media_entry.id))
|
||||
return
|
||||
except ProcessorNotEligible:
|
||||
print 'Processor "%s" exists but media "%s" is not eligible' % (
|
||||
args.reprocess_command, media_entry.id)
|
||||
print('Processor "%s" exists but media "%s" is not eligible' % (
|
||||
args.reprocess_command, media_entry.id))
|
||||
return
|
||||
|
||||
reprocess_parser = processor_class.generate_parser()
|
||||
@@ -203,7 +206,7 @@ def run(args, media_id=None):
|
||||
|
||||
except ProcessingManagerDoesNotExist:
|
||||
entry = MediaEntry.query.filter_by(id=media_id).first()
|
||||
print 'No such processing manager for {0}'.format(entry.media_type)
|
||||
print('No such processing manager for {0}'.format(entry.media_type))
|
||||
|
||||
|
||||
def bulk_run(args):
|
||||
@@ -233,12 +236,12 @@ def thumbs(args):
|
||||
processor_class = manager.get_processor(
|
||||
'resize', media_entry)
|
||||
except ProcessorDoesNotExist:
|
||||
print 'No such processor "%s" for media with id "%s"' % (
|
||||
'resize', media_entry.id)
|
||||
print('No such processor "%s" for media with id "%s"' % (
|
||||
'resize', media_entry.id))
|
||||
return
|
||||
except ProcessorNotEligible:
|
||||
print 'Processor "%s" exists but media "%s" is not eligible' % (
|
||||
'resize', media_entry.id)
|
||||
print('Processor "%s" exists but media "%s" is not eligible' % (
|
||||
'resize', media_entry.id))
|
||||
return
|
||||
|
||||
reprocess_parser = processor_class.generate_parser()
|
||||
@@ -260,7 +263,7 @@ def thumbs(args):
|
||||
reprocess_info=reprocess_request)
|
||||
|
||||
except ProcessingManagerDoesNotExist:
|
||||
print 'No such processing manager for {0}'.format(entry.media_type)
|
||||
print('No such processing manager for {0}'.format(entry.media_type))
|
||||
|
||||
|
||||
def initial(args):
|
||||
@@ -276,7 +279,7 @@ def initial(args):
|
||||
media_entry,
|
||||
reprocess_action='initial')
|
||||
except ProcessingManagerDoesNotExist:
|
||||
print 'No such processing manager for {0}'.format(entry.media_type)
|
||||
print('No such processing manager for {0}'.format(entry.media_type))
|
||||
|
||||
|
||||
def reprocess(args):
|
||||
|
||||
66
mediagoblin/gmg_commands/serve.py
Normal file
66
mediagoblin/gmg_commands/serve.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# 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/>.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from paste.deploy import loadapp, loadserver
|
||||
|
||||
|
||||
class ServeCommand(object):
|
||||
|
||||
def loadserver(self, server_spec, name, relative_to, **kwargs):
|
||||
return loadserver(server_spec, name=name, relative_to=relative_to,
|
||||
**kwargs)
|
||||
|
||||
def loadapp(self, app_spec, name, relative_to, **kwargs):
|
||||
return loadapp(app_spec, name=name, relative_to=relative_to, **kwargs)
|
||||
|
||||
def daemonize(self):
|
||||
# TODO: pass to gunicorn if available
|
||||
pass
|
||||
|
||||
def restart_with_reloader(self):
|
||||
pass
|
||||
|
||||
def restart_with_monitor(self, reloader=False):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
print('Running...')
|
||||
|
||||
|
||||
def parser_setup(subparser):
|
||||
subparser.add_argument('config', metavar='CONFIG_FILE')
|
||||
subparser.add_argument('command',
|
||||
choices=['start', 'stop', 'restart', 'status'],
|
||||
nargs='?', default='start')
|
||||
subparser.add_argument('-n', '--app-name',
|
||||
dest='app_name',
|
||||
metavar='NAME',
|
||||
help="Load the named application (default main)")
|
||||
subparser.add_argument('-s', '--server',
|
||||
dest='server',
|
||||
metavar='SERVER_TYPE',
|
||||
help="Use the named server.")
|
||||
subparser.add_argument('--reload',
|
||||
dest='reload',
|
||||
action='store_true',
|
||||
help="Use auto-restart file monitor")
|
||||
|
||||
|
||||
def serve(args):
|
||||
serve_cmd = ServeCommand() # TODO: pass args to it
|
||||
serve_cmd.run()
|
||||
@@ -14,6 +14,10 @@
|
||||
# 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 six
|
||||
|
||||
from mediagoblin.gmg_commands import util as commands_util
|
||||
from mediagoblin import auth
|
||||
from mediagoblin import mg_globals
|
||||
@@ -45,13 +49,13 @@ def adduser(args):
|
||||
).count()
|
||||
|
||||
if users_with_username:
|
||||
print u'Sorry, a user with that name already exists.'
|
||||
print(u'Sorry, a user with that name already exists.')
|
||||
|
||||
else:
|
||||
# Create the user
|
||||
entry = db.User()
|
||||
entry.username = args.username.lower()
|
||||
entry.email = unicode(args.email)
|
||||
entry.username = six.text_type(args.username.lower())
|
||||
entry.email = six.text_type(args.email)
|
||||
entry.pw_hash = auth.gen_password_hash(args.password)
|
||||
default_privileges = [
|
||||
db.Privilege.query.filter(
|
||||
@@ -66,7 +70,7 @@ def adduser(args):
|
||||
entry.all_privileges = default_privileges
|
||||
entry.save()
|
||||
|
||||
print "User created (and email marked as verified)"
|
||||
print(u"User created (and email marked as verified)")
|
||||
|
||||
|
||||
def makeadmin_parser_setup(subparser):
|
||||
@@ -81,16 +85,16 @@ def makeadmin(args):
|
||||
db = mg_globals.database
|
||||
|
||||
user = db.User.query.filter_by(
|
||||
username=unicode(args.username.lower())).one()
|
||||
username=six.text_type(args.username.lower())).one()
|
||||
if user:
|
||||
user.all_privileges.append(
|
||||
db.Privilege.query.filter(
|
||||
db.Privilege.privilege_name==u'admin').one()
|
||||
)
|
||||
user.save()
|
||||
print 'The user is now Admin'
|
||||
print(u'The user is now Admin')
|
||||
else:
|
||||
print 'The user doesn\'t exist'
|
||||
print(u'The user doesn\'t exist')
|
||||
|
||||
|
||||
def changepw_parser_setup(subparser):
|
||||
@@ -108,13 +112,13 @@ def changepw(args):
|
||||
db = mg_globals.database
|
||||
|
||||
user = db.User.query.filter_by(
|
||||
username=unicode(args.username.lower())).one()
|
||||
username=six.text_type(args.username.lower())).one()
|
||||
if user:
|
||||
user.pw_hash = auth.gen_password_hash(args.password)
|
||||
user.save()
|
||||
print 'Password successfully changed'
|
||||
print(u'Password successfully changed')
|
||||
else:
|
||||
print 'The user doesn\'t exist'
|
||||
print(u'The user doesn\'t exist')
|
||||
|
||||
|
||||
def deleteuser_parser_setup(subparser):
|
||||
@@ -132,6 +136,6 @@ def deleteuser(args):
|
||||
username=unicode(args.username.lower())).first()
|
||||
if user:
|
||||
user.delete()
|
||||
print 'The user %s has been deleted' % args.username
|
||||
print('The user %s has been deleted' % args.username)
|
||||
else:
|
||||
print 'The user %s doesn\'t exist' % args.username
|
||||
print('The user %s doesn\'t exist' % args.username)
|
||||
|
||||
Reference in New Issue
Block a user