From 18e4dca08782177125d032620499ceab1456b9e3 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Tue, 5 May 2015 12:32:14 -0700 Subject: pyblog: implement deploy and gen_deploy Also changed month to short format on the index page. --- pyblog | 161 +++++++++++++++++++++++++++++++++++++++++++++++---- source/css/theme.css | 2 +- 2 files changed, 151 insertions(+), 12 deletions(-) diff --git a/pyblog b/pyblog index 687d8400..5205ef85 100755 --- a/pyblog +++ b/pyblog @@ -5,6 +5,7 @@ # TODO: Feed icon next to the CC icon. import argparse +from contextlib import contextmanager import datetime import io import os @@ -18,6 +19,7 @@ import urllib.parse import xml.etree.ElementTree as ET import bs4 +import colorama import dateutil.parser import dateutil.tz @@ -45,17 +47,44 @@ def CDATA(text=None): ET._original_serialize_xml = ET._serialize_xml -def _serialize_xml(write, elem, qnames, namespaces,short_empty_elements, **kwargs): +def _serialize_xml(write, elem, qnames, namespaces,short_empty_elements, + **kwargs): if elem.tag == '![CDATA[': write("\n<{}{}]]>\n".format(elem.tag, elem.text)) if elem.tail: write(_escape_cdata(elem.tail)) else: - return ET._original_serialize_xml(write, elem, qnames, namespaces,short_empty_elements, **kwargs) + return ET._original_serialize_xml(write, elem, qnames, namespaces, + short_empty_elements, **kwargs) ET._serialize_xml = ET._serialize['xml'] = _serialize_xml +# declare the global foreground ANSI codes +BLACK = "" +BLUE = "" +CYAN = "" +GREEN = "" +MAGENTA = "" +RED = "" +WHITE = "" +YELLOW = "" +RESET = "" + +@contextmanager +def init_colorama(): + """Set global foreground modifying ANSI codes. + + BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW, and RESET. + + """ + + colorama.init() + for color, ansi in colorama.Fore.__dict__.items(): + exec("global {0}; {0} = '{1}'".format(color, ansi)) + yield + colorama.deinit() + class AtomFeed(object): """Class for storing atom:feed date and metadata.""" @@ -156,7 +185,7 @@ def generate_index(feed): # write a new
  • entry (