comparison paint/package.py @ 34:acb2f4896291

working towards something
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 30 Mar 2012 14:18:09 -0700
parents 5efb61fde8aa
children e8d73f9e99fb
comparison
equal deleted inserted replaced
33:5efb61fde8aa 34:acb2f4896291
35 self._egg_info_path = None 35 self._egg_info_path = None
36 self._build_path = None 36 self._build_path = None
37 37
38 # TODO: list of temporary files/directories to be deleted 38 # TODO: list of temporary files/directories to be deleted
39 39
40 def path(self): 40 def _path(self):
41 """filesystem path to package directory""" 41 """filesystem path to package directory"""
42 42
43 # return cached copy if it exists 43 # return cached copy if it exists
44 if self._tmppath: 44 if self._tmppath:
45 return self._tmppath 45 return self._tmppath
114 114
115 if self._egg_info_path: 115 if self._egg_info_path:
116 # return cached copy 116 # return cached copy
117 return self._egg_info_path 117 return self._egg_info_path
118 118
119 directory = self.path() 119 directory = self._path()
120 setup_py = os.path.join(directory, 'setup.py') 120 setup_py = os.path.join(directory, 'setup.py')
121 if not os.path.exists(setup_py): 121 if not os.path.exists(setup_py):
122 raise AssertionError("%s does not exist" % setup_py) 122 raise AssertionError("%s does not exist" % setup_py)
123 123
124 # setup the egg info 124 # setup the egg info
157 def dependencies(self): 157 def dependencies(self):
158 """return the dependencies""" 158 """return the dependencies"""
159 # TODO: should probably have a more detailed dict: 159 # TODO: should probably have a more detailed dict:
160 # {'mozinfo': {'version': '>= 0.2', 160 # {'mozinfo': {'version': '>= 0.2',
161 # 'url': 'http://something.com/'}} 161 # 'url': 'http://something.com/'}}
162
163 # get the egg_info directory 162 # get the egg_info directory
164 egg_info = self._egg_info() 163 egg_info = self._egg_info()
165 164
166 # read the dependencies 165 # read the dependencies
167 requires = os.path.join(egg_info, 'requires.txt') 166 requires = os.path.join(egg_info, 'requires.txt')
184 183
185 return dependencies 184 return dependencies
186 185
187 def extension(self): 186 def extension(self):
188 """filename extension""" 187 """filename extension"""
189 188 raise NotImplementedError("TODO")
190 def repackage(self, destination): 189
190 def repackage(self, destination=None):
191 """ 191 """
192 repackage the package to ensure its actually in the right form 192 repackage the package to ensure its actually in the right form
193 and return the path to the destination
194 - destination: if given, path to put the build in [TODO]
193 """ 195 """
194 196
195 if self._build_path: 197 if self._build_path:
198 if destination:
199 shutil.copy(self._build_path, destination)
200 return os.path.abspath(destination)
201
202 # return cached copy
196 return self._build_path 203 return self._build_path
204
205 path = self._path()
206 dist = os.path.join(path, 'dist')
207 if os.path.exists(dist):
208 shutil.rmtree(dist)
209
210 call([sys.executable, 'setup.py', 'sdist'], cwd=path, stdout=subprocess.PIPE)
211
212 assert os.path.exists(dist)
213 contents = os.listdir(dist)
214 assert len(contents) == 1
215
216 self._build_path = os.path.join(dist, contents[0])
217
218 # destination
219 # use an evil recursive trick
220 return self.repackage(destination=destination)
221 if destination:
222 shutil.copy(self._build_path, destination)
223 return destination
224
225 return self._build_path
197 226
198 def download(self, directory): 227 def download(self, directory):
199 """download a package and all its dependencies using pip""" 228 """download a package and all its dependencies using pip"""
200 if not os.path.exists(directory): 229 if not os.path.exists(directory):
201 os.makedirs(directory) 230 os.makedirs(directory)