aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/gmg_commands
diff options
context:
space:
mode:
authorBen Sturmfels <ben@sturm.com.au>2021-03-05 23:12:19 +1100
committerBen Sturmfels <ben@sturm.com.au>2021-03-05 23:12:19 +1100
commitdec47c7102cf0aa3a4debf002928db8e460c0d71 (patch)
tree47631fc15c7af172aa699506adf3d76d3a71976c /mediagoblin/gmg_commands
parent5f3a782fef4855e10b7259624a14d8afb0f7be93 (diff)
downloadmediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.tar.lz
mediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.tar.xz
mediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.zip
Apply `pyupgrade --py3-plus` to remove Python 2 compatibility code.
Diffstat (limited to 'mediagoblin/gmg_commands')
-rw-r--r--mediagoblin/gmg_commands/__init__.py2
-rw-r--r--mediagoblin/gmg_commands/addmedia.py5
-rw-r--r--mediagoblin/gmg_commands/alembic_commands.py2
-rw-r--r--mediagoblin/gmg_commands/assetlink.py4
-rw-r--r--mediagoblin/gmg_commands/batchaddmedia.py5
-rw-r--r--mediagoblin/gmg_commands/dbupdate.py26
-rw-r--r--mediagoblin/gmg_commands/deletemedia.py3
-rw-r--r--mediagoblin/gmg_commands/reprocess.py21
-rw-r--r--mediagoblin/gmg_commands/serve.py3
-rw-r--r--mediagoblin/gmg_commands/users.py35
-rw-r--r--mediagoblin/gmg_commands/util.py4
11 files changed, 52 insertions, 58 deletions
diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py
index 0034fd98..963c3952 100644
--- a/mediagoblin/gmg_commands/__init__.py
+++ b/mediagoblin/gmg_commands/__init__.py
@@ -101,7 +101,7 @@ def main_cli():
"otherwise mediagoblin.ini"))
subparsers = parser.add_subparsers(help='sub-command help')
- for command_name, command_struct in six.iteritems(SUBCOMMAND_MAP):
+ for command_name, command_struct in SUBCOMMAND_MAP.items():
if 'help' in command_struct:
subparser = subparsers.add_parser(
command_name, help=command_struct['help'])
diff --git a/mediagoblin/gmg_commands/addmedia.py b/mediagoblin/gmg_commands/addmedia.py
index 026f3495..fbec7071 100644
--- a/mediagoblin/gmg_commands/addmedia.py
+++ b/mediagoblin/gmg_commands/addmedia.py
@@ -14,7 +14,6 @@
# 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
@@ -95,7 +94,7 @@ def addmedia(args):
if some_string is None:
return None
if six.PY2:
- return six.text_type(some_string, 'utf-8')
+ return str(some_string, 'utf-8')
return some_string
try:
@@ -107,7 +106,7 @@ def addmedia(args):
description=maybe_unicodeify(args.description),
collection_slug=args.collection_slug,
license=maybe_unicodeify(args.license),
- tags_string=maybe_unicodeify(args.tags) or u"")
+ tags_string=maybe_unicodeify(args.tags) or "")
except FileUploadLimit:
print("This file is larger than the upload limits for this site.")
except UserUploadLimit:
diff --git a/mediagoblin/gmg_commands/alembic_commands.py b/mediagoblin/gmg_commands/alembic_commands.py
index 4e73ec13..f5f982d1 100644
--- a/mediagoblin/gmg_commands/alembic_commands.py
+++ b/mediagoblin/gmg_commands/alembic_commands.py
@@ -35,7 +35,7 @@ class FudgedCommandLine(config.CommandLine):
plugins = global_config.get('plugins', {}).keys()
for plugin in plugins:
try:
- import_component('{0}.models:MODELS'.format(plugin))
+ import_component('{}.models:MODELS'.format(plugin))
except ImportError:
# It doesn't really matter if there's no models to import
# here.
diff --git a/mediagoblin/gmg_commands/assetlink.py b/mediagoblin/gmg_commands/assetlink.py
index 148ebe9e..2f54808e 100644
--- a/mediagoblin/gmg_commands/assetlink.py
+++ b/mediagoblin/gmg_commands/assetlink.py
@@ -85,7 +85,7 @@ def link_theme_assets(theme, link_dir, printer=simple_printer):
os.symlink(
theme['assets_dir'].rstrip(os.path.sep),
link_dir)
- printer("Linked the theme's asset directory:\n %s\nto:\n %s\n" % (
+ printer("Linked the theme's asset directory:\n {}\nto:\n {}\n".format(
theme['assets_dir'], link_dir))
@@ -128,7 +128,7 @@ def link_plugin_assets(plugin_static, plugins_link_dir, printer=simple_printer):
os.symlink(
plugin_static.file_path.rstrip(os.path.sep),
link_dir)
- printer('Linked asset directory for plugin "%s":\n %s\nto:\n %s\n' % (
+ printer('Linked asset directory for plugin "{}":\n {}\nto:\n {}\n'.format(
plugin_static.name,
plugin_static.file_path.rstrip(os.path.sep),
link_dir))
diff --git a/mediagoblin/gmg_commands/batchaddmedia.py b/mediagoblin/gmg_commands/batchaddmedia.py
index 88fa3e5a..86c9425f 100644
--- a/mediagoblin/gmg_commands/batchaddmedia.py
+++ b/mediagoblin/gmg_commands/batchaddmedia.py
@@ -14,7 +14,6 @@
# 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, unicode_literals
import csv
import os
@@ -84,7 +83,7 @@ def batchaddmedia(args):
abs_metadata_filename = os.path.abspath(metadata_path)
abs_metadata_dir = os.path.dirname(abs_metadata_filename)
- all_metadata = open(abs_metadata_filename, 'r')
+ all_metadata = open(abs_metadata_filename)
media_metadata = csv.DictReader(all_metadata)
for index, file_metadata in enumerate(media_metadata):
if six.PY2:
@@ -159,7 +158,7 @@ Metadata was not uploaded.""".format(
file_abs_path = os.path.abspath(file_path)
try:
media_file = open(file_abs_path, 'rb')
- except IOError:
+ except OSError:
print(_("""\
FAIL: Local file {filename} could not be accessed.
{filename} will not be uploaded.""".format(filename=filename)))
diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py
index 2700ccbc..988c0e26 100644
--- a/mediagoblin/gmg_commands/dbupdate.py
+++ b/mediagoblin/gmg_commands/dbupdate.py
@@ -36,7 +36,7 @@ def dbupdate_parse_setup(subparser):
pass
-class DatabaseData(object):
+class DatabaseData:
def __init__(self, name, models, migrations):
self.name = name
self.models = models
@@ -64,34 +64,34 @@ def gather_database_data(plugins):
managed_dbdata.append(
DatabaseData(
- u'__main__', MAIN_MODELS, MAIN_MIGRATIONS))
+ '__main__', MAIN_MODELS, MAIN_MIGRATIONS))
for plugin in plugins:
try:
- models = import_component('{0}.models:MODELS'.format(plugin))
+ models = import_component('{}.models:MODELS'.format(plugin))
except ImportError as exc:
- _log.debug('No models found for {0}: {1}'.format(
+ _log.debug('No models found for {}: {}'.format(
plugin,
exc))
models = []
except AttributeError as exc:
- _log.warning('Could not find MODELS in {0}.models, have you '
- 'forgotten to add it? ({1})'.format(plugin, exc))
+ _log.warning('Could not find MODELS in {}.models, have you '
+ 'forgotten to add it? ({})'.format(plugin, exc))
models = []
try:
- migrations = import_component('{0}.migrations:MIGRATIONS'.format(
+ migrations = import_component('{}.migrations:MIGRATIONS'.format(
plugin))
except ImportError as exc:
- _log.debug('No migrations found for {0}: {1}'.format(
+ _log.debug('No migrations found for {}: {}'.format(
plugin,
exc))
migrations = {}
except AttributeError as exc:
- _log.debug('Could not find MIGRATIONS in {0}.migrations, have you'
- 'forgotten to add it? ({1})'.format(plugin, exc))
+ _log.debug('Could not find MIGRATIONS in {}.migrations, have you'
+ 'forgotten to add it? ({})'.format(plugin, exc))
migrations = {}
if models:
@@ -106,7 +106,7 @@ def run_foundations(db, global_config):
Gather foundations data and run it.
"""
from mediagoblin.db.models import FOUNDATIONS as MAIN_FOUNDATIONS
- all_foundations = [(u"__main__", MAIN_FOUNDATIONS)]
+ all_foundations = [("__main__", MAIN_FOUNDATIONS)]
Session = sessionmaker(bind=db.engine)
session = Session()
@@ -116,7 +116,7 @@ def run_foundations(db, global_config):
for plugin in plugins:
try:
foundations = import_component(
- '{0}.models:FOUNDATIONS'.format(plugin))
+ '{}.models:FOUNDATIONS'.format(plugin))
all_foundations.append((plugin, foundations))
except ImportError as exc:
continue
@@ -215,7 +215,7 @@ def sqam_migrations_to_run(db, app_config, global_config):
# was never installed with any migrations
from mediagoblin.db.models import MigrationData
if Session().query(MigrationData).filter_by(
- name=u"__main__").first() is None:
+ name="__main__").first() is None:
return False
# Setup media managers for all dbdata, run init/migrate and print info
diff --git a/mediagoblin/gmg_commands/deletemedia.py b/mediagoblin/gmg_commands/deletemedia.py
index bf50abde..4919f86a 100644
--- a/mediagoblin/gmg_commands/deletemedia.py
+++ b/mediagoblin/gmg_commands/deletemedia.py
@@ -14,7 +14,6 @@
# 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
@@ -28,7 +27,7 @@ def parser_setup(subparser):
def deletemedia(args):
app = commands_util.setup_app(args)
- media_ids = set([int(mid) for mid in args.media_ids.split(',') if mid.isdigit()])
+ media_ids = {int(mid) for mid in args.media_ids.split(',') if mid.isdigit()}
if not media_ids:
print('Can\'t find any valid media ID(s).')
sys.exit(1)
diff --git a/mediagoblin/gmg_commands/reprocess.py b/mediagoblin/gmg_commands/reprocess.py
index 85cae6df..b2a69819 100644
--- a/mediagoblin/gmg_commands/reprocess.py
+++ b/mediagoblin/gmg_commands/reprocess.py
@@ -14,7 +14,6 @@
# 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
@@ -146,7 +145,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 {}'.format(entry.media_type))
if args.state:
processors = manager.list_all_processors_by_state(args.state)
@@ -171,7 +170,7 @@ def available(args):
else:
for processor in processors:
if processor.description:
- print(" - %s: %s" % (processor.name, processor.description))
+ print(" - {}: {}".format(processor.name, processor.description))
else:
print(" - %s" % processor.name)
@@ -188,11 +187,11 @@ 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"' % (
+ print('No such processor "{}" for media with id "{}"'.format(
args.reprocess_command, media_entry.id))
return
except ProcessorNotEligible:
- print('Processor "%s" exists but media "%s" is not eligible' % (
+ print('Processor "{}" exists but media "{}" is not eligible'.format(
args.reprocess_command, media_entry.id))
return
@@ -206,7 +205,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 {}'.format(entry.media_type))
def bulk_run(args):
@@ -236,11 +235,11 @@ def thumbs(args):
processor_class = manager.get_processor(
'resize', media_entry)
except ProcessorDoesNotExist:
- print('No such processor "%s" for media with id "%s"' % (
+ print('No such processor "{}" for media with id "{}"'.format(
'resize', media_entry.id))
return
except ProcessorNotEligible:
- print('Processor "%s" exists but media "%s" is not eligible' % (
+ print('Processor "{}" exists but media "{}" is not eligible'.format(
'resize', media_entry.id))
return
@@ -248,7 +247,7 @@ def thumbs(args):
# prepare filetype and size to be passed into reprocess_parser
if args.size:
- extra_args = 'thumb --{0} {1} {2}'.format(
+ extra_args = 'thumb --{} {} {}'.format(
processor_class.thumb_size,
args.size[0],
args.size[1])
@@ -263,7 +262,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 {}'.format(entry.media_type))
def initial(args):
@@ -279,7 +278,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 {}'.format(entry.media_type))
def reprocess(args):
diff --git a/mediagoblin/gmg_commands/serve.py b/mediagoblin/gmg_commands/serve.py
index 6ded1cfc..0e25a112 100644
--- a/mediagoblin/gmg_commands/serve.py
+++ b/mediagoblin/gmg_commands/serve.py
@@ -14,12 +14,11 @@
# 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):
+class ServeCommand:
def loadserver(self, server_spec, name, relative_to, **kwargs):
return loadserver(server_spec, name=name, relative_to=relative_to,
diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py
index d1a8b72d..b61a5571 100644
--- a/mediagoblin/gmg_commands/users.py
+++ b/mediagoblin/gmg_commands/users.py
@@ -14,7 +14,6 @@
# 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
@@ -41,7 +40,7 @@ def adduser(args):
#TODO: Lets trust admins this do not validate Emails :)
commands_util.setup_app(args)
- args.username = six.text_type(commands_util.prompt_if_not_set(args.username, "Username:"))
+ args.username = str(commands_util.prompt_if_not_set(args.username, "Username:"))
args.password = commands_util.prompt_if_not_set(args.password, "Password:",True)
args.email = commands_util.prompt_if_not_set(args.email, "Email:")
@@ -52,36 +51,36 @@ def adduser(args):
).count()
if users_with_username:
- print(u'Sorry, a user with that name already exists.')
+ print('Sorry, a user with that name already exists.')
sys.exit(1)
else:
# Create the user
entry = db.LocalUser()
- entry.username = six.text_type(args.username.lower())
- entry.email = six.text_type(args.email)
+ entry.username = str(args.username.lower())
+ entry.email = str(args.email)
entry.pw_hash = auth.gen_password_hash(args.password)
default_privileges = [
db.Privilege.query.filter(
- db.Privilege.privilege_name==u'commenter').one(),
+ db.Privilege.privilege_name=='commenter').one(),
db.Privilege.query.filter(
- db.Privilege.privilege_name==u'uploader').one(),
+ db.Privilege.privilege_name=='uploader').one(),
db.Privilege.query.filter(
- db.Privilege.privilege_name==u'reporter').one(),
+ db.Privilege.privilege_name=='reporter').one(),
db.Privilege.query.filter(
- db.Privilege.privilege_name==u'active').one()
+ db.Privilege.privilege_name=='active').one()
]
entry.all_privileges = default_privileges
entry.save()
- print(u"User created (and email marked as verified).")
+ print("User created (and email marked as verified).")
def makeadmin_parser_setup(subparser):
subparser.add_argument(
'username',
help="Username to give admin level",
- type=six.text_type)
+ type=str)
def makeadmin(args):
@@ -95,12 +94,12 @@ def makeadmin(args):
if user:
user.all_privileges.append(
db.Privilege.query.filter(
- db.Privilege.privilege_name==u'admin').one()
+ db.Privilege.privilege_name=='admin').one()
)
user.save()
- print(u'The user %s is now an admin.' % args.username)
+ print('The user %s is now an admin.' % args.username)
else:
- print(u'The user %s doesn\'t exist.' % args.username)
+ print('The user %s doesn\'t exist.' % args.username)
sys.exit(1)
@@ -108,7 +107,7 @@ def changepw_parser_setup(subparser):
subparser.add_argument(
'username',
help="Username used to login",
- type=six.text_type)
+ type=str)
subparser.add_argument(
'password',
help="Your NEW supersecret word to login")
@@ -125,9 +124,9 @@ def changepw(args):
if user:
user.pw_hash = auth.gen_password_hash(args.password)
user.save()
- print(u'Password successfully changed for user %s.' % args.username)
+ print('Password successfully changed for user %s.' % args.username)
else:
- print(u'The user %s doesn\'t exist.' % args.username)
+ print('The user %s doesn\'t exist.' % args.username)
sys.exit(1)
@@ -135,7 +134,7 @@ def deleteuser_parser_setup(subparser):
subparser.add_argument(
'username',
help="Username to delete",
- type=six.text_type)
+ type=str)
def deleteuser(args):
diff --git a/mediagoblin/gmg_commands/util.py b/mediagoblin/gmg_commands/util.py
index 4a4a9a74..f27a9535 100644
--- a/mediagoblin/gmg_commands/util.py
+++ b/mediagoblin/gmg_commands/util.py
@@ -35,8 +35,8 @@ def prompt_if_not_set(variable, text, password=False):
"""
if variable is None:
if not password:
- variable = six.moves.input(text + u' ')
+ variable = six.moves.input(text + ' ')
else:
- variable=getpass.getpass(text + u' ')
+ variable=getpass.getpass(text + ' ')
return variable