Mercurial > hg > PaInt
annotate paint/package.py @ 35:e8d73f9e99fb
extension checking
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 30 Mar 2012 14:24:20 -0700 |
parents | acb2f4896291 |
children | f59da9e6be37 |
rev | line source |
---|---|
4 | 1 """ |
2 package model for python PAckage INTrospection | |
3 """ | |
4 | |
7 | 5 import os |
28 | 6 import pip |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
7 import pypi |
9
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
8 import shutil |
19 | 9 import subprocess |
10 import sys | |
7 | 11 import tarfile |
5 | 12 import tempfile |
7 | 13 import urllib2 |
21
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
14 import urlparse |
7 | 15 import utils |
5 | 16 |
19 | 17 try: |
18 from subprocess import check_call as call | |
19 except ImportError: | |
20 from subporcess import call | |
21 | |
10 | 22 __all__ = ['Package'] |
23 | |
4 | 24 class Package(object): |
33 | 25 """ |
26 class for python package introspection. | |
27 constructor takes the package 'src' | |
28 """ | |
4 | 29 |
30 def __init__(self, src): | |
31 self.src = src | |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
32 |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
33 # ephemeral data |
5 | 34 self._tmppath = None |
28 | 35 self._egg_info_path = None |
33 | 36 self._build_path = None |
5 | 37 |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
38 # TODO: list of temporary files/directories to be deleted |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
39 |
34 | 40 def _path(self): |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
41 """filesystem path to package directory""" |
7 | 42 |
43 # return cached copy if it exists | |
44 if self._tmppath: | |
45 return self._tmppath | |
46 | |
47 # fetch from the web if a URL | |
48 tmpfile = None | |
49 src = self.src | |
5 | 50 if utils.isURL(self.src): |
8 | 51 tmpfile = src = self.fetch() |
7 | 52 |
53 # unpack if an archive | |
28 | 54 if self._is_archive(src): |
8 | 55 try: |
56 self.unpack(src) | |
57 finally: | |
58 if tmpfile: | |
59 os.remove(tmpfile) | |
7 | 60 return self._tmppath |
61 | |
5 | 62 return self.src |
63 | |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
64 def fetch(self, filename=None): |
8 | 65 """fetch from remote source to a temporary file""" |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
66 if filename is None: |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
67 fd, filename = tempfile.mkstemp() |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
68 os.close(fd) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
69 fp = file(filename, 'w') |
15
8c8b7482772f
fix a few failures but still failing
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
70 resource = urllib2.urlopen(self.src) |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
71 fp.write(resource.read()) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
72 fp.close() |
7 | 73 return filename |
74 | |
75 def unpack(self, archive): | |
76 """unpack the archive to a temporary destination""" | |
77 # TODO: should handle zipfile additionally at least | |
78 # Ideally, this would be pluggable, etc | |
8 | 79 assert tarfile.is_tarfile(archive), "%s is not an archive" % self.src |
9
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
80 tf = tarfile.TarFile.open(archive) |
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
81 self._tmppath = tempfile.mkdtemp() |
19 | 82 members = tf.getmembers() |
83 | |
84 # cut off the top level directory | |
85 assert not [i for i in members if not os.path.sep in i.name] | |
86 tld = set() | |
87 for member in members: | |
88 directory, member.name = member.name.split(os.path.sep, 1) | |
89 tld.add(directory) | |
90 assert len(tld) == 1 | |
91 | |
92 # extract | |
93 for member in members: | |
94 tf.extract(member, path=self._tmppath) | |
95 tf.close() | |
7 | 96 |
28 | 97 def _is_archive(self, path): |
7 | 98 """returns if the filesystem path is an archive""" |
99 # TODO: should handle zipfile additionally at least | |
100 # Ideally, this would be pluggable, etc | |
101 return tarfile.is_tarfile(path) | |
9
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
102 |
28 | 103 def _cleanup(self): |
9
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
104 if self._tmppath: |
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
105 shutil.rmtree(self._tmppath) |
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
106 self._tmppath = None |
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
107 |
18
4c4d1e194bf7
leave in debugging code for now
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
108 # __del__ = cleanup |
11 | 109 |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
110 ### python-package-specific functionality |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
111 |
28 | 112 def _egg_info(self): |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
113 """build the egg_info directory""" |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
114 |
28 | 115 if self._egg_info_path: |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
116 # return cached copy |
28 | 117 return self._egg_info_path |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
118 |
34 | 119 directory = self._path() |
16 | 120 setup_py = os.path.join(directory, 'setup.py') |
121 if not os.path.exists(setup_py): | |
17 | 122 raise AssertionError("%s does not exist" % setup_py) |
11 | 123 |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
124 # setup the egg info |
19 | 125 call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=subprocess.PIPE) |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
126 |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
127 # get the .egg-info directory |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
128 egg_info = [i for i in os.listdir(directory) |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
129 if i.endswith('.egg-info')] |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
130 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info) |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
131 egg_info = os.path.join(directory, egg_info[0]) |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
132 assert os.path.isdir(egg_info), "%s is not a directory" % egg_info |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
133 |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
134 # cache it |
28 | 135 self._egg_info_path = egg_info |
136 return self._egg_info_path | |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
137 |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
138 def info(self): |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
139 """return info dictionary for package""" |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
140 # could use pkginfo |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
141 |
28 | 142 egg_info = self._egg_info() |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
143 |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
144 # read the package information |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
145 pkg_info = os.path.join(egg_info, 'PKG-INFO') |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
146 info_dict = {} |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
147 for line in file(pkg_info).readlines(): |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
148 if not line or line[0].isspace(): |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
149 continue # XXX neglects description |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
150 assert ':' in line |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
151 key, value = [i.strip() for i in line.split(':', 1)] |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
152 info_dict[key] = value |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
153 |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
154 # return the information |
20
11bc01a089e7
return only the dictionary
Jeff Hammel <jhammel@mozilla.com>
parents:
19
diff
changeset
|
155 return info_dict |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
156 |
11 | 157 def dependencies(self): |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
158 """return the dependencies""" |
32 | 159 # TODO: should probably have a more detailed dict: |
160 # {'mozinfo': {'version': '>= 0.2', | |
161 # 'url': 'http://something.com/'}} | |
21
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
162 # get the egg_info directory |
28 | 163 egg_info = self._egg_info() |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
164 |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
165 # read the dependencies |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
166 requires = os.path.join(egg_info, 'requires.txt') |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
167 if os.path.exists(requires): |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
168 dependencies = [i.strip() for i in file(requires).readlines() if i.strip()] |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
169 else: |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
170 dependencies = [] |
21
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
171 dependencies = dict([(i, None) for i in dependencies]) |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
172 |
21
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
173 # read the dependency links |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
174 dependency_links = os.path.join(egg_info, 'dependency_links.txt') |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
175 if os.path.exists(dependency_links): |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
176 links = [i.strip() for i in file(dependency_links).readlines() if i.strip()] |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
177 for link in links: |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
178 # XXX pretty ghetto |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
179 assert '#egg=' in link |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
180 url, dep = link.split('#egg=', 1) |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
181 if dep in dependencies: |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
182 dependencies[dep] = link |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
183 |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
184 return dependencies |
24 | 185 |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
186 def extension(self): |
35 | 187 """filename extension of the package""" |
188 | |
189 package = self.package() | |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
190 |
35 | 191 # determine the extension (XXX hacky) |
192 extensions = ('.tar.gz', '.zip', '.tar.bz2') | |
193 for ext in extensions: | |
194 if package.endsiwth(ext): | |
195 return ext | |
196 | |
197 raise Exception("Extension %s not found: %s" % (extensions, package)) | |
198 | |
199 def package(self, destination=None): | |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
200 """ |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
201 repackage the package to ensure its actually in the right form |
34 | 202 and return the path to the destination |
203 - destination: if given, path to put the build in [TODO] | |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
204 """ |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
205 |
33 | 206 if self._build_path: |
34 | 207 if destination: |
208 shutil.copy(self._build_path, destination) | |
209 return os.path.abspath(destination) | |
210 | |
211 # return cached copy | |
33 | 212 return self._build_path |
213 | |
34 | 214 path = self._path() |
215 dist = os.path.join(path, 'dist') | |
216 if os.path.exists(dist): | |
217 shutil.rmtree(dist) | |
218 | |
219 call([sys.executable, 'setup.py', 'sdist'], cwd=path, stdout=subprocess.PIPE) | |
220 | |
221 assert os.path.exists(dist) | |
222 contents = os.listdir(dist) | |
223 assert len(contents) == 1 | |
224 | |
225 self._build_path = os.path.join(dist, contents[0]) | |
226 | |
227 # destination | |
228 # use an evil recursive trick | |
229 return self.repackage(destination=destination) | |
230 if destination: | |
231 shutil.copy(self._build_path, destination) | |
232 return destination | |
233 | |
234 return self._build_path | |
235 | |
24 | 236 def download(self, directory): |
237 """download a package and all its dependencies using pip""" | |
28 | 238 if not os.path.exists(directory): |
239 os.makedirs(directory) | |
240 assert os.path.isdir(directory) | |
241 pip.main(['install', '--download', directory, self.src]) | |
242 | |
243 def pypi(self, directory): | |
244 """ | |
245 download packages for a pypi directory structure | |
246 http://k0s.org/portfolio/pypi.html | |
247 """ | |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
248 if not os.path.exists(directory): |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
249 os.makedirs(directory) |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
250 assert os.path.isdir(directory) |
28 | 251 tempdir = tempfile.mkdtemp() |
252 try: | |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
253 self.download(tempdir) |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
254 for package in os.listdir(tempdir): |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
255 |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
256 # full path |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
257 src = os.path.join(tempdir, package) |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
258 |
35 | 259 # make a package of the thing |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
260 package = Package(src) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
261 |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
262 # # get destination dirname, filename |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
263 # try: |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
264 # dirname, filename = pypi.pypi_path(src) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
265 # except ValueError: |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
266 # # PKG-INFO not found |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
267 # pass # TODO |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
268 |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
269 # # make the directory if it doesn't exist |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
270 # subdir = os.path.join(directory, dirname) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
271 # if not os.path.exists(subdir): |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
272 # os.makedirs(subdir) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
273 # assert os.path.isdir(subdir) |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
274 |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
275 # # move the file |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
276 # shutil.move(src, os.path.join(subdir, filename)) |
28 | 277 finally: |
278 shutil.rmtree(tempdir) | |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
279 |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
280 def pypi_path(self, path): |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
281 """ |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
282 returns subpath 2-tuple appropriate for pypi path structure: |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
283 http://k0s.org/portfolio/pypi.html |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
284 """ |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
285 info = self.info() |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
286 # sdist = pkginfo.sdist.SDist(path) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
287 |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
288 # determine the extension (XXX hacky) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
289 extensions = ('.tar.gz', '.zip', '.tar.bz2') |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
290 for ext in extensions: |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
291 import pdb; pdb.set_trace() |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
292 if sdist.filename.endswith(ext): |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
293 break |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
294 else: |
35 | 295 |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
296 |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
297 # get the filename destination |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
298 filename = '%s-%s%s' % (info['name'], ext) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
299 return sdist.name, filename |