aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/gmg_commands
diff options
context:
space:
mode:
authorSimen Heggestøyl <simenheg@gmail.com>2017-10-08 11:04:10 +0200
committerBoris Bobrov <breton@cynicmansion.ru>2017-10-16 18:25:40 +0300
commit2ad4630c033acd9c1b52c139830c65bdd471bb66 (patch)
tree2359d9bc6420b0c7ac26f1b7dcdb1338ddf943df /mediagoblin/gmg_commands
parent480aa3a2045bf7fae9a70f5135962507472e8df8 (diff)
downloadmediagoblin-2ad4630c033acd9c1b52c139830c65bdd471bb66.tar.lz
mediagoblin-2ad4630c033acd9c1b52c139830c65bdd471bb66.tar.xz
mediagoblin-2ad4630c033acd9c1b52c139830c65bdd471bb66.zip
Port batchaddmedia command to Python 3
Diffstat (limited to 'mediagoblin/gmg_commands')
-rw-r--r--mediagoblin/gmg_commands/batchaddmedia.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/mediagoblin/gmg_commands/batchaddmedia.py b/mediagoblin/gmg_commands/batchaddmedia.py
index a521fe4d..55ed865b 100644
--- a/mediagoblin/gmg_commands/batchaddmedia.py
+++ b/mediagoblin/gmg_commands/batchaddmedia.py
@@ -19,6 +19,7 @@ from __future__ import print_function
import codecs
import csv
import os
+import sys
import requests
import six
@@ -96,7 +97,7 @@ def batchaddmedia(args):
contents = all_metadata.read()
media_metadata = parse_csv_file(contents)
- for media_id, file_metadata in media_metadata.iteritems():
+ for media_id, file_metadata in media_metadata.items():
files_attempted += 1
# In case the metadata was not uploaded initialize an empty dictionary.
json_ld_metadata = compact_and_validate({})
@@ -139,7 +140,7 @@ Metadata was not uploaded.""".format(
file_path = os.path.join(abs_metadata_dir, path)
file_abs_path = os.path.abspath(file_path)
try:
- media_file = file(file_abs_path, 'r')
+ media_file = open(file_abs_path, 'rb')
except IOError:
print(_(u"""\
FAIL: Local file {filename} could not be accessed.
@@ -202,7 +203,12 @@ def parse_csv_file(file_contents):
# Build a dictionary
for index, line in enumerate(lines):
if line.isspace() or line == u'': continue
- values = unicode_csv_reader([line]).next()
+ if (sys.version_info[0] == 3):
+ # Python 3's csv.py supports Unicode out of the box.
+ reader = csv.reader([line])
+ else:
+ reader = unicode_csv_reader([line])
+ values = next(reader)
line_dict = dict([(key[i], val)
for i, val in enumerate(values)])
media_id = line_dict.get('id') or index