Beispiel #1
0
def cmd_buildtags(command, argv):
    """Command for building the tags index."""
    cfg = import_config()
    datadir = cfg['datadir']
    sep = cfg.get('tags_separator', ',')
    tagsfile = get_tagsfile(cfg)

    from douglas import tools
    from douglas.app import Douglas, initialize
    from douglas.entries import fileentry

    # Build a douglas object, initialize it, and run the start
    # callback.  This gives entry parsing related plugins a chance to
    # get their stuff together so that they work correctly.
    initialize(cfg)
    p = Douglas(cfg, {})
    p.initialize()
    req = p.get_request()
    tools.run_callback("start", {"request": req})

    # Grab all the entries in the datadir
    entrylist = [fileentry.FileEntry(req, e, datadir)
                 for e in tools.get_entries(cfg, datadir)]

    tags_to_files = {}
    for mem in entrylist:
        tagsline = mem["tags"]
        if not tagsline:
            continue
        tagsline = [t.strip() for t in tagsline.split(sep)]
        for t in tagsline:
            tags_to_files.setdefault(t, []).append(mem["filename"])

    savefile(tagsfile, tags_to_files)
    return 0
Beispiel #2
0
def buildtags(command, argv):
    """Command for building the tags index."""
    import config

    datadir = config.py.get("datadir")
    if not datadir:
        raise ValueError("config.py has no datadir property.")

    sep = config.py.get("tags_separator", ",")
    tagsfile = get_tagsfile(config.py)

    from douglas import tools
    from douglas.app import Douglas
    from douglas.entries import fileentry

    # build a douglas object, initialize it, and run the start
    # callback.  this gives entry parsing related plugins a chance to
    # get their stuff together so that they work correctly.
    p = Douglas(config.py, {})
    p.initialize()
    req = p.get_request()
    tools.run_callback("start", {"request": req})

    # grab all the entries in the datadir
    filelist = tools.walk(req, datadir)
    entrylist = [fileentry.FileEntry(req, e, datadir) for e in filelist]

    tags_to_files = {}
    for mem in entrylist:
        tagsline = mem["tags"]
        if not tagsline:
            continue
        tagsline = [t.strip() for t in tagsline.split(sep)]
        for t in tagsline:
            tags_to_files.setdefault(t, []).append(mem["filename"])

    savefile(tagsfile, tags_to_files)
    return 0
Beispiel #3
0
def cmd_persistdate(command, argv):
    from douglas.cmdline import import_config
    config = import_config()

    datadir = config.py.get('datadir')

    if not datadir:
        raise ValueError('config.py has no datadir property.')

    from douglas import tools
    from douglas.app import Douglas

    p = Douglas(config.py, {})
    p.initialize()
    req = p.get_request()
    tools.run_callback('start', {'request': req})

    filelist = tools.get_entries(config, datadir)
    print '%d files' % len(filelist)
    for fn in filelist:
        lines = open(fn, 'r').readlines()
        try:
            metadata = get_metadata(lines)
        except IndexError as exc:
            print '%s errored out: %s' % (fn, exc)
            continue

        if 'published' in metadata:
            print '%s already has metadata...' % fn
            continue

        print 'working on %s...' % fn
        timetuple = tools.filestat(req, fn)
        published = time.strftime('%Y-%m-%d %H:%M:%S', timetuple)
        lines.insert(1, '#published %s\n' % published)
        fp = open(fn, 'w')
        fp.write(''.join(lines))
        fp.close()