Esempio n. 1
0
 def _add_units(self, unit_inventory):
     """
     Determine the list of units contained in the parent inventory
     but are not contained in the child 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 child 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 parent and child 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, child_unit in units:
         if self.cancelled:
             break
         download = unit.get('_download')
         # unit has no file associated
         if not download:
             try:
                 self.add_unit(child_unit)
             except Exception, e:
                 failed.append((child_unit, e))
             continue
         url = download['url']
         batch.add(url, child_unit)
Esempio n. 2
0
 def add(self, url, unit):
     n = random.random()
     Batch.add(self, 'http:/NOWHERE/FAIL_ME_%d' % n, unit)