Commit ffe9c872 by benjaoming

Merge pull request #307 from spookylukey/master

Python 3 compatibility (or at least correct syntax) for mediawikimport c...
parents 7c10ab9d 4ec26b2d
from __future__ import print_function
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
import getpass import getpass
...@@ -87,7 +89,7 @@ class Command(BaseCommand): ...@@ -87,7 +89,7 @@ class Command(BaseCommand):
self.articles_worked_on.append(urltitle) self.articles_worked_on.append(urltitle)
print "Working on %s (%s)" % (title, urltitle) print("Working on %s (%s)" % (title, urltitle))
# Check if the URL path already exists # Check if the URL path already exists
try: try:
...@@ -96,10 +98,10 @@ class Command(BaseCommand): ...@@ -96,10 +98,10 @@ class Command(BaseCommand):
self.matching_old_link_new_link[page.title] = urlp.article.get_absolute_url() self.matching_old_link_new_link[page.title] = urlp.article.get_absolute_url()
if not replace_existing: if not replace_existing:
print "\tAlready existing, skipping..." print("\tAlready existing, skipping...")
return return
print "\tDestorying old version of the article" print("\tDestorying old version of the article")
urlp.article.delete() urlp.article.delete()
except URLPath.DoesNotExist: except URLPath.DoesNotExist:
...@@ -116,7 +118,7 @@ class Command(BaseCommand): ...@@ -116,7 +118,7 @@ class Command(BaseCommand):
else: else:
user = get_user_model().objects.get(username=history_page['user']) user = get_user_model().objects.get(username=history_page['user'])
except get_user_model().DoesNotExist: except get_user_model().DoesNotExist:
print "\tCannot found user with username=%s. Use --user-matching \"%s:<user_pk>\" to manualy set it" % (history_page['user'], history_page['user'], ) print("\tCannot found user with username=%s. Use --user-matching \"%s:<user_pk>\" to manualy set it" % (history_page['user'], history_page['user'], ))
user = None user = None
article_revision = ArticleRevision() article_revision = ArticleRevision()
...@@ -149,9 +151,9 @@ class Command(BaseCommand): ...@@ -149,9 +151,9 @@ class Command(BaseCommand):
# TODO: nsquare is bad # TODO: nsquare is bad
for (article, article_revision) in self.articles_imported: for (article, article_revision) in self.articles_imported:
print "Updating links of %s" % (article_revision.title, ) print("Updating links of %s" % (article_revision.title, ))
for id_from, id_to in self.matching_old_link_new_link.iteritems(): for id_from, id_to in self.matching_old_link_new_link.iteritems():
print "Replacing (%s \"wikilink\") with (%s)" % (id_from, id_to) print("Replacing (%s \"wikilink\") with (%s)" % (id_from, id_to))
article_revision.content = article_revision.content.replace("(%s \"wikilink\")" % (id_from, ), "(%s)" % (id_to,)) article_revision.content = article_revision.content.replace("(%s \"wikilink\")" % (id_from, ), "(%s)" % (id_to,))
article_revision.save() article_revision.save()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment