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

Diff of /src/packages/mksite.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.20