diff --git a/setup.py b/setup.py index 5037c3a..40609d7 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ setup( entry_points={ 'console_scripts': [ 'isso = isso:main', - 'wynaut = wynaut:main' + 'wynaut-import = wynaut.imprt:main' ], }, ) diff --git a/wynaut/__init__.py b/wynaut/__init__.py index 22c0d4e..410edde 100644 --- a/wynaut/__init__.py +++ b/wynaut/__init__.py @@ -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 diff --git a/wynaut/imprt/__init__.py b/wynaut/imprt.py similarity index 80% rename from wynaut/imprt/__init__.py rename to wynaut/imprt.py index 334f979..658fb54 100644 --- a/wynaut/imprt/__init__.py +++ b/wynaut/imprt.py @@ -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)