def GetResults(self):
     pid_id = StringToInt(self.request.get('id'))
     if pid_id is not None:
         results = Pid.all()
         results.filter('pid_id =', pid_id)
         results.filter('draft = ', False)
         return results
     return []
Beispiel #2
0
    def ClearPids(self):
        memcache.delete(memcache_keys.MANUFACTURER_PID_COUNT_KEY)
        memcache.delete(memcache_keys.MANUFACTURER_PID_COUNTS)
        for item in Command.all():
            item.delete()

        for item in Pid.all():
            item.delete()
        return ''
Beispiel #3
0
  def ClearPids(self):
    memcache.delete(memcache_keys.MANUFACTURER_PID_COUNT_KEY)
    memcache.delete(memcache_keys.MANUFACTURER_PID_COUNTS)
    for item in Command.all():
      item.delete()

    for item in Pid.all():
      item.delete()
    return ''
Beispiel #4
0
  def get(self):
    esta_manufacturer = common.GetManufacturer(self.ESTA_ID)
    self.response.headers['Content-Type'] = 'text/plain'

    # Can be '', 'esta', 'esta-draft', 'manufacturers' or 'manufacturer-names'
    pid_selection = self.request.get('pids')
    if pid_selection == 'manufacturer-names':
      manufacturers = []
      query = Manufacturer.all()
      query.order('name')
      for manufacturer in query:
        if manufacturer.esta_id in [self.ESTA_ID, 0xffff]:
          continue

        self.WriteManufacturer(manufacturer, [])
    else:
      pids = Pid.all()

      if pid_selection == 'esta':
        pids.filter('draft =', False)
        pids.filter('manufacturer = ', esta_manufacturer)
      elif pid_selection == 'esta-draft':
        pids.filter('draft =', True)
        pids.filter('manufacturer = ', esta_manufacturer)
      elif pid_selection == "manufacturers":
        pids.filter('manufacturer != ', esta_manufacturer)

      manufacturers = {}
      esta_pids = []
      for pid in pids:
        if pid.manufacturer.esta_id == self.ESTA_ID:
          esta_pids.append(pid)
        else:
          # Build the hash of manufacturer pids by manufacturer
          manufacturers.setdefault(pid.manufacturer.esta_id, []).append(pid)

      esta_pids.sort(key=lambda p: p.pid_id)
      for pid in esta_pids:
        self.WritePid(pid)

      for manufacturer_id in sorted(manufacturers):
        manufacturer_pids = manufacturers[manufacturer_id]
        manufacturer_pids.sort(key=lambda p: p.pid_id)
        self.WriteManufacturer(manufacturers[manufacturer_id][0].manufacturer,
                               manufacturer_pids)

    query = LastUpdateTime.all()
    if pid_selection == 'manufacturer-names':
      query.filter('name = ', timestamp_keys.MANUFACTURERS)
    else:
      query.filter('name = ', timestamp_keys.PIDS)
    update_time = query.fetch(1)
    if update_time:
      timestamp = TimestampToInt(update_time[0].update_time)
      self.Write('version: %d' % timestamp)
    def GetResults(self):
        name = self.request.get('name')
        if name is not None:
            name = name.strip().replace(' ', '_').upper()
            # do full string matching for now
            results = Pid.all()
            results.filter('draft = ', False)
            results.filter('name =', name)

            return results
        return []
Beispiel #6
0
    def BuildResponse(self):
        param_counts = {}
        responders = 0
        max_manufacturer_pids = 0
        max_manufacturer_responder = ''
        max_pids = 0
        max_pids_responder = ''
        for responder in Responder.all():
            params = []
            version = common.GetLatestSoftware(responder)
            if version:
                params = version.supported_parameters

            manufacturer_pids = 0
            for param in params:
                param_counts.setdefault(param, 0)
                param_counts[param] += 1
                if param >= 0x8000:
                    manufacturer_pids += 1
            if params:
                responders += 1
            if manufacturer_pids > max_manufacturer_pids:
                max_manufacturer_responder = responder.model_description
                max_manufacturer_pids = manufacturer_pids
            if len(params) > max_pids:
                max_pids_responder = responder.model_description
                max_pids = len(params)

        pids = []
        for param, count in param_counts.iteritems():
            param_info = {
                'id': param,
                'count': count,
            }
            if param < 0x8000:
                query = Pid.all()
                query.filter('pid_id = ', param)
                pid = query.fetch(1)
                if pid:
                    param_info['name'] = pid[0].name
            pids.append(param_info)

        output = {
            'count':
            responders,
            'max_manufacturer_pids':
            (max_manufacturer_responder, max_manufacturer_pids),
            'max_pids': (max_pids_responder, max_pids),
            'pids':
            pids,
        }
        return json.dumps(output)
Beispiel #7
0
  def ManufacturerPidCount(self):
    """Return the number of manufacturer PIDs."""
    manufacturer_pids = memcache.get(memcache_keys.MANUFACTURER_PID_COUNT_KEY)
    if manufacturer_pids is None:
      manufacturer_pids = 0

      for pid in Pid.all():
        if pid.manufacturer.esta_id != self.ESTA_ID:
          manufacturer_pids += 1
      if not memcache.add(memcache_keys.MANUFACTURER_PID_COUNT_KEY,
                          manufacturer_pids):
        logging.error("Memcache set failed.")
    return manufacturer_pids
Beispiel #8
0
  def BuildResponse(self):
    param_counts = {}
    responders = 0
    max_manufacturer_pids = 0
    max_manufacturer_responder = ''
    max_pids = 0
    max_pids_responder = ''
    for responder in Responder.all():
      params = []
      version = common.GetLatestSoftware(responder)
      if version:
        params = version.supported_parameters

      manufacturer_pids = 0
      for param in params:
        param_counts.setdefault(param, 0)
        param_counts[param] += 1
        if param >= 0x8000:
          manufacturer_pids += 1
      if params:
        responders += 1
      if manufacturer_pids > max_manufacturer_pids:
        max_manufacturer_responder = responder.model_description
        max_manufacturer_pids = manufacturer_pids
      if len(params) > max_pids:
        max_pids_responder = responder.model_description
        max_pids = len(params)

    pids = []
    for param, count in param_counts.iteritems():
      param_info = {
        'id': param,
        'count': count,
      }
      if param < 0x8000:
        query = Pid.all()
        query.filter('pid_id = ', param)
        pid = query.fetch(1)
        if pid:
          param_info['name'] = pid[0].name
      pids.append(param_info)

    output = {
        'count': responders,
        'max_manufacturer_pids': (max_manufacturer_responder,
                                  max_manufacturer_pids),
        'max_pids': (max_pids_responder, max_pids),
        'pids': pids,
    }
    return json.dumps(output)
  def LoadCurrentIndex(self):
    """Load the current PID to responder map. Also populates the pid_cache.

    Returns:
      A dict in the form {
        (manufacturer_id, pid_id) : set(responder_keys),
      }
    """
    index = {}
    for pid in Pid.all():
      key = (pid.manufacturer.esta_id, pid.pid_id)
      responders = set()
      for responder in pid.responders:
        responders.add(responder)
      index[key] = responders
      self._pid_cache[key] = pid
    return index
Beispiel #10
0
    def LookupPid(self, pid_id, manufacturer_id):
        """
    Lookup a PID

    Returns:
      A tuple of (manufacturer, pid) data objects.
    """
        manufacturer = common.GetManufacturer(manufacturer_id)
        if manufacturer is None:
            raise UnknownManufacturerException(manufacturer_id)

        pid_query = Pid.all()
        pid_query.filter('pid_id = ', pid_id)
        pid_query.filter('manufacturer = ', manufacturer.key())

        result_set = pid_query.fetch(1)
        if result_set:
            return manufacturer, result_set[0]
        else:
            return manufacturer, None
  def LookupPid(self, pid_id, manufacturer_id):
    """
    Lookup a PID

    Returns:
      A tuple of (manufacturer, pid) data objects.
    """
    manufacturer = common.GetManufacturer(manufacturer_id)
    if manufacturer is None:
      raise UnknownManufacturerException(manufacturer_id)

    pid_query = Pid.all()
    pid_query.filter('pid_id = ', pid_id)
    pid_query.filter('manufacturer = ', manufacturer.key())

    result_set = pid_query.fetch(1)
    if result_set:
      return manufacturer, result_set[0]
    else:
      return manufacturer, None
Beispiel #12
0
    def LookupPIDFromRequest(self):
        pid_id = self.request.get('pid')
        try:
            pid_id = int(pid_id)
        except ValueError:
            return None

        manufacturer = common.GetManufacturer(self.request.get('manufacturer'))
        if manufacturer is None or pid_id is None:
            return None

        models = Pid.all()
        models.filter('pid_id = ', pid_id)
        models.filter('manufacturer = ', manufacturer.key())

        pid_data = models.fetch(1)
        if pid_data:
            return pid_data[0]
        else:
            return None
Beispiel #13
0
    def UpdateIfRequired(self, new_pid_data, manufacturer_id=0):
        """
    Check if we need to update the data for this PID.

    Args:
      pid: The PID data
      manufacturer_id: The manufacturer_id for the PID data.

    Returns:
      True if the PID was updated, false otherwise.
    """
        manufacturer, pid = self.LookupPid(new_pid_data['value'],
                                           manufacturer_id)
        save = False

        if not pid:
            pid = Pid(manufacturer=manufacturer,
                      pid_id=new_pid_data['value'],
                      name=new_pid_data['name'])

        if pid.link != new_pid_data.get('link'):
            pid.link = new_pid_data.get('link')
            save = True

        if pid.notes != new_pid_data.get('notes'):
            pid.notes = new_pid_data.get('notes')
            save = True

        if pid.draft != new_pid_data.get('draft', False):
            pid.draft = new_pid_data.get('draft', False)
            save = True

        save |= self.UpdateCommand(pid, new_pid_data, 'discovery')
        save |= self.UpdateCommand(pid, new_pid_data, 'get')
        save |= self.UpdateCommand(pid, new_pid_data, 'set')

        if save:
            logging.info('Updated %s' % new_pid_data['name'])
            pid.put()
        return save
  def UpdateIfRequired(self, new_pid_data, manufacturer_id=0):
    """
    Check if we need to update the data for this PID.

    Args:
      pid: The PID data
      manufacturer_id: The manufacturer_id for the PID data.

    Returns:
      True if the PID was updated, false otherwise.
    """
    manufacturer, pid = self.LookupPid(new_pid_data['value'], manufacturer_id)
    save = False

    if not pid:
      pid = Pid(manufacturer=manufacturer,
                pid_id=new_pid_data['value'],
                name=new_pid_data['name'])

    if pid.link != new_pid_data.get('link'):
      pid.link = new_pid_data.get('link')
      save = True

    if pid.notes != new_pid_data.get('notes'):
      pid.notes = new_pid_data.get('notes')
      save = True

    if pid.draft != new_pid_data.get('draft', False):
      pid.draft = new_pid_data.get('draft', False)
      save = True

    save |= self.UpdateCommand(pid, new_pid_data, 'discovery')
    save |= self.UpdateCommand(pid, new_pid_data, 'get')
    save |= self.UpdateCommand(pid, new_pid_data, 'set')

    if save:
      logging.info('Updated %s' % new_pid_data['name'])
      pid.put()
    return save
  def GetTemplateData(self):
    model = common.LookupModelFromRequest(self.request)
    if not model:
      self.error(404)
      return

    esta_manufacturer = common.GetManufacturer(0)
    if not esta_manufacturer:
      logging.error("Can't find ESTA manufacturer!")
      # 404 early here
      self.error(404)
      return

    self.response.headers['Content-Type'] = 'text/plain'

    # software version info
    software_versions = []
    for version_info in model.software_version_set:
      version_output = {
          'version_id': version_info.version_id,
          'label': common.MaybeEncode(version_info.label),
      }

      supported_parameters = version_info.supported_parameters
      if supported_parameters is not None:
        param_output = []
        for param in supported_parameters:
          param_dict = {'id': param}

          query = Pid.all()
          query.filter('pid_id =', param)
          if param >= 0x8000:
            query.filter('manufacturer = ', model.manufacturer)
            param_dict['manufacturer_id'] = model.manufacturer.esta_id
          else:
            query.filter('manufacturer = ', esta_manufacturer)
            param_dict['manufacturer_id'] = esta_manufacturer.esta_id

          results = query.fetch(1)
          if results:
            param_dict['name'] = results[0].name
          param_output.append(param_dict)

        version_output['supported_parameters'] = sorted(
            param_output,
            key=lambda x: x['id'])
      software_versions.append(version_output)

      personalities = []
      for personality in version_info.personality_set:
        personality_info = {
          'description': common.MaybeEncode(personality.description),
          'index': personality.index,
        }
        if personality.slot_count is not None:
          personality_info['slot_count'] = personality.slot_count

        personalities.append(personality_info)

      if personalities:
        personalities.sort(key=lambda x: x['index'])
        version_output['personalities'] = personalities

      sensors = []
      for sensor in version_info.sensor_set:
        sensor_info = {
            'description': common.MaybeEncode(sensor.description),
            'index': sensor.index,
            'type': sensor.type,
            'supports_recording': sensor.supports_recording,
            'supports_min_max': sensor.supports_min_max_recording,
        }
        type_str = SENSOR_TYPES.get(sensor.type)
        if type_str is not None:
          sensor_info['type_str'] = type_str
        sensors.append(sensor_info)

      if sensors:
        sensors.sort(key=lambda x: x['index'])
        version_output['sensors'] = sensors

    # construct link to Open Fixture Library's RDM lookup page
    ofl_model_url = 'https://open-fixture-library.org/rdm?source=olp'
    ofl_model_url += '&manufacturerId=' + str(model.manufacturer.esta_id)
    ofl_model_url += '&modelId=' + str(model.device_model_id)

    output = {
      'description': common.MaybeEncode(model.model_description),
      'manufacturer': model.manufacturer.name,
      'manufacturer_id': model.manufacturer.esta_id,
      'model_id': model.device_model_id,
      'software_versions': software_versions,
      'software_versions_json': json.dumps(software_versions),
      'open_fixture_library_model_url': ofl_model_url
    }
    # link and product_category are optional
    if model.link:
      output['link'] = model.link
    category = model.product_category
    if category:
      output['product_category'] = category.name
      output['product_category_id'] = category.id

    # tags
    for tag in model.tag_set:
      tags = output.setdefault('tags', [])
      tags.append(tag.tag.label)

    if model.image_data:
      serving_url = model.image_serving_url
      if not serving_url:
        serving_url = images.get_serving_url(model.image_data.key())
        model.image_serving_url = serving_url
        model.put()
      output['image_key'] = serving_url
    return output
Beispiel #16
0
    def GetTemplateData(self):
        model = common.LookupModelFromRequest(self.request)
        if not model:
            self.error(404)
            return

        esta_manufacturer = common.GetManufacturer(0)
        if not esta_manufacturer:
            logging.error("Can't find ESTA manufacturer!")
            # 404 early here
            self.error(404)
            return

        self.response.headers['Content-Type'] = 'text/plain'

        # software version info
        software_versions = []
        for version_info in model.software_version_set:
            version_output = {
                'version_id': version_info.version_id,
                'label': common.MaybeEncode(version_info.label),
            }

            supported_parameters = version_info.supported_parameters
            if supported_parameters is not None:
                param_output = []
                for param in supported_parameters:
                    param_dict = {'id': param}

                    query = Pid.all()
                    query.filter('pid_id =', param)
                    if param >= 0x8000:
                        query.filter('manufacturer = ', model.manufacturer)
                        param_dict[
                            'manufacturer_id'] = model.manufacturer.esta_id
                    else:
                        query.filter('manufacturer = ', esta_manufacturer)
                        param_dict[
                            'manufacturer_id'] = esta_manufacturer.esta_id

                    results = query.fetch(1)
                    if results:
                        param_dict['name'] = results[0].name
                    param_output.append(param_dict)

                version_output['supported_parameters'] = sorted(
                    param_output, key=lambda x: x['id'])
            software_versions.append(version_output)

            personalities = []
            for personality in version_info.personality_set:
                personality_info = {
                    'description': common.MaybeEncode(personality.description),
                    'index': personality.index,
                }
                if personality.slot_count is not None:
                    personality_info['slot_count'] = personality.slot_count

                personalities.append(personality_info)

            if personalities:
                personalities.sort(key=lambda x: x['index'])
                version_output['personalities'] = personalities

            sensors = []
            for sensor in version_info.sensor_set:
                sensor_info = {
                    'description': common.MaybeEncode(sensor.description),
                    'index': sensor.index,
                    'type': sensor.type,
                    'supports_recording': sensor.supports_recording,
                    'supports_min_max': sensor.supports_min_max_recording,
                }
                type_str = SENSOR_TYPES.get(sensor.type)
                if type_str is not None:
                    sensor_info['type_str'] = type_str
                sensors.append(sensor_info)

            if sensors:
                sensors.sort(key=lambda x: x['index'])
                version_output['sensors'] = sensors

        # construct link to Open Fixture Library's RDM lookup page
        ofl_model_url = 'https://open-fixture-library.org/rdm?source=olp'
        ofl_model_url += '&manufacturerId=' + str(model.manufacturer.esta_id)
        ofl_model_url += '&modelId=' + str(model.device_model_id)

        output = {
            'description': common.MaybeEncode(model.model_description),
            'manufacturer': model.manufacturer.name,
            'manufacturer_id': model.manufacturer.esta_id,
            'model_id': model.device_model_id,
            'software_versions': software_versions,
            'software_versions_json': json.dumps(software_versions),
            'open_fixture_library_model_url': ofl_model_url
        }
        # link and product_category are optional
        if model.link:
            output['link'] = model.link
        category = model.product_category
        if category:
            output['product_category'] = category.name
            output['product_category_id'] = category.id

        # tags
        for tag in model.tag_set:
            tags = output.setdefault('tags', [])
            tags.append(tag.tag.label)

        if model.image_data:
            serving_url = model.image_serving_url
            if not serving_url:
                serving_url = images.get_serving_url(model.image_data.key())
                model.image_serving_url = serving_url
                model.put()
            output['image_key'] = serving_url
        return output