コード例 #1
0
ファイル: yamdwe.py プロジェクト: krichter722/yamdwe
def main():
    # the wikicontent code (that uses visitor module) tends to recurse quite deeply for complex pages
    sys.setrecursionlimit(20000)

    enable_unicode_output()

    args = arguments.parse_args()

    if args.http_pass is not None and args.http_user is None:
        raise RuntimeError(
            "ERROR: Option --http_pass requires --http_user to also be specified"
        )
    if args.wiki_pass is not None and args.wiki_user is None:
        raise RuntimeError(
            "ERROR: Option --wiki_pass requires --wiki_user to also be specified"
        )

    if args.http_user is not None and args.http_pass is None:
        args.http_pass = getpass.getpass("Enter password for HTTP auth (%s):" %
                                         args.http_user)
    if args.wiki_user is not None and args.wiki_pass is None:
        args.wiki_pass = getpass.getpass(
            "Enter password for Wiki login (%s):" % args.wiki_user)

    importer = mediawiki.Importer(args.mediawiki, args.http_user,
                                  args.http_pass, args.wiki_user,
                                  args.wiki_pass)
    exporter = dokuwiki.Exporter(args.dokuwiki)

    # Set the wikicontent's definition of File: and Image: prefixes (varies by language settings)
    canonical_file, aliases = importer.get_file_namespaces()
    wikicontent.set_file_namespaces(canonical_file, aliases)

    # Read all pages and page revisions
    pages = importer.get_all_pages()
    print("Found %d pages to export..." % len(pages))

    # Add a shameless "exported by yamdwe" note to the front page of the wiki
    mainpage = importer.get_main_pagetitle()
    for page in pages:
        if page["title"] == mainpage:
            latest = dict(page["revisions"][0])
            latest["user"] = "******"
            now = datetime.datetime.utcnow().replace(microsecond=0)
            latest["timestamp"] = now.isoformat() + "Z"
            latest[
                "comment"] = "Automated note about use of yamdwe Dokuwiki import tool"
            latest[
                "*"] += "\n\n(Automatically exported to Dokuwiki from Mediawiki by [https://github.com/projectgus/yamdwe Yamdwe] on %s.)" % (
                    datetime.date.today().strftime("%x"))
            page["revisions"].insert(0, latest)

    # Export pages to Dokuwiki format
    exporter.write_pages(pages)

    # Bring over images
    images = importer.get_all_images()
    print("Found %d images to export..." % len(images))
    exporter.write_images(images, canonical_file, args.http_user,
                          args.http_pass)

    # fix permissions on data directory if possible
    exporter.fixup_permissions()

    # touch conf file to invalidate cached pages
    exporter.invalidate_cache()

    print("Done.")
コード例 #2
0
ファイル: yamdwe.py プロジェクト: edmondac/yamdwe
def main():
    # the wikicontent code (that uses visitor module) tends to recurse quite deeply for complex pages
    sys.setrecursionlimit(20000)

    # try not to crash if the output/console has a character we can't encode
    sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout,
                                                                 "replace")

    args = arguments.parse_args()

    if args.http_pass is not None and args.http_user is None:
        raise RuntimeError(
            "ERROR: Option --http_pass requires --http_user to also be specified"
        )
    if args.wiki_pass is not None and args.wiki_user is None:
        raise RuntimeError(
            "ERROR: Option --wiki_pass requires --wiki_user to also be specified"
        )

    if args.http_user is not None and args.http_pass is None:
        args.http_pass = getpass.getpass("Enter password for HTTP auth (%s):" %
                                         args.http_user)
    if args.wiki_user is not None and args.wiki_pass is None:
        args.wiki_pass = getpass.getpass(
            "Enter password for Wiki login (%s):" % args.wiki_user)

    if not args.mediawiki.endswith("api.php"):
        print(
            "WARNING: Mediawiki URL does not end in 'api.php'... This has to be the URL of the Mediawiki API, not just the wiki. If you can't export anything, try adding '/api.php' to the wiki URL."
        )

    if "domain" in inspect.getargspec(simplemediawiki.MediaWiki.__init__)[0]:
        importer = mediawiki.Importer(args.mediawiki,
                                      args.http_user,
                                      args.http_pass,
                                      args.wiki_user,
                                      args.wiki_pass,
                                      args.wiki_domain,
                                      verbose=args.verbose)
    else:
        importer = mediawiki.Importer(args.mediawiki,
                                      args.http_user,
                                      args.http_pass,
                                      args.wiki_user,
                                      args.wiki_pass,
                                      verbose=args.verbose)
    exporter = dokuwiki.Exporter(args.dokuwiki)

    # Set the wikicontent's definition of File: and Image: prefixes (varies by language settings)
    canonical_file, aliases = importer.get_file_namespaces()
    wikicontent.set_file_namespaces(canonical_file, aliases)

    # Read all pages and page revisions
    pages = importer.get_all_pages()
    print("Found %d pages to export..." % len(pages))

    # Add a shameless "exported by yamdwe" note to the front page of the wiki
    mainpage = importer.get_main_pagetitle()

    for page in pages:
        if page["title"] == mainpage:
            latest = dict(page["revisions"][0])
            latest["user"] = "******"
            now = datetime.datetime.utcnow().replace(microsecond=0)
            latest["timestamp"] = now.isoformat() + "Z"
            latest[
                "comment"] = "Automated note about use of yamdwe Dokuwiki import tool"
            latest[
                "*"] += "\n\n(Automatically exported to Dokuwiki from Mediawiki by [https://github.com/projectgus/yamdwe Yamdwe] on %s.)" % (
                    datetime.date.today().strftime("%x"))
            page["revisions"].insert(0, latest)

    # Export pages to Dokuwiki format
    exporter.write_pages(pages)

    # Bring over images
    images = importer.get_all_images()
    print("Found %d images to export..." % len(images))
    exporter.write_images(images, canonical_file, args.http_user,
                          args.http_pass)

    # fix permissions on data directory if possible
    exporter.fixup_permissions()

    # touch conf file to invalidate cached pages
    exporter.invalidate_cache()

    print("Done.")