/[gentoo]/src/packages/mksite.py
Gentoo

Contents of /src/packages/mksite.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.2 - (show annotations) (download) (as text)
Sat Jan 6 02:25:34 2007 UTC (10 years, 9 months ago) by marduk
Branch: v1_3
Changes since 1.1.2.1: +11 -13 lines
File MIME type: text/x-python
Making "alternate" links relative instead of absolute as Epiphany, Firefox,
et al (?) seem not to like them.

1 #!/bin/env python
2
3 # Create the site (as if) from scratch according to config.py
4
5 import os
6 import sys
7
8 import config
9 from genarchbar import genarchbar
10
11 archList = config.ARCHLIST[:]
12 archList.sort()
13
14 def mkdir(path):
15 """Create directory path if it doesn't already exist"""
16
17 if not os.path.exists(path):
18 return os.makedirs(path)
19
20 def symlink(src, dst):
21 """Create symlink if overwriting dst if it exists"""
22
23 if os.path.exists(dst) or os.path.islink(dst):
24 os.unlink(dst)
25 return os.symlink(src, dst)
26
27 def head():
28 """return head.html file as string"""
29 s = '<meta content="text/html; charset=utf-8" http-equiv="Content-Type">\n'
30 s+= '<link rel="stylesheet" type="text/css" href="%s">\n' % \
31 config.STYLESHEET
32 if hasattr(config, 'FAVICON'):
33 s+= '<link type="image/x-icon" href="%s" rel="shortcut icon">\n' \
34 % config.FAVICON
35 s+= ('<link rel="alternate" type="application/rss+xml" title="Portage '
36 'Updates" href="/gentoo.rss">\n')
37 s+= ('<link rel="alternate" type="application/rss-xml" '
38 'title="Most Recently Introduced Packages" href="/feeds/new.rss">\n')
39
40 for arch in archList:
41 s+= (
42 '<link rel="alternate" type="application/rss+xml" title="Portage '
43 'Updates for %s" href="/archs/%s/gentoo.rss">\n'
44 % (arch, arch)
45 )
46 s+= (
47 '<link rel="alternate" type="application/rss+xml" title="Portage '
48 'Updates for %s (stable)" href="/archs/%s/stable/gentoo.rss">\n'
49 % (arch, arch)
50 )
51 s+= (
52 '<link rel="alternate" type="application/rss+xml" title="Portage '
53 'Updates for %s (testing)" href="/archs/%s/testing/gentoo.rss">\n'
54 % (arch, arch)
55 )
56 s+= '<title>Gentoo Online Package Database</title>\n</head>\n'
57 return s
58
59 def do_arch():
60 """/arch directories"""
61
62 # create arch dirs
63 arch_dir = config.LOCALHOME + '/archs'
64 for arch in ['.'] + archList:
65 either = arch_dir + '/' + arch
66 stable = either + '/stable'
67 testing = either + '/testing'
68
69 mkdir(either)
70 mkdir(stable)
71 mkdir(testing)
72
73
74 # archnav.html
75 archbar = genarchbar(config.FEHOME, arch, '')
76 open(either + '/archnav.html', 'w').write(archbar)
77 archbar = genarchbar(config.FEHOME, arch, 'stable')
78 open(stable + '/archnav.html', 'w').write(archbar)
79 archbar = genarchbar(config.FEHOME, arch, 'testing')
80 open(testing + '/archnav.html', 'w').write(archbar)
81
82 # main /arch dir
83 index = open(config.FELIB + '/index.shtml', 'r').read()
84 archbar = genarchbar(config.FEHOME, '', '')
85 open(arch_dir + '/archnav.html', 'w').write(archbar)
86 open(arch_dir + '/index.shtml', 'w').write(index)
87
88
89 def main():
90 """Main program entry point."""
91
92 # create main directories
93 mkdir(config.LOCALHOME)
94 mkdir(config.LOCALHOME + '/archs')
95 mkdir(config.LOCALHOME + '/bumps')
96 mkdir(config.LOCALHOME + '/categories')
97 mkdir(config.LOCALHOME + '/daily')
98 mkdir(config.LOCALHOME + '/ebuilds')
99 mkdir(config.LOCALHOME + '/feeds')
100 #mkdir(config.LOCALHOME + '/images')
101 mkdir(config.LOCALHOME + '/new')
102 mkdir(config.LOCALHOME + '/packages')
103 mkdir(config.LOCALHOME + '/search')
104 mkdir(config.LOCALHOME + '/similar')
105
106 # set up .htaccess
107 htaccess = open(config.LOCALHOME + '/.htaccess', 'w')
108 htaccess.write('Options +FollowSymlinks +ExecCGI +Includes\n'
109 'AddCharset UTF-8 .html .shtml .rss\n'
110 'AddType text/html .shtml\n'
111 'AddHandler server-parsed .shtml\n'
112 )
113 htaccess.close()
114
115 # index.shtml
116 index = open(config.FELIB + '/index.shtml', 'r').read()
117 open(config.LOCALHOME + '/index.shtml', 'w').write(index)
118
119 # menu.html
120 open(config.LOCALHOME + '/menu.html', 'w')\
121 .write(open(config.FELIB + '/menu.html', 'r').read())
122
123 do_arch()
124
125 # /bumps
126 open(config.LOCALHOME + '/bumps/index.shtml', 'w').write(index)
127
128 # /categories
129 open(config.LOCALHOME + '/categories/index.shtml', 'w').write(index)
130
131 # /daily
132 open(config.LOCALHOME + '/daily/.htaccess', 'w').write(
133 'Options +ExecCGI\n'
134 'ErrorDocument 404 /daily/\n'
135 )
136 open(config.LOCALHOME + '/daily/index.shtml', 'w').write(
137 index.replace(
138 '<!--#include virtual="main.shtml"-->',
139 '<!--#exec cgi="daily.py" -->'
140 )
141 )
142 symlink(config.FELIB + '/daily.py', config.LOCALHOME + '/daily/daily.py')
143
144 # /ebuilds
145 symlink(config.FELIB + '/query_ebuild.py',
146 config.LOCALHOME + '/ebuilds/query_ebuild.py')
147 open(config.LOCALHOME + '/ebuilds/index.shtml', 'w').write(
148 index.replace(
149 '<!--#include virtual="main.shtml"-->',
150 '<!--#exec cmd="./query_ebuild.py $QUERY_STRING" -->')
151 )
152
153 # /feeds
154 open(config.LOCALHOME + '/feeds/index.shtml', 'w').write(index)
155 # This is a hack, but right now I'm too lazy to re-rewrite
156 # genrsslist.py
157 tmp = sys.stdout
158 sys.stdout = open(config.LOCALHOME + '/feeds/main.shtml', 'w')
159 import genrsslist
160 sys.stdout = tmp
161
162 # /new
163 open(config.LOCALHOME + '/new/index.shtml', 'w').write(
164 index.replace('<!--#include virtual="main.shtml"-->',
165 '<h3 class="category">Most Recently Introduced '
166 'Packages</h3>\n'
167 '<!--#include virtual="main.shtml"-->'
168 )
169 )
170
171 # /packages
172 open(config.LOCALHOME + '/packages/index.shtml', 'w').write(
173 index.replace('<!--#include virtual="main.shtml"-->',
174 '<!--#exec cgi="query_package.py" -->'
175 )
176 )
177 symlink(
178 config.FELIB + '/query_package.py',
179 config.LOCALHOME + '/packages/query_package.py'
180 )
181
182 # /search
183 open(config.LOCALHOME + '/search/index.shtml', 'w').write(
184 index.replace('<!--#include virtual="main.shtml"-->',
185 '<!--#exec cmd="./search.py $QUERY_STRING" -->'
186 )
187 )
188
189 symlink(
190 config.FELIB + '/search.py',
191 config.LOCALHOME + '/search/search.py'
192 )
193
194 # /similar
195 open(config.LOCALHOME + '/similar/index.shtml', 'w').write(
196 index.replace('<!--#include virtual="main.shtml"-->',
197 '<!--#exec cmd="./similar.py $QUERY_STRING" -->'
198 )
199 )
200
201 symlink(
202 config.FELIB + '/similar.py',
203 config.LOCALHOME + '/similar/similar.py'
204 )
205
206
207
208 # main root (/)
209 open(config.LOCALHOME + '/head.html', 'w').write(head())
210 symlink('archs/archnav.html', config.LOCALHOME + '/archnav.html')
211 symlink('archs/index.shtml', config.LOCALHOME + '/index.shtml')
212 symlink('archs/head.shtml', config.LOCALHOME + '/head.shtml')
213 symlink('archs/gentoo.rss', config.LOCALHOME + '/gentoo.rss')
214 symlink('archs/gentoo_simple.rss', config.LOCALHOME +
215 '/gentoo_simple.rss')
216 symlink('archs/main.shtml', config.LOCALHOME + '/main.shtml')
217
218 if __name__ == '__main__':
219 main()

  ViewVC Help
Powered by ViewVC 1.1.20