1 | import os |
---|
2 | import socket |
---|
3 | import sys |
---|
4 | from paste.script.appinstall import Installer as BaseInstaller |
---|
5 | from paste.fileapp import FileApp |
---|
6 | from paste.httpexceptions import HTTPNotFound |
---|
7 | from spider import webmirror |
---|
8 | |
---|
9 | class PackageProxyApp(object): |
---|
10 | |
---|
11 | def __init__(self, index_url=None, pack_dir=None): |
---|
12 | if not index_url: |
---|
13 | print "No repository index provided" |
---|
14 | sys.exit() |
---|
15 | if not pack_dir: |
---|
16 | print "No packages cache directory provided" |
---|
17 | sys.exit() |
---|
18 | if not os.path.isdir(pack_dir): |
---|
19 | print 'You must create the %r directory' % pack_dir |
---|
20 | sys.exit() |
---|
21 | self.index_url = index_url |
---|
22 | self.pack_dir = pack_dir |
---|
23 | |
---|
24 | def __call__(self, environ, start_response): |
---|
25 | path = environ.get('PATH_INFO', '').strip() |
---|
26 | filename = self.checkCache(path) |
---|
27 | if path.split('/')[0] == "favicon.ico": |
---|
28 | return HTTPNotFound()(environ, start_response) |
---|
29 | if filename is None: |
---|
30 | return HTTPNotFound()(environ, start_response) |
---|
31 | return FileApp(filename)(environ, start_response) |
---|
32 | |
---|
33 | def checkCache(self, path): |
---|
34 | pth = self.pack_dir + path |
---|
35 | pth1 = pth |
---|
36 | if not (path[-3:] in ['tgz','.gz','egg','zip','exe']): |
---|
37 | pth1 = pth + 'index.html' |
---|
38 | else: |
---|
39 | pth = '/'.join(pth.split('/')[:-1]) |
---|
40 | if not os.path.exists(pth1): |
---|
41 | webmirror(pth,1,self.index_url+path,0,1) |
---|
42 | if pth1: |
---|
43 | return pth1 |
---|
44 | return pth |
---|
45 | |
---|
46 | def app_factory(global_config, **local_conf): |
---|
47 | # Grab config from wsgi .ini file. If not specified, config.py's values |
---|
48 | # take over. |
---|
49 | pack_dir = local_conf.get('pack_directory', None) |
---|
50 | index_url = local_conf.get('index', None) |
---|
51 | return PackageProxyApp(index_url, pack_dir) |
---|
52 | """ |
---|
53 | class Installer(BaseInstaller): |
---|
54 | use_cheetah = False |
---|
55 | config_file = 'deployment.ini_tmpl' |
---|
56 | |
---|
57 | def config_content(self, command, vars): |
---|
58 | import pkg_resources |
---|
59 | module = 'collective.eggproxy' |
---|
60 | if pkg_resources.resource_exists(module, self.config_file): |
---|
61 | return self.template_renderer( |
---|
62 | pkg_resources.resource_string(module, self.config_file), |
---|
63 | vars, |
---|
64 | filename=self.config_file) |
---|
65 | """ |
---|