summaryrefslogtreecommitdiff
path: root/raw_produce
blob: 353f4690ff65c15c02758daab62f68f832e417a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python

import subprocess
import os
import sys

repo = os.path.dirname (os.path.abspath (__file__))

out_path = os.path.join (repo, "index.html")
description = open (os.path.join (repo, ".git", "description")).read ()

global_template = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>%(title)s</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="blogit-style.css" type="text/css" />
  </head>
  <body>
    <h1>%(title)s</h1>
    %(content)s
  </body>
</html>"""

post_template = """<div id="post-%(hash)s">
  <h2>%(subject)s</h2>
  <h3>By %(name)s on %(date)s</h3>
  <p>
    %(body)s
  </p>
</div>"""

os.chdir (repo)

bits = {
        "hash": "%h",
        "name": "%an",
        "date": "%ad",
        "sansub": "%f",
        "subject": "%s",
        "body": "%b",
       }

bits_list = [
              "hash",
              "name",
              "date",
              "sansub",
              "subject",
              "body",
            ]

format = "%n".join ([bits[bit] for bit in bits_list])

posts = []

for k in range (10):
  p = subprocess.Popen (["git", "log", "--no-merges",
                         "--pretty=format:" + format,
                         "HEAD~%d..HEAD~%d" % (k + 1, k)],
                         stdout = subprocess.PIPE,
                         stderr = subprocess.PIPE)
  out, _ = p.communicate ()
  if p.returncode != 0:
    break
  out = out.split ("\n", len (bits_list))
  bits = dict ([(bits_list[i], out[i]) for i in range (len (bits_list))])
  bits["body"] = bits["body"].replace ("\n", "<br />")
  posts.append (post_template % bits)

html = global_template % {"title": description,
                          "content": "\n".join (posts)}

open (out_path, "w").write (html)