refactor `wynaut import` to `wynaut-import`

feature/cli
Martin Zimmermann 11 years ago
parent 770dbf48af
commit 1641f7f9c9

@ -40,7 +40,7 @@ setup(
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
'isso = isso:main', 'isso = isso:main',
'wynaut = wynaut:main' 'wynaut-import = wynaut.imprt:main'
], ],
}, },
) )

@ -4,49 +4,17 @@ import pkg_resources
dist = pkg_resources.get_distribution("isso") dist = pkg_resources.get_distribution("isso")
import os import os
import tempfile from argparse import ArgumentParser, SUPPRESS
from argparse import ArgumentParser
from isso.db import SQLite3
from isso.core import Config
from wynaut.imprt import Disqus def get_parser(desc):
try: parser = ArgumentParser(description=desc)
input = raw_input
except NameError:
pass
parser.add_argument('--version', action='version', version='%(prog)s' + dist.version,
def main(): help=SUPPRESS)
parser = ArgumentParser(description="manage Isso")
subparser = parser.add_subparsers(help="commands", dest="command")
parser.add_argument('--version', action='version', version='%(prog)s' + dist.version)
parser.add_argument('-c', dest="conf", default=os.environ.get("ISSO_SETTINGS"), parser.add_argument('-c', dest="conf", default=os.environ.get("ISSO_SETTINGS"),
metavar="/etc/isso.conf", help="set configuration file") metavar="/etc/isso.conf", help="set configuration file")
imprt = subparser.add_parser('import', help="import Disqus XML export") return parser
imprt.add_argument("dump", metavar="FILE")
imprt.add_argument("-f", "--force", dest="force", action="store_true",
help="force actions")
imprt.add_argument("-n", "--dry-run", dest="dryrun", action="store_true",
help="perform a trial run with no changes made")
args = parser.parse_args()
conf = Config.load(args.conf)
if args.command == "import":
xxx = tempfile.NamedTemporaryFile()
dbpath = conf.get("general", "dbpath") if not args.dryrun else xxx.name
dsq = Disqus(args.dump)
db = SQLite3(dbpath, conf)
if db.execute("SELECT * FROM comments").fetchone():
if not args.force and input("Isso DB is not empty! Continue? [y/N]: ") not in ("y", "Y"):
raise SystemExit("Abort.")
dsq.migrate(db)

@ -5,6 +5,7 @@ from __future__ import division
import sys import sys
import os import os
import time import time
import tempfile
import textwrap import textwrap
from time import mktime, strptime from time import mktime, strptime
@ -16,8 +17,18 @@ try:
except ImportError: except ImportError:
from urllib.parse import urlparse from urllib.parse import urlparse
try:
input = raw_input
except NameError:
pass
from werkzeug.utils import cached_property from werkzeug.utils import cached_property
from isso.db import SQLite3
from isso.core import Config
from wynaut import get_parser
class Import(object): class Import(object):
@ -141,3 +152,33 @@ class Disqus(Import):
remap[dsq_id] = rv["id"] remap[dsq_id] = rv["id"]
self._posts.update(set(remap.keys())) self._posts.update(set(remap.keys()))
def main():
parser = get_parser("import Disqus XML export")
parser.add_argument("dump", metavar="FILE")
parser.add_argument("-y", "--yes", dest="yes", action="store_true",
help="always confirm actions")
parser.add_argument("-n", "--dry-run", dest="dryrun", action="store_true",
help="perform a trial run with no changes made")
parser.add_argument("-f", "--from", dest="type", choices=["disqus", "csv"])
args = parser.parse_args()
conf = Config.load(args.conf)
xxx = tempfile.NamedTemporaryFile()
dbpath = conf.get("general", "dbpath") if not args.dryrun else xxx.name
if args.type == "disqus":
importer = Disqus(args.dump)
elif args.type == "csv":
pass
db = SQLite3(dbpath, conf)
if db.execute("SELECT * FROM comments").fetchone():
if not args.yes and input("Isso DB is not empty! Continue? [y/N]: ") not in ("y", "Y"):
raise SystemExit("Abort.")
importer.migrate(db)
Loading…
Cancel
Save