<commit_before>#  Copyright (c) 2022, <NAME>
#  License: MIT License
from typing import cast
import sys
from pathlib import Path
from argparse import ArgumentParser
import ezdxf
from ezdxf.entities import Body

DIR = Path("~/Desktop/Outbox").expanduser()
if not DIR.exists():
    DIR = Path(".")

SEARCH_TYPES = {"3DSOLID", "REGION"}
DEFAULT_FILE = DIR / "acis.dxf"


def export_acis(entity: Body, folder: Path):
    version = entity.doc.dxfversion
    fname = f"{version}-{entity.dxftype()}-{entity.dxf.handle}"
    data = entity.acis_data
    if isinstance(data[0], bytes):
        with open(folder / (fname + ".sab"), "wb") as fp:
            print(f"Exporting: {fp.name}")
            fp.write(b"".join(data))
    else:
        with open(folder / (fname + ".sat"), "wt") as fp:
            print(f"Exporting: {fp.name}")
            fp.write("\n".join(data))


def extract_acis(filepath: Path):
    print(f"processing file: {filepath}")
    try:
        doc = ezdxf.readfile(filepath)
    except IOError as e:
        print(str(e))
        sys.exit(1)
    msp = doc.modelspace()
    for e in msp:
        if e.dxftype() in SEARCH_TYPES:
            export_acis(cast("Body", e), folder=filepath.parent)


def main():
    parser = ArgumentParser()
    parser.add_argument("files", nargs="*")
    args = parser.parse_args()
    if len(args.files):
        for filename in args.files:
            extract_acis(Path(filename))
    else:
        extract_acis(DEFAULT_FILE)


if __name__ == "__main__":
    main()<commit_msg>improve acis-extractor<commit_after>#  Copyright (c) 2022, <NAME>
#  License: MIT License
import sys
from pathlib import Path
from argparse import ArgumentParser
import ezdxf
from ezdxf.entities import Body

DIR = Path("~/Desktop/Outbox").expanduser()
if not DIR.exists():
    DIR = Path(".")

DEFAULT_FILE = DIR / "acis.dxf"


def export_acis(entity: Body, folder: Path):
    version = entity.doc.dxfversion
    fname = f"{version}-{entity.dxftype()}-{entity.dxf.handle}"
    data = entity.acis_data
    if isinstance(data[0], bytes):
        with open(folder / (fname + ".sab"), "wb") as fp:
            print(f"Exporting: {fp.name}")
            fp.write(b"".join(data))
    else:
        with open(folder / (fname + ".sat"), "wt") as fp:
            print(f"Exporting: {fp.name}")
            fp.write("\n".join(data))


def extract_acis(filepath: Path):
    print(f"processing file: {filepath}")
    try:
        doc = ezdxf.readfile(filepath)
    except IOError as e:
        print(str(e))
        sys.exit(1)
    msp = doc.modelspace()
    for e in msp:
        if isinstance(e, Body):
            export_acis(e, folder=filepath.parent)


def main():
    parser = ArgumentParser()
    parser.add_argument("files", nargs="*")
    args = parser.parse_args()
    if len(args.files):
        for filename in args.files:
            extract_acis(Path(filename))
    else:
        extract_acis(DEFAULT_FILE)


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.14545454545454545, 'fraction_numerical': 0.004377104377104377, 'mean_word_length': 2.8089743589743588, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4803992', 'n_tokens_mistral': 1024, 'n_tokens_neox': 1020, 'n_words': 241}