Example #1
0
 def _add_units(self, unit_inventory):
     """
     Determine the list of units contained in the upstream inventory
     but are not contained in the local inventory and add them.
     For each unit, this is performed in the following steps:
       1. Download the file (if defined) associated with the unit.
       2. Add the unit to the local inventory.
       3. Associate the unit to the repository.
     The unit is added only:
       1. If no file is associated with unit.
       2. The file associated with the unit is successfully downloaded.
     For units with files, the unit is added to the inventory as part of the
     transport callback.
     :param unit_inventory: The inventory of both upstream and local content units.
     :type unit_inventory: UnitInventory
     :return: The list of failed that failed to be added.
         Each item is: (unit, exception)
     :rtype: list
     """
     failed = []
     units = self._missing_units(unit_inventory)
     self.progress.push_step("add_units", len(units))
     batch = Batch()
     for unit, local_unit in units:
         if self.cancelled:
             break
         download = unit.get("_download")
         # unit has no file associated
         if not download:
             try:
                 self.add_unit(local_unit)
             except Exception, e:
                 failed.append((local_unit, e))
             continue
         url = download["url"]
         batch.add(url, local_unit)
Example #2
0
 def add(self, url, unit):
     n = random.random()
     Batch.add(self, 'http:/NOWHERE/FAIL_ME_%d' % n, unit)