Ejemplo n.º 1
0
def generate(
    fw_version: str,
    hub_type: str,
    mpy_options: typing.List[str],
    map_file: io.FileIO,
    out_file: io.FileIO,
):
    metadata = {
        "metadata-version": VERSION,
        "firmware-version": fw_version,
        "mpy-abi-version": mpy_tool.config.MPY_VERSION,
        "mpy-cross-options": mpy_options,
    }

    if hub_type not in HUB_INFO:
        print("Unknown hub type", file=sys.stderr)
        exit(1)

    metadata.update(HUB_INFO[hub_type])

    flash_origin = None  # Starting address of firmware area in flash memory
    flash_length = None  # Size of firmware area of flash memory
    user_start = None  # Starting address of user .mpy file

    for line in map_file.readlines():
        match = re.match(
            r"^FLASH\s+(0x[0-9A-Fa-f]{8,16})\s+(0x[0-9A-Fa-f]{8,16})", line)
        if match:
            flash_origin = int(match[1], base=0)
            flash_length = int(match[2], base=0)
            continue

        match = re.match(r"^\.user\s+(0x[0-9A-Fa-f]{8,16})", line)
        if match:
            user_start = int(match[1], base=0)
            continue

    if flash_origin is None:
        print("Failed to find 'FLASH' start address", file=sys.stderr)
        exit(1)

    if flash_length is None:
        print("Failed to find 'FLASH' length", file=sys.stderr)
        exit(1)

    if user_start is None:
        print("Failed to find '.user' start address", file=sys.stderr)
        exit(1)

    metadata["user-mpy-offset"] = user_start - flash_origin
    metadata["max-firmware-size"] = flash_length

    json.dump(metadata, out_file, indent=4, sort_keys=True)
Ejemplo n.º 2
0
    def _parse_file(self, file: FileIO) -> Tuple[List[Requirement], List[str]]:
        requirements: List[Requirement] = []
        to_recurse: List[str] = []

        for line in file.readlines():
            try:
                requirements.append(Requirement.from_line(line))
            except NotFrozenRequirement:
                if line.startswith("-r "):
                    to_recurse.append(remove_comments(line))
                else:
                    continue
        return requirements, to_recurse
Ejemplo n.º 3
0
def load(text_path: str, entities_list: io.FileIO, sample: Optional[int]=None):
    """

    :param text_path:
    :param entities_list:
    :return:
    """
    reader = LemmatizedCsvReader(text_path)
    for entity_id, entities in enumerate(entities_list.readlines()):
        word_text = entities.strip()
        word = Word(word_text=word_text)
        db.session.add(word)
        db.session.flush()
        for match in reader.get_kwic(word_text):
            db.session.add(Mention(mention_word=word.word_id, mention_text=repr(match)))
            print(repr(match))
        if sample and entity_id == sample:
            print("Stopping on sample")
            break
    db.session.commit()
Ejemplo n.º 4
0
def generate_noun_query():
    with open(PATH_TO_NOUN_LIST, 'r') as noun_file:
        noun_list = file.readlines(noun_file)
    noun = noun_list[randint(0, len(noun_list))]
    print('Querying for: {0}'.format(noun))
    return noun