refactor `wynaut import` to `wynaut-import`

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

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

@ -4,49 +4,17 @@ import pkg_resources
dist = pkg_resources.get_distribution("isso")
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:
input = raw_input
except NameError:
pass
parser = ArgumentParser(description=desc)
def main():
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('--version', action='version', version='%(prog)s' + dist.version,
help=SUPPRESS)
parser.add_argument('-c', dest="conf", default=os.environ.get("ISSO_SETTINGS"),
metavar="/etc/isso.conf", help="set configuration file")
imprt = subparser.add_parser('import', help="import Disqus XML export")
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)
return parser

@ -5,6 +5,7 @@ from __future__ import division
import sys
import os
import time
import tempfile
import textwrap
from time import mktime, strptime
@ -16,8 +17,18 @@ try:
except ImportError:
from urllib.parse import urlparse
try:
input = raw_input
except NameError:
pass
from werkzeug.utils import cached_property
from isso.db import SQLite3
from isso.core import Config
from wynaut import get_parser
class Import(object):
@ -141,3 +152,33 @@ class Disqus(Import):
remap[dsq_id] = rv["id"]
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