annotate paint/package.py @ 64:1a279bac0afa

start moving this monster to a package information provider
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 25 Jan 2013 13:41:37 -0800
parents ad174d9f396d
children 6d6f5c5c26d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
e230ac76aaa4 stub package model
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
e230ac76aaa4 stub package model
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 package model for python PAckage INTrospection
e230ac76aaa4 stub package model
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
e230ac76aaa4 stub package model
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
5 # TODO: use pkginfo.sdist more
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
6
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 53
diff changeset
7 import info
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
8 import os
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
9 import pip
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
10 import shutil
19
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
11 import subprocess
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
12 import sys
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
13 import tarfile
5
5b74792d46e4 stub package model;
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
14 import tempfile
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
15 import urllib2
21
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
16 import urlparse
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
17 import utils
5
5b74792d46e4 stub package model;
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
18
62
726008cff4e3 remove code supporting old version
Jeff Hammel <jhammel@mozilla.com>
parents: 58
diff changeset
19 from subprocess import check_call as call
19
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
20
10
d63ae03cc300 * fix up __init__ imports
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
21 __all__ = ['Package']
d63ae03cc300 * fix up __init__ imports
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
22
4
e230ac76aaa4 stub package model
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 class Package(object):
33
5efb61fde8aa improved docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
24 """
5efb61fde8aa improved docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
25 class for python package introspection.
5efb61fde8aa improved docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
26 constructor takes the package 'src'
5efb61fde8aa improved docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
27 """
4
e230ac76aaa4 stub package model
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28
50
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
29 def __init__(self, src, verbose=True):
63
ad174d9f396d docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
30 """
ad174d9f396d docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
31 - src : URL or filesystem path to the package
ad174d9f396d docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
32 """
4
e230ac76aaa4 stub package model
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 self.src = src
50
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
34 self.verbose = verbose
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
35
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
36 # ephemeral data
5
5b74792d46e4 stub package model;
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
37 self._tmppath = None
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
38 self._egg_info_path = None
33
5efb61fde8aa improved docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
39 self._build_path = None
40
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
40 self._pkg_info_path = None
5
5b74792d46e4 stub package model;
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
41
64
1a279bac0afa start moving this monster to a package information provider
Jeff Hammel <jhammel@mozilla.com>
parents: 63
diff changeset
42 # package metadata provider
1a279bac0afa start moving this monster to a package information provider
Jeff Hammel <jhammel@mozilla.com>
parents: 63
diff changeset
43 # TODO: this should be chooseable but currently the keys of the
1a279bac0afa start moving this monster to a package information provider
Jeff Hammel <jhammel@mozilla.com>
parents: 63
diff changeset
44 # interfaces are not the same
1a279bac0afa start moving this monster to a package information provider
Jeff Hammel <jhammel@mozilla.com>
parents: 63
diff changeset
45 self.package_info = info.EggInfo
1a279bac0afa start moving this monster to a package information provider
Jeff Hammel <jhammel@mozilla.com>
parents: 63
diff changeset
46
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
47 # TODO: list of temporary files/directories to be deleted
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
48
49
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
49 def _log(self, message):
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
50 if self.verbose:
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
51 print '>>> %s' % message
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
52
34
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
53 def _path(self):
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
54 """filesystem path to package directory"""
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
55
51
8b4243893474 more cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
56 self._log(">>> _path:Getting path to package")
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
57
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
58 # return cached copy if it exists
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
59 if self._tmppath:
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
60 return self._tmppath
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
61
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
62 # fetch from the web if a URL
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
63 tmpfile = None
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
64 src = self.src
5
5b74792d46e4 stub package model;
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
65 if utils.isURL(self.src):
8
c1181e9c9ca2 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
66 tmpfile = src = self.fetch()
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
67
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
68 # unpack if an archive
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
69 if self._is_archive(src):
8
c1181e9c9ca2 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
70 try:
37
36e70712fc9a things are just awful
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
71 self._unpack(src)
8
c1181e9c9ca2 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
72 finally:
c1181e9c9ca2 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
73 if tmpfile:
c1181e9c9ca2 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
74 os.remove(tmpfile)
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
75 return self._tmppath
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
76
5
5b74792d46e4 stub package model;
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
77 return self.src
5b74792d46e4 stub package model;
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
78
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
79 def fetch(self, filename=None):
8
c1181e9c9ca2 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
80 """fetch from remote source to a temporary file"""
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
81 if filename is None:
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
82 fd, filename = tempfile.mkstemp()
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
83 os.close(fd)
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
84 fp = file(filename, 'w')
15
8c8b7482772f fix a few failures but still failing
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
85 resource = urllib2.urlopen(self.src)
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
86 fp.write(resource.read())
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
87 fp.close()
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
88 return filename
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
89
37
36e70712fc9a things are just awful
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
90 def _unpack(self, archive):
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
91 """unpack the archive to a temporary destination"""
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
92 # TODO: should handle zipfile additionally at least
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
93 # Ideally, this would be pluggable, etc
8
c1181e9c9ca2 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
94 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
95 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
96 self._tmppath = tempfile.mkdtemp()
19
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
97 members = tf.getmembers()
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
98
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
99 # cut off the top level directory
37
36e70712fc9a things are just awful
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
100 members = [i for i in members if os.path.sep in i.name]
19
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
101 tld = set()
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
102 for member in members:
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
103 directory, member.name = member.name.split(os.path.sep, 1)
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
104 tld.add(directory)
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
105 assert len(tld) == 1
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
106
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
107 # extract
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
108 for member in members:
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
109 tf.extract(member, path=self._tmppath)
c54db80d6e7f fix test
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
110 tf.close()
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
111
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
112 def _is_archive(self, path):
7
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
113 """returns if the filesystem path is an archive"""
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
114 # TODO: should handle zipfile additionally at least
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
115 # Ideally, this would be pluggable, etc
a7bf894c96c7 yet more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
116 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
117
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
118 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
119 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
120 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
121 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
122
18
4c4d1e194bf7 leave in debugging code for now
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
123 # __del__ = cleanup
11
c41a946d34af stub out info method
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
124
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
125 ### python-package-specific functionality
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
126
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
127 def _egg_info(self):
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
128 """build the egg_info directory"""
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
129
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
130 if self._egg_info_path:
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
131 # return cached copy
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
132 return self._egg_info_path
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
133
34
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
134 directory = self._path()
16
e6cdc58fc4f5 more helpful debugging
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
135 setup_py = os.path.join(directory, 'setup.py')
e6cdc58fc4f5 more helpful debugging
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
136 if not os.path.exists(setup_py):
17
e74fc40e1f64 interpolate string
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
137 raise AssertionError("%s does not exist" % setup_py)
11
c41a946d34af stub out info method
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
138
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
139 # setup the egg info
39
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
140 exception = None
38
c9d8abb2026f error handling
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
141 try:
39
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
142 code = call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=subprocess.PIPE)
45
bb0813966bff python 2.4 compatability
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
143 except Exception, exception:
39
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
144 pass
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
145 if code or exception:
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
146 message = """Failure to generate egg_info
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
147 - src: %s
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
148 - directory: %s
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
149 """ % (self.src, directory)
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
150 if exception:
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
151 sys.stderr.write(message)
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
152 raise exception
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
153 else:
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
154 raise Exception(message)
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
155
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
156 # get the .egg-info directory
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
157 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
158 if i.endswith('.egg-info')]
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
159 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
160 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
161 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
162
14
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
163 # cache it
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
164 self._egg_info_path = egg_info
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
165 return self._egg_info_path
14
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
166
40
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
167 def _pkg_info(self):
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
168 """returns path to PKG-INFO file"""
14
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
169
39
cc25499e9485 note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
170 if self._pkg_info_path:
40
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
171 # return cached value
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
172 return self._pkg_info_path
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
173
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
174 try:
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
175 egg_info = self._egg_info()
45
bb0813966bff python 2.4 compatability
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
176 except Exception, exception:
40
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
177 # try to get the package info from a file
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
178 path = self._path()
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
179 pkg_info = os.path.join(path, 'PKG-INFO')
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
180 if os.path.exists(pkg_info):
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
181 self._pkg_info_path = pkg_info
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
182 return self._pkg_info_path
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
183 raise Exception("Cannot find or generate PKG-INFO")
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
184
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
185 pkg_info = os.path.join(egg_info, 'PKG-INFO')
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
186 assert os.path.exists(pkg_info)
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
187 self._pkg_info_path = pkg_info
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
188 return self._pkg_info_path
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
189
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
190 def info(self):
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
191 """return info dictionary for package"""
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
192 # could use pkginfo module
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
193
53
c588375a7ce4 starting a new strawman to work out kinks
Jeff Hammel <jhammel@mozilla.com>
parents: 52
diff changeset
194 self._log(">>> Getting the info")
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
195
40
06f21791eba1 add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
196 pkg_info = self._pkg_info()
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
197
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
198 # read the package information
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
199 info_dict = {}
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
200 for line in file(pkg_info).readlines():
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
201 if not line or line[0].isspace():
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
202 continue # XXX neglects description
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
203 assert ':' in line
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
204 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
205 info_dict[key] = value
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
206
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
207 # return the information
20
11bc01a089e7 return only the dictionary
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
208 return info_dict
13
0dd1f8f83be2 moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
209
11
c41a946d34af stub out info method
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
210 def dependencies(self):
14
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
211 """return the dependencies"""
32
f2e31ac03bb3 flushing this out
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
212 # TODO: should probably have a more detailed dict:
f2e31ac03bb3 flushing this out
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
213 # {'mozinfo': {'version': '>= 0.2',
f2e31ac03bb3 flushing this out
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
214 # 'url': 'http://something.com/'}}
21
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
215 # get the egg_info directory
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
216 egg_info = self._egg_info()
14
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
217
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
218 # read the dependencies
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
219 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
220 if os.path.exists(requires):
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
221 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
222 else:
6d27c2136163 a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
223 dependencies = []
21
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
224 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
225
21
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
226 # read the dependency links
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
227 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
228 if os.path.exists(dependency_links):
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
229 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
230 for link in links:
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
231 # XXX pretty ghetto
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
232 assert '#egg=' in link
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
233 url, dep = link.split('#egg=', 1)
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
234 if dep in dependencies:
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
235 dependencies[dep] = link
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
236
4df3e715817d now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
237 return dependencies
24
54c1e7e43a54 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
238
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
239 def extension(self):
35
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
240 """filename extension of the package"""
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
241
49
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
242 print ">>> extension:Getting package"
35
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
243 package = self.package()
49
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
244 print ">>> extension:package=%s" % package
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
245
35
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
246 # determine the extension (XXX hacky)
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
247 extensions = ('.tar.gz', '.zip', '.tar.bz2')
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
248 for ext in extensions:
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
249 if package.endswith(ext):
35
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
250 return ext
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
251
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
252 raise Exception("Extension %s not found: %s" % (extensions, package))
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
253
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
254 def package(self, destination=None):
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
255 """
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
256 repackage the package to ensure its actually in the right form
34
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
257 and return the path to the destination
49
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
258 - destination: if given, path to put the build in
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
259 """
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
260
49
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
261 self._log("package: Getting package directory, destination=%s" % repr(destination))
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
262
33
5efb61fde8aa improved docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
263 if self._build_path:
49
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
264 self._log("package: build_path already set: %s" % self._build_path)
34
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
265 if destination:
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
266 shutil.copy(self._build_path, destination)
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
267 return os.path.abspath(destination)
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
268
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
269 # return cached copy
33
5efb61fde8aa improved docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
270 return self._build_path
5efb61fde8aa improved docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
271
34
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
272 path = self._path()
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
273 dist = os.path.join(path, 'dist')
49
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
274 self._log("package: dist directory: %s; (path=%s)" % (dist, path))
34
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
275 if os.path.exists(dist):
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
276 shutil.rmtree(dist)
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
277
49
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
278 command = [sys.executable, 'setup.py', 'sdist']
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
279 self._log("package: running: %s" % ' '.join(command))
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
280 call(command, cwd=path)
85374a69cf89 call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents: 48
diff changeset
281 self._log("package: done running setup.py dist")
34
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
282
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
283 assert os.path.exists(dist)
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
284 contents = os.listdir(dist)
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
285 assert len(contents) == 1
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
286
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
287 self._build_path = os.path.join(dist, contents[0])
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
288
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
289 # destination
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
290 # use an evil recursive trick
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
291 if destination:
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
292 return self.package(destination=destination)
34
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
293
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
294 return self._build_path
acb2f4896291 working towards something
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
295
24
54c1e7e43a54 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
296 def download(self, directory):
54c1e7e43a54 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
297 """download a package and all its dependencies using pip"""
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
298 if not os.path.exists(directory):
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
299 os.makedirs(directory)
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
300 assert os.path.isdir(directory)
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
301 pip.main(['install', '--download', directory, self.src])
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
302
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
303 def pypi(self, directory):
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
304 """
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
305 download packages for a pypi directory structure
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
306 http://k0s.org/portfolio/pypi.html
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
307 """
29
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
308 if not os.path.exists(directory):
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
309 os.makedirs(directory)
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
310 assert os.path.isdir(directory)
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
311 tempdir = tempfile.mkdtemp()
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
312 try:
29
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
313 self.download(tempdir)
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
314 files = os.listdir(tempdir)
52
026d693cd561 cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
315 self._log(">>> Files: %s" % files)
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
316 for f in files:
29
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
317
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
318 # full path
47
213cf933366d stupid mistakes
Jeff Hammel <jhammel@mozilla.com>
parents: 45
diff changeset
319 src = os.path.join(tempdir, f)
29
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
320
35
e8d73f9e99fb extension checking
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
321 # make a package of the thing
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
322 print ">>> pypi:Packaging %s" % src
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
323 package = Package(src)
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
324 print ">>> pypi:DONE packaging %s" % src
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
325
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
326 # get destination dirname, filename
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
327 print ">>> pypi:Getting PyPI path"
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
328 dirname, filename = package.pypi_path()
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
329 print ">>> pypi:DONE PyPI path: %s/%s" % (dirname, filename)
29
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
330
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
331 # make the directory if it doesn't exist
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
332 subdir = os.path.join(directory, dirname)
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
333 if not os.path.exists(subdir):
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
334 os.makedirs(subdir)
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
335 assert os.path.isdir(subdir)
29
59524b6d25c0 implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
336
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
337 # move the file
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
338 print ">>> pypi:Moving to PyPI path %s/%s" % (subdir, filename)
47
213cf933366d stupid mistakes
Jeff Hammel <jhammel@mozilla.com>
parents: 45
diff changeset
339 package.package(destination=os.path.join(subdir, filename))
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
340 print ">>> Done with %s" % src
28
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
341 finally:
c44fb4b6918b CLI sorta works
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
342 shutil.rmtree(tempdir)
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
343
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
344 def pypi_path(self):
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
345 """
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
346 returns subpath 2-tuple appropriate for pypi path structure:
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
347 http://k0s.org/portfolio/pypi.html
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
348 """
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
349 print ">>> pypi_path:Getting info"
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
350 info = self.info()
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
351 print ">>> pypi_path:DONE getting info"
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
352
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
353 # determine the extension
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
354 print ">>> pypi_path:Getting extension"
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
355 extension = self.extension()
48
abfb267e8332 debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
356 print ">>> pypi_path:DONE Getting extension: %s" % extension
31
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
357
5fb1844db0b2 back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
358 # get the filename destination
36
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
359 name = info['Name']
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
360 version = info['Version']
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
361 filename = '%s-%s%s' % (name, version, extension)
f59da9e6be37 this almost works, dammit
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
362 return name, filename