forked from tweecode/twee
-
Notifications
You must be signed in to change notification settings - Fork 4
/
twee.py
108 lines (75 loc) · 2.11 KB
/
twee.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
import sys, os, getopt, glob
scriptPath = os.path.realpath(os.path.dirname(sys.argv[0]))
sys.path.append(os.sep.join([scriptPath, 'tw', 'lib']))
sys.path.append(os.sep.join([scriptPath, 'lib']))
from tiddlywiki import TiddlyWiki
from twparser import TwParser
def usage():
print 'usage: twee [-a author] [-t target] [-m mergefile] [-r rss] source1 [source2..]'
def main (argv):
# defaults
author = 'twee'
target = 'jonah'
merge = rss_output = ''
plugins = []
# read command line switches
try:
opts, args = getopt.getopt(argv, 'a:m:p:r:t:', ['author=', 'merge=', 'plugins=', 'rss=', 'target='])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if (opt in ('-a', '--author')):
author = arg
elif (opt in ('-m', '--merge')):
merge = arg
elif (opt in ('-p', '--plugins')):
plugins = arg.split(',')
elif (opt in ('-r', '--rss')):
rss_output = arg
elif (opt in ('-t', '--target')):
target = arg
# construct a TW object
tw = TiddlyWiki(author)
# read in a file to be merged
if merge != '':
file = open(merge)
tw.addHtml(file.read())
file.close()
# read source files
sources = []
for arg in args:
for file in glob.glob(arg):
sources.append(file)
if len(sources) == 0:
print 'twee: no source files specified\n'
sys.exit(2)
for source in sources:
file = open(source)
tw.addTwee(file.read())
file.close()
# generate RSS if requested
if rss_output != '':
rss_file = open(rss_output, 'w')
tw.toRss().write_xml(rss_file)
rss_file.close()
# output the target header
# if (target != 'none') and (target != 'plugin'):
# file = open(scriptPath + os.sep + 'targets' + os.sep + target \
# + os.sep + 'header.html')
# print(file.read())
# file.close()
# the tiddlers
print TwParser(tw)
# print tw.toHtml()
# plugins
# for plugin in plugins:
# file = open(scriptPath + os.sep + 'targets' + os.sep + target \
# + os.sep + 'plugins' + os.sep + plugin + os.sep + 'compiled.html')
# print(file.read())
# file.close()
# and close it up
# print '</div></html>'
if __name__ == '__main__':
main(sys.argv[1:])