def _UpdateProductDataFromCatalog(cls, catalog_plist): """Updates models.AppleSUSProduct model from a catalog plist object. Args: catalog_plist: plist.ApplePlist object. Returns: list of new models.AppleSUSProduct objects, or empty list. """ if 'Products' not in catalog_plist: logging.error('Products not found in Apple Updates catalog') return [] new_products = [] # Create a dict of all previously processed product IDs for fast lookup. existing_products = set() products_query = models.AppleSUSProduct.all().filter( 'deprecated =', False) for product in products_query: existing_products.add(product.product_id) # Loop over all products IDs in the Apple Updates catalog, adding any new # products to the models.AppleSUSProduct model. catalog_product_keys = catalog_plist.get('Products', {}).keys() catalog_product_keys.sort() for key in catalog_product_keys: if key in existing_products: continue # This product has already been processed in the past. # Download and parse distribution metadata. distributions = catalog_plist['Products'][key]['Distributions'] dist_url = distributions.get('English', None) or distributions.get( 'en', None) if not dist_url: logging.error( 'No english distributions exists for product %s; skipping.', key) continue # No english distribution exists :( r = urllib2.urlopen(dist_url) if r.code != httplib.OK: continue dist_str = r.read() dist = applesus.DistFileDocument() dist.LoadDocument(dist_str) product = models.AppleSUSProduct(key_name=key) product.product_id = key product.name = dist.title product.apple_mtime = catalog_plist['Products'][key]['PostDate'] product.version = dist.version product.description = dist.description product.tracks = [common.UNSTABLE] product.restart_required = dist.restart_required if not dist.restart_required and settings.APPLE_AUTO_UNATTENDED_ENABLED: product.unattended = True else: product.unattended = False # Parse package download URLs. for package in catalog_plist['Products'][key]['Packages']: product.package_urls.append(package.get('URL')) product.put() new_products.append(product) return new_products
def setUp(self): mox.MoxTestBase.setUp(self) self.stubs = stubout.StubOutForTesting() self.dfd = applesus.DistFileDocument()
def _UpdateProductDataFromCatalog(self, catalog_plist): """Updates models.AppleSUSProduct model from a catalog plist object. Args: catalog_plist: plist.ApplePlist object. Returns: list of new models.AppleSUSProduct objects, or empty list. """ if 'Products' not in catalog_plist: logging.error('Products not found in Apple Updates catalog') return [] new_products = [] # Create a dict of all previously processed product IDs for fast lookup. existing_products = {} products_query = models.AppleSUSProduct.all() for product in products_query: existing_products[product.product_id] = True # Loop over all products IDs in the Apple Updates catalog, adding any new # products to the models.AppleSUSProduct model. catalog_product_keys = catalog_plist.get('Products', {}).keys() catalog_product_keys.sort() for key in catalog_product_keys: if key in existing_products: continue # This product has already been processed in the past. #logging.debug('Processing new product: %s', key) distributions = catalog_plist['Products'][key]['Distributions'] url = distributions.get('English', None) or distributions.get( 'en', None) if not url: logging.error( 'No english distributions exists for product %s; skipping.', key) continue # No english distribution exists :( r = urllib2.urlopen(url) if r.code != 200: #logging.warning('Skipping dist where HTTP status != 200') continue dist_str = r.read() dist = applesus.DistFileDocument() dist.LoadDocument(dist_str) product = models.AppleSUSProduct(key_name=key) product.product_id = key product.name = dist.title product.apple_mtime = catalog_plist['Products'][key]['PostDate'] product.version = dist.version product.description = dist.description product.tracks = [common.UNSTABLE] product.restart_required = dist.restart_required if not dist.restart_required and settings.APPLE_AUTO_UNATTENDED_ENABLED: product.unattended = True else: product.unattended = False product.put() new_products.append(product) #logging.debug('Product complete: %s', product.name) return new_products