Example #1
0
    def token(self):
        prev_pos = self.lexer_object.lexpos

        token = self.lexer_object.token()
        if token is not None:
            token.location = self.current_location.clone()
            self.log.debug('Got next token; value=%r, type=%s, location=%s' % (token.value, token.type, token.location))

        else:
            self.log.debug('End of file reached; location=%s' % self.current_location)

        data = self.lexer_object.lexdata[prev_pos:self.lexer_object.lexpos]
        self.current_location.update(data)

        if token is not None:
            if token.type in self.error_tokens:
                error = replace(self.error_tokens[token.type], type=token.type, value=token.value, location=token.location)
                self.error_context.error(error, token.location)
                self.log.error(error)
                return None

            if token.type in self.warning_tokens:
                warning = replace(self.warning_tokens[token.type], type=token.type, value=token.value, location=token.location)
                self.error_context.warning(warning, token.location)
                self.log.warning(warning)

        return token
Example #2
0
    def calculate_slots(self):
        self.slots = 0
        self.slot_number = 0
        if self.local_name.find("RSP") > -1:
            self.type = "RSP"
            self.slots = 0
            self.slot_number = int(replace(self.local_name, ["0/", "RSP"],
                                           "")) + 8
        if self.local_name.find("chassis") > -1:
            self.type = "CHASSIS"
            self.slots = int(
                replace(self.pid, {",", "ASR", "99", "DC", "V2", "-", "90"},
                        ""))
            self.slot_number = 0

        if (self.pid.find("SFP") > -1 or self.pid.find("XFP") > -1):
            self.slots = 0
            self.type = "SFP"
            self.slot_number = int(self.local_name[-1])

        if (self.pid.find("MOD") > -1):
            self.slots = 2
            self.type = "MOD"
            self.slot_number = int(self.local_name[-1])
        if (self.pid.find("MPA") > -1):
            self.type = "MPA"
            self.slots = int(self.pid.split("X")[0].split("-")[-1])
            self.slot_number = int(self.local_name[-1])
def matlab_run(script: str, replacement_dict: dict = {}):
    timestamp = datetime.now()
    f_out = f"temp_matlab_{datetime.now().strftime('%Y%m%d_%H%M%S')}.m"
    replace(script, f_out, replacement_dict)
    proc = subprocess.run([
        matlab_path, '-nodisplay', '-nosplash', '-nodesktop',
        f'-r "run(\'{f_out}\');exit;"'
    ])
    if proc.returncode != 0:
        raise RuntimeError(f'Subprocess {f_out} exited with non-zero return '
                           'status.')
    # cleanup
    os.remove(f_out)
    return
Example #4
0
    def p_error(self, token):
        if token is not None:
            self.lexer_object.error_context.error(replace(self.error_message, token=token.value, type=token.type), token.location)
            self.log.error('Invalid token; value=%s, type=%s, location=%s' % (token.value, token.type, token.location))

        else:
            self.lexer_object.error_context.error("Unexpected end of file", self.lexer_object.current_location)
            self.log.error('Unexpected end of file')
Example #5
0
    def __report(self, func, msg, rule, prod, location=None):
        args = dict(('prod%d' % (i + 1), repr(entry)) for i, entry in enumerate(prod[1:]))
        args['rule'] = repr(rule)
        args['start'] = location.start
        args['end'] = location.end
        args['location'] = location

        exp = replace(msg, **args)
        func(exp, location)
Example #6
0
    def __init__(self, parent_device, name, serial_number, vid, pid,
                 local_name):
        self.parent_device = parent_device
        self.name = name
        self.serial_number = serial_number
        self.vid = vid
        self.pid = replace(pid, [","], "")
        self.local_name = local_name.strip()
        self.part_level = local_name.count("/")
        self.type = "OTHER"
        self.side = 0
        if self.local_name.find("fan") > -1:
            self.part_level = 1
            self.side = 1
            self.type = "FAN"
        if self.local_name.find("power") > -1:
            self.part_level = 1
            self.side = 1
            self.type = "POWER"

        self.children = {}
        self.calculate_slots()
        self.uid = 0
Example #7
0
    def t_error(self, t):
        token = t.value[0]
        self.error_context.error(replace(self.error_message, token=token), self.current_location.clone())

        self.lexer_object.skip(len(token))
        self.log.error('Error parsing character %r' % token)