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

Contents of /src/packages/mksite.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.3 - (show annotations) (download) (as text)
Sat Jan 6 15:12:31 2007 UTC (11 years, 6 months ago) by marduk
Branch: v1_3
Changes since 1.1.2.2: +6 -1 lines
File MIME type: text/x-python
Oops, forgot to create index.shtml in the /arch dirs

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 index = open(config.FELIB + '/index.shtml', 'r').read()
65 for arch in ['.'] + archList:
66 either = arch_dir + '/' + arch
67 stable = either + '/stable'
68 testing = either + '/testing'
69
70 mkdir(either)
71 mkdir(stable)
72 mkdir(testing)
73
74
75 # archnav.html
76 archbar = genarchbar(config.FEHOME, arch, '')
77 open(either + '/archnav.html', 'w').write(archbar)
78 archbar = genarchbar(config.FEHOME, arch, 'stable')
79 open(stable + '/archnav.html', 'w').write(archbar)
80 archbar = genarchbar(config.FEHOME, arch, 'testing')
81 open(testing + '/archnav.html', 'w').write(archbar)
82
83 # index.shtml
84 open(either + '/index.shtml', 'w').write(index)
85 open(stable + '/index.shtml', 'w').write(index)
86 open(testing + '/index.shtml', 'w').write(index)
87
88 # main /arch dir
89 archbar = genarchbar(config.FEHOME, '', '')
90 open(arch_dir + '/archnav.html', 'w').write(archbar)
91 open(arch_dir + '/index.shtml', 'w').write(index)
92
93
94 def main():
95 """Main program entry point."""
96
97 # create main directories
98 mkdir(config.LOCALHOME)
99 mkdir(config.LOCALHOME + '/archs')
100 mkdir(config.LOCALHOME + '/bumps')
101 mkdir(config.LOCALHOME + '/categories')
102 mkdir(config.LOCALHOME + '/daily')
103 mkdir(config.LOCALHOME + '/ebuilds')
104 mkdir(config.LOCALHOME + '/feeds')
105 #mkdir(config.LOCALHOME + '/images')
106 mkdir(config.LOCALHOME + '/new')
107 mkdir(config.LOCALHOME + '/packages')
108 mkdir(config.LOCALHOME + '/search')
109 mkdir(config.LOCALHOME + '/similar')
110
111 # set up .htaccess
112 htaccess = open(config.LOCALHOME + '/.htaccess', 'w')
113 htaccess.write('Options +FollowSymlinks +ExecCGI +Includes\n'
114 'AddCharset UTF-8 .html .shtml .rss\n'
115 'AddType text/html .shtml\n'
116 'AddHandler server-parsed .shtml\n'
117 )
118 htaccess.close()
119
120 # index.shtml
121 index = open(config.FELIB + '/index.shtml', 'r').read()
122 open(config.LOCALHOME + '/index.shtml', 'w').write(index)
123
124 # menu.html
125 open(config.LOCALHOME + '/menu.html', 'w')\
126 .write(open(config.FELIB + '/menu.html', 'r').read())
127
128 do_arch()
129
130 # /bumps
131 open(config.LOCALHOME + '/bumps/index.shtml', 'w').write(index)
132
133 # /categories
134 open(config.LOCALHOME + '/categories/index.shtml', 'w').write(index)
135
136 # /daily
137 open(config.LOCALHOME + '/daily/.htaccess', 'w').write(
138 'Options +ExecCGI\n'
139 'ErrorDocument 404 /daily/\n'
140 )
141 open(config.LOCALHOME + '/daily/index.shtml', 'w').write(
142 index.replace(
143 '<!--#include virtual="main.shtml"-->',
144 '<!--#exec cgi="daily.py" -->'
145 )
146 )
147 symlink(config.FELIB + '/daily.py', config.LOCALHOME + '/daily/daily.py')
148
149 # /ebuilds
150 symlink(config.FELIB + '/query_ebuild.py',
151 config.LOCALHOME + '/ebuilds/query_ebuild.py')
152 open(config.LOCALHOME + '/ebuilds/index.shtml', 'w').write(
153 index.replace(
154 '<!--#include virtual="main.shtml"-->',
155 '<!--#exec cmd="./query_ebuild.py $QUERY_STRING" -->')
156 )
157
158 # /feeds
159 open(config.LOCALHOME + '/feeds/index.shtml', 'w').write(index)
160 # This is a hack, but right now I'm too lazy to re-rewrite
161 # genrsslist.py
162 tmp = sys.stdout
163 sys.stdout = open(config.LOCALHOME + '/feeds/main.shtml', 'w')
164 import genrsslist
165 sys.stdout = tmp
166
167 # /new
168 open(config.LOCALHOME + '/new/index.shtml', 'w').write(
169 index.replace('<!--#include virtual="main.shtml"-->',
170 '<h3 class="category">Most Recently Introduced '
171 'Packages</h3>\n'
172 '<!--#include virtual="main.shtml"-->'
173 )
174 )
175
176 # /packages
177 open(config.LOCALHOME + '/packages/index.shtml', 'w').write(
178 index.replace('<!--#include virtual="main.shtml"-->',
179 '<!--#exec cgi="query_package.py" -->'
180 )
181 )
182 symlink(
183 config.FELIB + '/query_package.py',
184 config.LOCALHOME + '/packages/query_package.py'
185 )
186
187 # /search
188 open(config.LOCALHOME + '/search/index.shtml', 'w').write(
189 index.replace('<!--#include virtual="main.shtml"-->',
190 '<!--#exec cmd="./search.py $QUERY_STRING" -->'
191 )
192 )
193
194 symlink(
195 config.FELIB + '/search.py',
196 config.LOCALHOME + '/search/search.py'
197 )
198
199 # /similar
200 open(config.LOCALHOME + '/similar/index.shtml', 'w').write(
201 index.replace('<!--#include virtual="main.shtml"-->',
202 '<!--#exec cmd="./similar.py $QUERY_STRING" -->'
203 )
204 )
205
206 symlink(
207 config.FELIB + '/similar.py',
208 config.LOCALHOME + '/similar/similar.py'
209 )
210
211
212
213 # main root (/)
214 open(config.LOCALHOME + '/head.html', 'w').write(head())
215 symlink('archs/archnav.html', config.LOCALHOME + '/archnav.html')
216 symlink('archs/index.shtml', config.LOCALHOME + '/index.shtml')
217 symlink('archs/head.shtml', config.LOCALHOME + '/head.shtml')
218 symlink('archs/gentoo.rss', config.LOCALHOME + '/gentoo.rss')
219 symlink('archs/gentoo_simple.rss', config.LOCALHOME +
220 '/gentoo_simple.rss')
221 symlink('archs/main.shtml', config.LOCALHOME + '/main.shtml')
222
223 if __name__ == '__main__':
224 main()

  ViewVC Help
Powered by ViewVC 1.1.20