Mercurial > hg > PaInt
comparison paint/package.py @ 40:06f21791eba1
add yet another indirection layer
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Fri, 30 Mar 2012 15:58:13 -0700 |
| parents | cc25499e9485 |
| children | 97a7b740ddab |
comparison
equal
deleted
inserted
replaced
| 39:cc25499e9485 | 40:06f21791eba1 |
|---|---|
| 34 | 34 |
| 35 # ephemeral data | 35 # ephemeral data |
| 36 self._tmppath = None | 36 self._tmppath = None |
| 37 self._egg_info_path = None | 37 self._egg_info_path = None |
| 38 self._build_path = None | 38 self._build_path = None |
| 39 self._pkg_info_path = None | |
| 39 | 40 |
| 40 # TODO: list of temporary files/directories to be deleted | 41 # TODO: list of temporary files/directories to be deleted |
| 41 | 42 |
| 42 def _path(self): | 43 def _path(self): |
| 43 """filesystem path to package directory""" | 44 """filesystem path to package directory""" |
| 149 | 150 |
| 150 # cache it | 151 # cache it |
| 151 self._egg_info_path = egg_info | 152 self._egg_info_path = egg_info |
| 152 return self._egg_info_path | 153 return self._egg_info_path |
| 153 | 154 |
| 155 def _pkg_info(self): | |
| 156 """returns path to PKG-INFO file""" | |
| 157 | |
| 158 if self._pkg_info_path: | |
| 159 # return cached value | |
| 160 return self._pkg_info_path | |
| 161 | |
| 162 try: | |
| 163 egg_info = self._egg_info() | |
| 164 except BaseException, exception: | |
| 165 # try to get the package info from a file | |
| 166 path = self._path() | |
| 167 pkg_info = os.path.join(path, 'PKG-INFO') | |
| 168 if os.path.exists(pkg_info): | |
| 169 self._pkg_info_path = pkg_info | |
| 170 return self._pkg_info_path | |
| 171 raise Exception("Cannot find or generate PKG-INFO") | |
| 172 | |
| 173 pkg_info = os.path.join(egg_info, 'PKG-INFO') | |
| 174 assert os.path.exists(pkg_info) | |
| 175 self._pkg_info_path = pkg_info | |
| 176 return self._pkg_info_path | |
| 177 | |
| 154 def info(self): | 178 def info(self): |
| 155 """return info dictionary for package""" | 179 """return info dictionary for package""" |
| 156 # could use pkginfo | 180 # could use pkginfo module |
| 157 | 181 |
| 158 if self._pkg_info_path: | 182 pkg_info = self._pkg_info() |
| 159 pkg_info = self._pkg_info_path | |
| 160 else: | |
| 161 try: | |
| 162 egg_info = self._egg_info() | |
| 163 pkg_info = os.path.join(egg_info, 'PKG-INFO') | |
| 164 except BaseException, exception: | |
| 165 # try to get the package info from a file | |
| 166 raise NotImplementedError("TODO: try to get the package info from a file") | |
| 167 | 183 |
| 168 # read the package information | 184 # read the package information |
| 169 info_dict = {} | 185 info_dict = {} |
| 170 for line in file(pkg_info).readlines(): | 186 for line in file(pkg_info).readlines(): |
| 171 if not line or line[0].isspace(): | 187 if not line or line[0].isspace(): |
