|
1 Using a download cache |
|
2 ====================== |
|
3 |
|
4 Normally, when distributions are installed, if any processing is |
|
5 needed, they are downloaded from the internet to a temporary directory |
|
6 and then installed from there. A download cache can be used to avoid |
|
7 the download step. This can be useful to reduce network access and to |
|
8 create source distributions of an entire buildout. |
|
9 |
|
10 The buildout download-cache option can be used to specify a directory |
|
11 to be used as a download cache. |
|
12 |
|
13 In this example, we'll create a directory to hold the cache: |
|
14 |
|
15 >>> cache = tmpdir('cache') |
|
16 |
|
17 And set up a buildout that downloads some eggs: |
|
18 |
|
19 >>> write('buildout.cfg', |
|
20 ... ''' |
|
21 ... [buildout] |
|
22 ... parts = eggs |
|
23 ... download-cache = %(cache)s |
|
24 ... find-links = %(link_server)s |
|
25 ... |
|
26 ... [eggs] |
|
27 ... recipe = zc.recipe.egg |
|
28 ... eggs = demo ==0.2 |
|
29 ... ''' % globals()) |
|
30 |
|
31 We specified a link server that has some distributions available for |
|
32 download: |
|
33 |
|
34 >>> print get(link_server), |
|
35 <html><body> |
|
36 <a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br> |
|
37 <a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br> |
|
38 <a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br> |
|
39 <a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br> |
|
40 <a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.egg</a><br> |
|
41 <a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br> |
|
42 <a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br> |
|
43 <a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br> |
|
44 <a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br> |
|
45 <a href="index/">index/</a><br> |
|
46 <a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br> |
|
47 </body></html> |
|
48 |
|
49 |
|
50 We'll enable logging on the link server so we can see what's going on: |
|
51 |
|
52 >>> get(link_server+'enable_server_logging') |
|
53 GET 200 /enable_server_logging |
|
54 '' |
|
55 |
|
56 We also specified a download cache. |
|
57 |
|
58 If we run the buildout, we'll see the eggs installed from the link |
|
59 server as usual: |
|
60 |
|
61 >>> print system(buildout), |
|
62 GET 200 / |
|
63 GET 200 /demo-0.2-py2.4.egg |
|
64 GET 200 /demoneeded-1.2c1.zip |
|
65 Installing eggs. |
|
66 Getting distribution for 'demo==0.2'. |
|
67 Got demo 0.2. |
|
68 Getting distribution for 'demoneeded'. |
|
69 Got demoneeded 1.2c1. |
|
70 Generated script '/sample-buildout/bin/demo'. |
|
71 |
|
72 We'll also get the download cache populated. The buildout doesn't put |
|
73 files in the cache directly. It creates an intermediate directory, |
|
74 dist: |
|
75 |
|
76 |
|
77 >>> ls(cache) |
|
78 d dist |
|
79 |
|
80 >>> ls(cache, 'dist') |
|
81 - demo-0.2-py2.4.egg |
|
82 - demoneeded-1.2c1.zip |
|
83 |
|
84 If we remove the installed eggs from eggs directory and re-run the buildout: |
|
85 |
|
86 >>> import os |
|
87 >>> for f in os.listdir('eggs'): |
|
88 ... if f.startswith('demo'): |
|
89 ... remove('eggs', f) |
|
90 |
|
91 >>> print system(buildout), |
|
92 GET 200 / |
|
93 Updating eggs. |
|
94 Getting distribution for 'demo==0.2'. |
|
95 Got demo 0.2. |
|
96 Getting distribution for 'demoneeded'. |
|
97 Got demoneeded 1.2c1. |
|
98 |
|
99 We see that the distributions aren't downloaded, because they're |
|
100 downloaded from the cache. |
|
101 |
|
102 Installing solely from a download cache |
|
103 --------------------------------------- |
|
104 |
|
105 A download cache can be used as the basis of application source |
|
106 releases. In an application source release, we want to distribute an |
|
107 application that can be built without making any network accesses. In |
|
108 this case, we distribute a buildout with download cache and tell the |
|
109 buildout to install from the download cache only, without making |
|
110 network accesses. The buildout install-from-cache option can be used |
|
111 to signal that packages should be installed only from the download |
|
112 cache. |
|
113 |
|
114 Let's remove our installed eggs and run the buildout with the |
|
115 install-from-cache option set to true: |
|
116 |
|
117 >>> for f in os.listdir('eggs'): |
|
118 ... if f.startswith('demo'): |
|
119 ... remove('eggs', f) |
|
120 |
|
121 >>> write('buildout.cfg', |
|
122 ... ''' |
|
123 ... [buildout] |
|
124 ... parts = eggs |
|
125 ... download-cache = %(cache)s |
|
126 ... install-from-cache = true |
|
127 ... find-links = %(link_server)s |
|
128 ... |
|
129 ... [eggs] |
|
130 ... recipe = zc.recipe.egg |
|
131 ... eggs = demo |
|
132 ... ''' % globals()) |
|
133 |
|
134 >>> print system(buildout), |
|
135 Uninstalling eggs. |
|
136 Installing eggs. |
|
137 Getting distribution for 'demo'. |
|
138 Got demo 0.2. |
|
139 Getting distribution for 'demoneeded'. |
|
140 Got demoneeded 1.2c1. |
|
141 Generated script '/sample-buildout/bin/demo'. |