Exemplo n.º 1
0
def run():
    usage = "usage: %prog [options] <path to wiki> <pagename>"
    parser = OptionParser(usage=usage)
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      help="Report success")
    parser.add_option("-a",
                      "--auth",
                      action="store_true",
                      dest="auth",
                      help="Use local user-based wiki authentication")
    parser.add_option("-c",
                      "--comment",
                      dest="comment",
                      help="Optional change comment for the edit")

    (options, args) = parser.parse_args()

    if len(args) != 2:
        print parser.get_usage()
        sys.exit(2)

    # Configdir to path, so wikiconfig can be imported by Request
    cp = args[0]
    cp2 = os.path.join(cp, 'config')
    if os.path.isdir(cp2):
        cp = cp2
    sys.path.insert(0, cp)

    pagename = unicode(args[1], sys.getfilesystemencoding())

    # Make a new request for the page
    req = MinimalMoinScript(pagename, parse=False)
    req.page = Page(req, pagename)

    # Auth
    if options.auth:
        import posix, pwd
        # We need to import contexts before importing users, because otherwise
        # the relative imports in MoinMoin will fail.
        import MoinMoin.web.contexts
        from MoinMoin.user import User
        req.user = User(req, auth_username=pwd.getpwuid(posix.getuid())[0])

    mytext = unicode(sys.stdin.read(), sys.getfilesystemencoding())

    if options.comment:
        savetext(req, pagename, mytext, comment=unicode(options.comment))
    else:
        savetext(req, pagename, mytext)

    # Must finish the request to ensure that metadata is saved
    graphdata_close(req)
Exemplo n.º 2
0
def run():
    pages = []
    retain_shelve = False

    usage = "usage: %prog [options] <path-to-wiki> [pagename(s)]\n"
    parser = OptionParser(usage=usage)

    parser.add_option("-f", "--file", dest="filename",
                      help="write shelve to FILE")

    parser.add_option("-u", "--update_underlay", dest="underlay_only", 
                      action='store_true', default=False,
                      help="Only update underlay pages")

    (options, args) = parser.parse_args()
    help = parser.format_help()

    # Encoder from unicode to charset selected in config
    encoder = getencoder(config.charset)
    def _e(str):
        return encoder(str, 'replace')[0]

    class UserInputException(Exception):
        pass

    try:
        wikipath = args[0]
        configdir = os.path.abspath(os.path.join(wikipath, 'config'))

        sys.path.insert(0, configdir)

        request = MinimalMoinScript(parse=False)
        datadir = request.cfg.data_dir

        # Get a list of all pages
        root = RootPage(request)
        filter=None
        if options.underlay_only:
            retain_shelve = True

            def filterStandard(name):
                pageobj = Page(request, name)
                return pageobj.getPageStatus()[0]

            filter = filterStandard
        if options.filename:
            retain_shelve = True

        if len(args) > 1:
            pagelist = [unicode(x, sys.getfilesystemencoding()) for x in args[1:]]
            pageobjs = list()

            for page in pagelist:
                pageobj = Page(request, page)
                if not pageobj.exists():
                    raise UserInputException(page)
                pageobjs.append(pageobj)

            pages = pageobjs
            retain_shelve = True
        else:
            pages = root.getPageList(user="", include_underlay=True, filter=filter,
                                     return_objects=True, includeBackend=False)

    except IndexError:
        print >> sys.stderr, help
        sys.exit(3)
    except UserInputException, page:
        print >> sys.stderr, "page %s does not exist" % (page)
        print >> sys.stderr, help
        sys.exit(2)
Exemplo n.º 3
0
            sys.stderr.write('Removed graphdata directory (%s)\n' % gddir)
    elif not options.filename:
        for file in os.listdir(datadir):
            if file.startswith('read_lock') or file.startswith('write_lock'):
                sys.stderr.write("Found lockfile (%s), \n" % file + \
                                 "database may be corrupted. \n" + \
                                 "Rehash entire db or remove lock " + \
                                 "and rehash the crashed pages.\n")
                sys.exit(1)

    total = len(pages)
    padding = len(str(total))
    count = 1

    # Just init one request
    scriptcontext = MinimalMoinScript(parse=False)
    scriptcontext.graphdata.clear_metas()
    # If you want to rehash into separate shelve, ignore locks, create a
    # new shelve from scratch
    if options.filename:
        from graphingwiki.backend.shelvedb import GraphData
        scriptcontext._graphdata = GraphData(scriptcontext)
        scriptcontext._graphdata.close()
        if os.path.exists(options.filename):
            if not os.path.isfile(options.filename):
                sys.stderr.write("Destination not a file: %s\n" % 
                                 (options.filename))
                sys.exit(1)
            os.unlink(options.filename)
        scriptcontext._graphdata.db = scriptcontext._graphdata.shelveopen(options.filename, "c")
        scriptcontext._graphdata.readlock = lambda: None