summaryrefslogtreecommitdiff
blob: 7e3561bb70dec15cf46cdebe40f88927d80d76c2 (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/env python

# Create the site (as if) from scratch according to config.py

import os
import sys

import config
from genarchbar import genarchbar

archList = config.ARCHLIST[:]
archList.sort()

def mkdir(path):
    """Create directory path if it doesn't already exist"""

    if not os.path.exists(path):
        return os.makedirs(path)

def symlink(src, dst):
    """Create symlink if overwriting dst if it exists"""

    if os.path.exists(dst) or os.path.islink(dst):
        os.unlink(dst)
    return os.symlink(src, dst)

def head():
    """return head.html file as string"""
    s = '<meta content="text/html; charset=utf-8" http-equiv="Content-Type">\n'
    s+= '<link rel="stylesheet" type="text/css" href="%s">\n' % \
            config.STYLESHEET
    if hasattr(config, 'FAVICON'):
        s+= '<link type="image/x-icon" href="%s" rel="shortcut icon">\n' \
                % config.FAVICON
    s+= ('<link rel="alternate" type="application/rss+xml" title="Portage '
        'Updates" href="/gentoo.rss">\n')
    s+= ('<link rel="alternate" type="application/rss-xml" '
        'title="Most Recently Introduced Packages" href="/feeds/new.rss">\n')

    for arch in archList:
        s+= (
            '<link rel="alternate" type="application/rss+xml" title="Portage '
            'Updates for %s" href="/archs/%s/gentoo.rss">\n'
            % (arch, arch)
            )
        s+= (
            '<link rel="alternate" type="application/rss+xml" title="Portage '
            'Updates for %s (stable)" href="/archs/%s/stable/gentoo.rss">\n'
            % (arch, arch)
            )
        s+= (
            '<link rel="alternate" type="application/rss+xml" title="Portage '
            'Updates for %s (testing)" href="/archs/%s/testing/gentoo.rss">\n'
            % (arch, arch)
            )
    s+= '<title>Gentoo Online Package Database</title>\n</head>\n'
    return s

def do_arch():
    """/arch directories"""

    # create arch dirs
    arch_dir = config.LOCALHOME + '/archs'
    index = open(config.FELIB + '/index.shtml', 'r').read()
    for arch in ['.'] + archList:
        either = arch_dir + '/' + arch
        stable = either + '/stable'
        testing = either + '/testing'

        mkdir(either)
        mkdir(stable)
        mkdir(testing)


        # archnav.html
        archbar = genarchbar(config.FEHOME, arch, '')
        open(either + '/archnav.html', 'w').write(archbar)
        archbar = genarchbar(config.FEHOME, arch, 'stable')
        open(stable + '/archnav.html', 'w').write(archbar)
        archbar = genarchbar(config.FEHOME, arch, 'testing')
        open(testing + '/archnav.html', 'w').write(archbar)
        
        # index.shtml
        open(either + '/index.shtml', 'w').write(index)
        open(stable + '/index.shtml', 'w').write(index)
        open(testing + '/index.shtml', 'w').write(index)

    # main /arch dir
    archbar = genarchbar(config.FEHOME, '', '')
    open(arch_dir + '/archnav.html', 'w').write(archbar)
    open(arch_dir + '/index.shtml', 'w').write(index)


def main():
    """Main program entry point."""

    # create main directories
    mkdir(config.LOCALHOME)
    mkdir(config.LOCALHOME + '/archs')
    mkdir(config.LOCALHOME + '/bumps')
    mkdir(config.LOCALHOME + '/categories')
    mkdir(config.LOCALHOME + '/daily')
    mkdir(config.LOCALHOME + '/ebuilds')
    mkdir(config.LOCALHOME + '/feeds')
    #mkdir(config.LOCALHOME + '/images')
    mkdir(config.LOCALHOME + '/new')
    mkdir(config.LOCALHOME + '/packages')
    mkdir(config.LOCALHOME + '/search')
    mkdir(config.LOCALHOME + '/similar')

    # set up .htaccess
    htaccess = open(config.LOCALHOME + '/.htaccess', 'w')
    htaccess.write('Options +FollowSymlinks +ExecCGI +Includes\n'
            'AddCharset UTF-8 .html .shtml .rss\n'
            'AddType text/html .shtml\n'
            'AddHandler server-parsed .shtml\n'
            )
    htaccess.close()

    # index.shtml
    index = open(config.FELIB + '/index.shtml', 'r').read()
    open(config.LOCALHOME + '/index.shtml', 'w').write(index)
    
    # menu.html
    open(config.LOCALHOME + '/menu.html', 'w')\
            .write(open(config.FELIB + '/menu.html', 'r').read())
    
    do_arch()

    # /bumps
    open(config.LOCALHOME + '/bumps/index.shtml', 'w').write(index)

    # /categories
    open(config.LOCALHOME + '/categories/index.shtml', 'w').write(index)

    # /daily
    open(config.LOCALHOME + '/daily/.htaccess', 'w').write(
        'Options +ExecCGI +FollowSymlinks\n'
        'ErrorDocument 404 /daily/\n'
    )
    open(config.LOCALHOME + '/daily/index.shtml', 'w').write(
        index.replace(
            '<!--#include virtual="main.shtml"-->',
            '<!--#exec cgi="daily.py" -->' 
        )
    )
    symlink(config.FELIB + '/daily.py', config.LOCALHOME + '/daily/daily.py')
    # we need to create an empty archnav.html in this directory for the
    # current day special case (see bug #166551)
    open(config.LOCALHOME + '/daily/archnav.html', 'w')

    # /ebuilds
    symlink(config.FELIB + '/query_ebuild.py', 
            config.LOCALHOME + '/ebuilds/query_ebuild.py')
    open(config.LOCALHOME + '/ebuilds/index.shtml', 'w').write(
            index.replace(
                '<!--#include virtual="main.shtml"-->',
                '<!--#exec cmd="export QUERY_STRING;./query_ebuild.py" -->')
            )

    # /feeds
    open(config.LOCALHOME + '/feeds/index.shtml', 'w').write(index)
    # This is a hack, but right now I'm too lazy to re-rewrite
    # genrsslist.py
    tmp = sys.stdout
    sys.stdout = open(config.LOCALHOME + '/feeds/main.shtml', 'w')
    import genrsslist
    sys.stdout = tmp

    # /new
    open(config.LOCALHOME + '/new/index.shtml', 'w').write(
            index.replace('<!--#include virtual="main.shtml"-->',
                '<h3 class="category">Most Recently Introduced '
                'Packages</h3>\n'
                '<!--#include virtual="main.shtml"-->'
                )
            )

    # /packages
    open(config.LOCALHOME + '/packages/index.shtml', 'w').write(
            index.replace('<!--#include virtual="main.shtml"-->',
                '<!--#exec cgi="query_package.py" -->'
                )
            )
    symlink(
            config.FELIB + '/query_package.py', 
            config.LOCALHOME + '/packages/query_package.py'
    )

    # /search
    open(config.LOCALHOME + '/search/index.shtml', 'w').write(
            index.replace('<!--#include virtual="main.shtml"-->',
                '<!--#exec cmd="export QUERY_STRING;./search.py" -->'
                )
            )

    symlink(
            config.FELIB + '/search.py',
            config.LOCALHOME + '/search/search.py'
    )

    # /similar
    open(config.LOCALHOME + '/similar/index.shtml', 'w').write(
            index.replace('<!--#include virtual="main.shtml"-->',
                '<!--#exec cmd="export QUERY_STRING;./similar.py" -->'
                )
            )

    symlink(
            config.FELIB + '/similar.py',
            config.LOCALHOME + '/similar/similar.py'
    )



    # main root (/)
    open(config.LOCALHOME + '/head.html', 'w').write(head())
    symlink('archs/archnav.html', config.LOCALHOME + '/archnav.html')
    symlink('archs/index.shtml', config.LOCALHOME + '/index.shtml')
    #symlink('archs/head.html', config.LOCALHOME + '/head.html')
    symlink('archs/gentoo.rss', config.LOCALHOME + '/gentoo.rss')
    symlink('archs/gentoo_simple.rss', config.LOCALHOME +
        '/gentoo_simple.rss')
    symlink('archs/main.shtml', config.LOCALHOME + '/main.shtml')

if __name__ == '__main__':
    main()