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
def render_url(cfg, pathinfo, querystring=""): """ Takes a url and a querystring and renders the page that corresponds with that by creating a Request and a Douglas object and passing it through. It then returns the resulting Response. :param cfg: the config.py dict :param pathinfo: the ``PATH_INFO`` string; example: ``/dev/douglas/firstpost.html`` :param querystring: the querystring (if any); example: debug=yes :returns: a douglas ``Response`` object. """ from douglas.app import Douglas if querystring: request_uri = pathinfo + '?' + querystring else: request_uri = pathinfo parts = urlparse(cfg['base_url']) env = { 'HTTP_HOST': parts.netloc, 'HTTP_PORT': parts.port, 'HTTP_USER_AGENT': 'static renderer', 'PATH_INFO': pathinfo, 'QUERY_STRING': querystring, 'REMOTE_ADDR': '', 'REQUEST_METHOD': 'GET', 'REQUEST_URI': request_uri, 'SCRIPT_NAME': '', 'wsgi.url_scheme': 'http', 'wsgi.errors': sys.stderr, 'wsgi.input': None } p = Douglas(cfg, env, {'COMPILING': 1}) p.run(compiling=True) return p.get_response()
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
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()
def render_url(cdict, pathinfo, querystring=""): """ Takes a url and a querystring and renders the page that corresponds with that by creating a Request and a douglas object and passing it through. It then returns the resulting Response. :param cdict: the config.py dict :param pathinfo: the ``PATH_INFO`` string; example: ``/dev/douglas/firstpost.html`` :param querystring: the querystring (if any); example: debug=yes :returns: a douglas ``Response`` object. """ from douglas.app import Douglas if querystring: request_uri = pathinfo + "?" + querystring else: request_uri = pathinfo env = { "HTTP_HOST": "localhost", "HTTP_REFERER": "", "HTTP_USER_AGENT": "static renderer", "PATH_INFO": pathinfo, "QUERY_STRING": querystring, "REMOTE_ADDR": "", "REQUEST_METHOD": "GET", "REQUEST_URI": request_uri, "SCRIPT_NAME": "", "wsgi.errors": sys.stderr, "wsgi.input": None } data = {"STATIC": 1} p = Douglas(cdict, env, data) p.run(static=True) return p.get_response()