|
|
|
@ -6,6 +6,7 @@ import sys
|
|
|
|
|
import os
|
|
|
|
|
import io
|
|
|
|
|
import re
|
|
|
|
|
import logging
|
|
|
|
|
import textwrap
|
|
|
|
|
|
|
|
|
|
from time import mktime, strptime, time
|
|
|
|
@ -26,6 +27,7 @@ except ImportError:
|
|
|
|
|
|
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("isso")
|
|
|
|
|
|
|
|
|
|
def strip(val):
|
|
|
|
|
if isinstance(val, string_types):
|
|
|
|
@ -146,14 +148,6 @@ class Disqus(object):
|
|
|
|
|
initial_indent=" ", subsequent_indent=" "))
|
|
|
|
|
print("")
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def detect(cls, peek):
|
|
|
|
|
|
|
|
|
|
if 'xmlns="http://disqus.com' in peek:
|
|
|
|
|
return "http://disqus.com"
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WordPress(object):
|
|
|
|
|
|
|
|
|
@ -164,11 +158,13 @@ class WordPress(object):
|
|
|
|
|
self.xmlfile = xmlfile
|
|
|
|
|
self.count = 0
|
|
|
|
|
|
|
|
|
|
with io.open(xmlfile) as fp:
|
|
|
|
|
ns = WordPress.detect(fp.read(io.DEFAULT_BUFFER_SIZE))
|
|
|
|
|
|
|
|
|
|
if ns:
|
|
|
|
|
self.ns = "{" + ns + "}"
|
|
|
|
|
for line in io.open(xmlfile):
|
|
|
|
|
m = WordPress.detect(line)
|
|
|
|
|
if m:
|
|
|
|
|
self.ns = WordPress.ns.replace("1.0", m.group(1))
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
logger.warn("No WXR namespace found, assuming 1.0")
|
|
|
|
|
|
|
|
|
|
def insert(self, thread):
|
|
|
|
|
|
|
|
|
@ -242,10 +238,17 @@ class WordPress(object):
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def detect(cls, peek):
|
|
|
|
|
return re.compile("http://wordpress.org/export/(1\.\d)/").search(peek)
|
|
|
|
|
|
|
|
|
|
m = re.search("http://wordpress.org/export/1\.\d/", peek)
|
|
|
|
|
|
|
|
|
|
def autodetect(peek):
|
|
|
|
|
|
|
|
|
|
if 'xmlns="http://disqus.com' in peek:
|
|
|
|
|
return Disqus
|
|
|
|
|
|
|
|
|
|
m = WordPress.detect(peek)
|
|
|
|
|
if m:
|
|
|
|
|
return m.group(0)
|
|
|
|
|
return WordPress
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
@ -255,20 +258,15 @@ def dispatch(type, db, dump):
|
|
|
|
|
if input("Isso DB is not empty! Continue? [y/N]: ") not in ("y", "Y"):
|
|
|
|
|
raise SystemExit("Abort.")
|
|
|
|
|
|
|
|
|
|
if type is None:
|
|
|
|
|
|
|
|
|
|
if type == "disqus":
|
|
|
|
|
cls = Disqus
|
|
|
|
|
elif type == "wordpress":
|
|
|
|
|
cls = WordPress
|
|
|
|
|
else:
|
|
|
|
|
with io.open(dump) as fp:
|
|
|
|
|
peek = fp.read(io.DEFAULT_BUFFER_SIZE)
|
|
|
|
|
|
|
|
|
|
if WordPress.detect(peek):
|
|
|
|
|
type = "wordpress"
|
|
|
|
|
|
|
|
|
|
if Disqus.detect(peek):
|
|
|
|
|
type = "disqus"
|
|
|
|
|
cls = autodetect(fp.read(io.DEFAULT_BUFFER_SIZE))
|
|
|
|
|
|
|
|
|
|
if type == "wordpress":
|
|
|
|
|
WordPress(db, dump).migrate()
|
|
|
|
|
elif type == "disqus":
|
|
|
|
|
Disqus(db, dump).migrate()
|
|
|
|
|
else:
|
|
|
|
|
if cls is None:
|
|
|
|
|
raise SystemExit("Unknown format, abort.")
|
|
|
|
|
|
|
|
|
|
cls(db, dump).migrate()
|
|
|
|
|