示例#1
0
    def isidentifier(self):
        """Override to provide an actual implementation.

        This can be removed if the base ever includes the implementation.

        """
        return utils.isidentifier(self)
示例#2
0
    def isidentifier(self):
        """Override to provide an actual implementation.

        This can be removed if the base ever includes the implementation.

        """
        return utils.isidentifier(self)
示例#3
0
def main():
    dest = 'upper'
    try:
        rmtree(dest)
    except OSError:
        pass
    makedirs(dest, exist_ok=True)
    for pdb in sys.argv[1:]:
        names = get_output(pdb, 'list')
        names = sorted(set(names.splitlines()))
        structs = [i.split()[1] for i in names if i.startswith('STRUCT')]
        enums = [i.split()[1] for i in names if i.startswith('ENUM')]
        unions = [i.split()[1] for i in names if i.startswith('UNION')]
        for i in itertools.chain(structs, enums, unions):
            if not i.isupper():
                continue
            if not isidentifier(i):
                continue
            defs = get_output(pdb, 'def', i)
            if not defs:
                continue
            print('writting {}...'.format(i))
            with open(os.path.join(dest, i) + '.h', 'w') as header:
                print(defs, file=header)
示例#4
0
文件: split.py 项目: LibreCrops/cdef
def main():
    dest = "upper"
    try:
        rmtree(dest)
    except OSError:
        pass
    makedirs(dest, exist_ok=True)
    for pdb in sys.argv[1:]:
        names = get_output(pdb, "list")
        names = sorted(set(names.splitlines()))
        structs = [i.split()[1] for i in names if i.startswith("STRUCT")]
        enums = [i.split()[1] for i in names if i.startswith("ENUM")]
        unions = [i.split()[1] for i in names if i.startswith("UNION")]
        for i in itertools.chain(structs, enums, unions):
            if not i.isupper():
                continue
            if not isidentifier(i):
                continue
            defs = get_output(pdb, "def", i)
            if not defs:
                continue
            print("writting {}...".format(i))
            with open(os.path.join(dest, i) + ".h", "w") as header:
                print(defs, file=header)
示例#5
0
 def validate_arguments(self):
     for name in self.arguments_names:
         if not isidentifier(name) or keyword.iskeyword(name):
             raise ValueError('{} is not valid argument name!'.format(name))
示例#6
0
def create_signal(db, signal):  # type: (canmatrix.CanMatrix, canmatrix.Signal) -> str
    output = ""
    if sys.version_info > (3, 0):
        quote_name = not signal.name.isidentifier()
    else:
        from future.utils import isidentifier
        quote_name = not isidentifier(signal.name)
    if quote_name:
        output += 'Var="%s" ' % signal.name
    else:
        output += "Var=%s " % signal.name
    if signal.type_label:
        output += signal.type_label + " "
    else:
        if signal.is_signed:
            output += "signed "
        elif signal.is_float:
            output += "float "
        else:
            output += "unsigned "

    start_bit = signal.get_startbit()
    if not signal.is_little_endian:
        # Motorola
        output += "%d,%d -m " % (start_bit, signal.size)
    else:
        output += "%d,%d " % (start_bit, signal.size)
    if signal.attributes.get('HexadecimalOutput', False):
        output += "-h "
    if len(signal.unit) > 0:
        t = signal.unit[0:16]
        if " " in t:
            format_string = '/u:"%s" '
        else:
            format_string = '/u:%s '
        output += format_string % t
    if float(signal.factor) != 1:
        output += "/f:%s " % (format_float(signal.factor))
    if float(signal.offset) != 0:
        output += "/o:%s " % (format_float(signal.offset))

    if signal.min is not None:
        output += "/min:{} ".format(format_float(signal.min))

    if signal.max is not None:
        output += "/max:{} ".format(format_float(signal.max))

    display_decimal_places = signal.attributes.get('DisplayDecimalPlaces')
    if display_decimal_places is not None:
        output += "/p:%d " % (int(display_decimal_places))

    if len(signal.values) > 0:
        val_tab_name = signal.enumeration
        if val_tab_name is None:
            val_tab_name = signal.name

        output += "/e:%s " % val_tab_name


    default = signal.initial_value  # type: ignore
    min_ok = signal.min is None or default >= signal.min
    max_ok = signal.max is None or default <= signal.max
    if min_ok and max_ok:
        output += "/d:{} ".format(default)

    long_name = signal.attributes.get('LongName')
    if long_name is not None:
        output += '/ln:"{}" '.format(long_name)

    output = output.rstrip()
    if signal.comment is not None and len(signal.comment) > 0:
        output += "\t// " + signal.comment.replace('\n', ' ').replace('\r', ' ')
    output += "\n"
    return output
示例#7
0
def get_sensor_from_katstore(store, name, start_time, end_time):
    """Get raw sensor data from katstore (CAM's central sensor database).

    Parameters
    ----------
    store : string
        Hostname / endpoint of katstore webserver speaking katstore64 API
    name : string
        Sensor name (the normalised / escaped version with underscores)
    start_time, end_time : float
        Time range for sensor records as UTC seconds since Unix epoch

    Returns
    -------
    data : :class:`RecordSensorGetter` object
        Retrieved sensor data with 'timestamp', 'value' and 'status' fields

    Raises
    ------
    ConnectionError
        If this cannot connect to the katstore server
    RuntimeError
        If connection succeeded but interaction with katstore64 API failed
    KeyError
        If the sensor was not found in the store or it has no data in time range
    """
    # The sensor name won't be in sensor store if it contains invalid characters
    if not isidentifier(name):
        raise KeyError("Sensor name '%s' is not valid Python identifier" %
                       (name, ))
    with requests.Session() as session:
        url = "http://%s/katstore/api/query" % (store, )
        params = {
            'sensor': name,
            'start_time': start_time,
            'end_time': end_time,
            'limit': 1000000,
            'include_value_time': 'True'
        }
        try:
            response = session.get(url, params=params)
        except requests.exceptions.ConnectionError as exc:
            err = ConnectionError("Could not connect to sensor store '%s'" %
                                  (store, ))
            raise_from(err, exc)
        with response:
            try:
                response.raise_for_status()
                sensor_data = response.json()['data']
                samples = [(rec['value_time'], rec['value'], rec['status'])
                           for rec in sensor_data if rec['sensor'] == name]
            except (ValueError, IndexError, TypeError, KeyError,
                    requests.exceptions.RequestException) as exc:
                err = RuntimeError(
                    "Could not retrieve samples from '%s' (%d: %s)" %
                    (url, response.status_code, response.reason))
                raise_from(err, exc)
        if not samples:
            raise KeyError("Sensor store has no data for sensor '%s'" %
                           (name, ))
        samples = np.rec.fromrecords(samples, names='timestamp,value,status')
        return RecordSensorGetter(samples, name)