Changeset 69

Show
Ignore:
Timestamp:
06/20/06 15:31:28 (2 years ago)
Author:
mk
Message:

Better handling of setuptools errors.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/cheesecake/cheesecake_index.py

    r68 r69  
    825825        self.cleanup(remove_log_file=False) 
    826826 
    827         msg += "\n" + pad_msg("CHEESECAKE INDEX", 0) 
    828827        msg += "\nDetailed info available in log file %s" % self.logfile 
    829828 
     
    932931              Whenever package has been found on CheeseShop. 
    933932        """ 
     933        self.log.info("Trying to download package %s from PyPI using setuptools utilities" % self.name) 
     934 
    934935        try: 
    935             self.log.info("Trying to download package %s from PyPI using setuptools utilities" % self.name) 
    936936            from setuptools.package_index import PackageIndex 
    937937            from pkg_resources import Requirement 
    938938            from distutils import log 
    939  
     939            from distutils.errors import DistutilsError 
     940 
     941        except ImportError, e: 
     942            msg = "Error: setuptools is not installed and is required for downloading a package by name\n" 
     943            msg += "You can donwload and process a package by its full URL via the -u or --url option\n" 
     944            msg += "Example: python cheesecake.py --url=http://www.mems-exchange.org/software/durus/Durus-3.1.tar.gz" 
     945            self.raise_exception(msg) 
     946 
     947        try: 
    940948            # Temporarily set the log verbosity to INFO so we can capture setuptools info messages 
    941949            old_threshold = log.set_threshold(log.INFO) 
     
    951959            log.set_threshold(old_threshold) 
    952960 
    953             if output is None: 
    954                 self.raise_exception("Error: Could not find distribution for " + self.name) 
    955  
    956             # Defaults. 
    957             self.download_url = "" 
    958             self.distance_from_pypi = 0 
    959             self.found_on_cheeseshop = False 
    960  
    961             for line in captured_stdout.split('\n'): 
    962                 s = re.search(r"Reading http(.*)", line) 
    963                 if s: 
    964                     inspected_url = s.group(1) 
    965                     if not re.search(r"www.python.org\/pypi", inspected_url): 
    966                         self.distance_from_pypi += 1 
    967                     continue 
    968                 s = re.search(r"Downloading (.*)", line) 
    969                 if s: 
    970                     self.download_url = s.group(1) 
    971                     break 
    972  
    973             self.sandbox_pkg_file = output 
    974             self.package = self.get_package_from_path(output) 
    975             self.log.info("Downloaded package %s from %s" % (self.package, self.download_url)) 
    976  
    977             if re.search(r"cheeseshop.python.org", self.download_url): 
    978                 self.found_on_cheeseshop = True 
    979  
    980         except ImportError, e: 
    981             msg = "Error: setuptools is not installed and is required for downloading a package by name\n" 
    982             msg += "You can donwload and process a package by its full URL via the -u or --url option\n" 
    983             msg += "Example: python cheesecake.py --url=http://www.mems-exchange.org/software/durus/Durus-3.1.tar.gz" 
     961        except DistutilsError, e: 
     962            # Bring back old stdout. 
     963            captured_stdout = sys.stdout.read_buffer() 
     964            sys.stdout = old_stdout 
     965            log.set_threshold(old_threshold) 
     966 
     967            # Drop all setuptools output as INFO. 
     968            self.log.info("*** Begin setuptools output") 
     969            map(self.log.info, captured_stdout.splitlines()) 
     970            self.log.info(str(e)) 
     971            self.log.info("*** End setuptools output") 
     972 
     973            msg = "Error: setuptools returned an error: %s\n" % e 
    984974            self.raise_exception(msg) 
     975 
     976        if output is None: 
     977            self.raise_exception("Error: Could not find distribution for " + self.name) 
     978 
     979        # Defaults. 
     980        self.download_url = "" 
     981        self.distance_from_pypi = 0 
     982        self.found_on_cheeseshop = False 
     983 
     984        for line in captured_stdout.split('\n'): 
     985            s = re.search(r"Reading http(.*)", line) 
     986            if s: 
     987                inspected_url = s.group(1) 
     988                if not re.search(r"www.python.org\/pypi", inspected_url): 
     989                    self.distance_from_pypi += 1 
     990                continue 
     991            s = re.search(r"Downloading (.*)", line) 
     992            if s: 
     993                self.download_url = s.group(1) 
     994                break 
     995 
     996        self.sandbox_pkg_file = output 
     997        self.package = self.get_package_from_path(output) 
     998        self.log.info("Downloaded package %s from %s" % (self.package, self.download_url)) 
     999 
     1000        if re.search(r"cheeseshop.python.org", self.download_url): 
     1001            self.found_on_cheeseshop = True 
    9851002 
    9861003    def download_pkg(self): 
  • branches/mk/tests/unit/test_index_unpack.py

    r66 r69  
    5151            msg = "Could not unpack package %s ... exiting" % \ 
    5252                  os.path.join(default_temp_directory, package_file) 
    53             msg += "\n" + pad_msg("CHEESECAKE INDEX", 0) 
    5453            msg += "\nDetailed info available in log file %s" % self.logfile 
    5554            assert str(e) == msg