Skip to content

Commit

Permalink
api: return fake uptake results (#55)
Browse files Browse the repository at this point in the history
We are turning off sentry, so uptake will no longer be added to the
database.
  • Loading branch information
oremj committed Feb 21, 2018
1 parent 7ca4ecd commit cd9bf8e
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,27 @@ def uptake(request):
return xml.error('product and/or os are required GET parameters.',
errno=101)

product_names = None
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:
product_names = [p.name for p in products]
if not product_names:
return xml.error('No products found', errno=102)
else:
pids = None

os_names = 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:
os_names = [o.name for o in oses]
if not os_names:
return xml.error('No OSes found', errno=102)
else:
osids = None

uptake = Location.get_mirror_uptake(products=pids, oses=osids)

xml.prepare_uptake(uptake)
xml.prepare_uptake_fake(products=product_names, oses=os_names)
return xml.render()


Expand Down Expand Up @@ -504,6 +500,32 @@ def prepare_locations(self, product, locations):
locnode.appendChild(self.doc.createTextNode(location.path))
prodnode.appendChild(locnode)

def prepare_uptake_fake(self, products, oses):
root = self.doc.createElement('mirror_uptake')
self.doc.appendChild(root)

for product in products:
for os_name in oses:
item = self.doc.createElement('item')

elem = self.doc.createElement('product')
elem.appendChild(self.doc.createTextNode(str(product)))
item.appendChild(elem)

elem = self.doc.createElement('os')
elem.appendChild(self.doc.createTextNode(str(os_name)))
item.appendChild(elem)

elem = self.doc.createElement('available')
elem.appendChild(self.doc.createTextNode(str(2000000)))
item.appendChild(elem)

elem = self.doc.createElement('total')
elem.appendChild(self.doc.createTextNode(str(2000000)))
item.appendChild(elem)

root.appendChild(item)

def prepare_uptake(self, uptake):
"""Product uptake"""
content_map = {'product': 'location__product__name',
Expand Down

0 comments on commit cd9bf8e

Please sign in to comment.