| 1356 | | error = None |
|---|
| 1357 | | try: |
|---|
| 1358 | | # Temporarily set the log verbosity to INFO so we can capture setuptools info messages. |
|---|
| 1359 | | old_threshold = log.set_threshold(log.INFO) |
|---|
| 1360 | | pkgindex = PackageIndex() |
|---|
| 1361 | | old_stdout = sys.stdout |
|---|
| 1362 | | sys.stdout = StdoutRedirector() |
|---|
| 1363 | | output = pkgindex.fetch(Requirement.parse(self.name), |
|---|
| 1364 | | self.sandbox, |
|---|
| 1365 | | force_scan=True, |
|---|
| 1366 | | source=False) |
|---|
| 1367 | | except DistutilsError, e: |
|---|
| 1368 | | error = e |
|---|
| | 1356 | def fetch_package(mode): |
|---|
| | 1357 | """Fetch package from PyPI. |
|---|
| | 1358 | |
|---|
| | 1359 | Mode can be one of: |
|---|
| | 1360 | * 'pypi_source': get source package from PyPI |
|---|
| | 1361 | * 'pypi_any': get source/egg package from PyPI |
|---|
| | 1362 | * 'any': get package from PyPI or local filesystem |
|---|
| | 1363 | |
|---|
| | 1364 | Returns tuple (status, output), where `status` is True |
|---|
| | 1365 | if fetch was successful and False if it failed. `output` |
|---|
| | 1366 | is PackageIndex.fetch() return value. |
|---|
| | 1367 | """ |
|---|
| | 1368 | if 'pypi' in mode: |
|---|
| | 1369 | pkgindex = PackageIndex(search_path=[]) |
|---|
| | 1370 | else: |
|---|
| | 1371 | pkgindex = PackageIndex() |
|---|
| | 1372 | |
|---|
| | 1373 | if mode == 'pypi_source': |
|---|
| | 1374 | source = True |
|---|
| | 1375 | else: |
|---|
| | 1376 | source = False |
|---|
| | 1377 | |
|---|
| | 1378 | try: |
|---|
| | 1379 | output = pkgindex.fetch(Requirement.parse(self.name), |
|---|
| | 1380 | self.sandbox, |
|---|
| | 1381 | force_scan=True, |
|---|
| | 1382 | source=source) |
|---|
| | 1383 | return True, output |
|---|
| | 1384 | except DistutilsError, e: |
|---|
| | 1385 | return False, e |
|---|
| | 1386 | |
|---|
| | 1387 | # Temporarily set the log verbosity to INFO so we can capture setuptools |
|---|
| | 1388 | # info messages. |
|---|
| | 1389 | old_threshold = log.set_threshold(log.INFO) |
|---|
| | 1390 | old_stdout = sys.stdout |
|---|
| | 1391 | sys.stdout = StdoutRedirector() |
|---|
| | 1392 | |
|---|
| | 1393 | # Try to get source package from PyPI first, then egg from PyPI, and if |
|---|
| | 1394 | # that fails search in locally installed packages. |
|---|
| | 1395 | for mode, info in [('pypi_source', "source package on PyPI"), |
|---|
| | 1396 | ('pypi_any', "egg on PyPI"), |
|---|
| | 1397 | ('any', "locally installed package")]: |
|---|
| | 1398 | msg = "Looking for %s... " % info |
|---|
| | 1399 | status, output = fetch_package(mode) |
|---|
| | 1400 | if status and output: |
|---|
| | 1401 | self.log.info(msg + "found!") |
|---|
| | 1402 | break |
|---|
| | 1403 | self.log.info(msg + "failed.") |
|---|