def uptake(request): """ping mirror uptake""" product = request.GET.get("product", None) os = request.GET.get("os", None) fuzzy = request.GET.get("fuzzy", False) xml = XMLRenderer() if not product and not os: return xml.error("product and/or os are required GET parameters.", errno=101) if product: if fuzzy: products = Product.objects.filter(name__icontains=product) else: products = Product.objects.filter(name__exact=product) pids = [p.id for p in products] if not pids: return xml.error("No products found", errno=102) else: pids = None if os: if fuzzy: oses = OS.objects.filter(name__icontains=os) else: oses = OS.objects.filter(name__exact=os) osids = [o.id for o in oses] if not osids: return xml.error("No OSes found", errno=102) else: osids = None uptake = Location.get_mirror_uptake(products=pids, oses=osids) xml.prepare_uptake(uptake) return xml.render()
def setUp(self): super(LocationTestCase, self).setUp() # OSes for os in ["win", "osx", "linux"]: OS.objects.create(name=os) # locations self.locations = {} for p in self.products: self.locations[p.name] = [] for os in OS.objects.all(): path = "/%s/location.%s.bin" % (p.name, os) loc = Location(product=p, os=os, path=path) loc.save() self.locations[p.name].append(loc)
def setUp(self): super(LocationTestCase, self).setUp() # OSes for os in ['win', 'osx', 'linux']: OS.objects.create(name=os) # locations self.locations = {} for p in self.products: self.locations[p.name] = [] for os in OS.objects.all(): path = '/%s/location.%s.bin' % (p.name, os) loc = Location(product=p, os=os, path=path) loc.save() self.locations[p.name].append(loc)
def uptake(request): """ping mirror uptake""" product = request.GET.get('product', None) os = request.GET.get('os', None) fuzzy = request.GET.get('fuzzy', False) xml = XMLRenderer() if not product and not os: return xml.error('product and/or os are required GET parameters.', errno=101) if product: if fuzzy: products = Product.objects.filter(name__icontains=product) else: products = Product.objects.filter(name__exact=product) pids = [p.id for p in products] if not pids: return xml.error('No products found', errno=102) else: pids = None if os: if fuzzy: oses = OS.objects.filter(name__icontains=os) else: oses = OS.objects.filter(name__exact=os) osids = [o.id for o in oses] if not osids: return xml.error('No OSes found', errno=102) else: osids = None uptake = Location.get_mirror_uptake(products=pids, oses=osids) xml.prepare_uptake(uptake) return xml.render()
return xml.error('product, os, and path are required POST parameters.', errno=101) try: product = Product.objects.get(name=prodname) os = OS.objects.get(name=osname) except (Product.DoesNotExist, OS.DoesNotExist), e: return xml.error(e) # do not make duplicates dupes = Location.objects.filter(product=product, os=os).count() if dupes: return xml.error('The specified location already exists.', errno=104) try: location = Location(product=product, os=os, path=path) location.save(force_insert=True) except Exception, e: return xml.error(e) locations = Location.objects.filter(pk=location.pk) # success: return the single new location to the user xml.prepare_locations(product, locations) return xml.render() @require_POST @csrf_exempt @is_staff_or_basicauth(HTTP_AUTH_REALM) def location_delete(request): """Remove a location from the DB"""
return xml.error('product, os, and path are required POST parameters.', errno=101) try: product = Product.objects.get(name=prodname) os = OS.objects.get(name=osname) except (Product.DoesNotExist, OS.DoesNotExist), e: return xml.error(e) # do not make duplicates dupes = Location.objects.filter(product=product, os=os).count() if dupes: return xml.error('The specified location already exists.', errno=104) try: location = Location(product=product, os=os, path=path) location.save(force_insert=True) except Exception, e: return xml.error(e) locations = Location.objects.filter(pk=location.pk) # success: return the single new location to the user xml.prepare_locations(product, locations) return xml.render() @require_POST @csrf_exempt @has_perm_or_basicauth("mirror.modify_location", HTTP_AUTH_REALM) def location_modify(request): xml = XMLRenderer()