-
Notifications
You must be signed in to change notification settings - Fork 5
/
template.py
49 lines (42 loc) · 1.11 KB
/
template.py
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
import os
def defaultopen(f, title):
f.write("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>%s</title>
</head>
<body>
"""%title)
def defaultclose(f, title):
f.write("""
</body>
</html>
""")
def defaultmkdir(d):
if not os.path.exists(d):
os.makedirs(d)
def defaultidxopen(f, title):
return
try:
from customtemplate import *
except:
pass
class templatefile(file):
def __init__(self, name, mode="w", title="Data"):
super(templatefile, self).__init__(name, mode)
self.title = title
defaultopen(self, self.title)
def close(self):
defaultclose(self, self.title)
super(templatefile, self).close()
class idxfile(templatefile):
def __init__(self, name, mode="w", title="Data"):
super(templatefile, self).__init__(name, mode)
self.title = title
defaultopen(self, self.title)
defaultidxopen(self, self.title)
def close(self):
defaultclose(self, self.title)
super(templatefile, self).close()
mkdir = defaultmkdir
open = templatefile