Ejemplo n.º 1
0
    def _split(self) -> List[Rsi]:
        result = []

        for name, state in self.rsi.states.items():
            state_rsi = Rsi(self.rsi.size)
            state_rsi.set_state(state, name)
            result.append(state_rsi)
            self.names[state_rsi] = state.name

        return result
Ejemplo n.º 2
0
def from_dmi(
    inputf: Union[BytesIO, Path, str],
    output: Path,
    new_license: Optional[str],
    new_copyright: Optional[str],
    indents: Optional[int] = None,
    splitter: Optional[str] = "",
) -> None:
    rsi = Rsi.from_dmi(inputf)
    if new_license:
        rsi.license = new_license
    if new_copyright:
        rsi.copyright = new_copyright

    splitter_class = {
        "hyphen": HyphenSplitter,
        "number": NumberSplitter,
        "simple": SimpleSplitter,
        "underscore": UnderscoreSplitter,
    }.get(splitter, None)  # type: ignore

    if splitter_class is None:
        rsi.write(output)
    else:
        splitter_class(rsi).split_to(output, indents)
Ejemplo n.º 3
0
def from_dmi(inputf: Path, output: Path, new_license: Optional[str],
             new_copyright: Optional[str]) -> None:
    rsi = Rsi.from_dmi(inputf)
    if new_license:
        rsi.license = new_license
    if new_copyright:
        rsi.copyright = new_copyright
    rsi.write(output)
Ejemplo n.º 4
0
    def _split(self) -> List[Rsi]:
        groups: Dict[str, Rsi] = {}

        for name, state in self.rsi.states.items():
            prefix = name.split("_")[0]
            suffix = name.split("_")[-1]
            state_rsi = groups.setdefault(prefix, Rsi(self.rsi.size))

            if prefix != suffix:
                state.name = suffix
                state_rsi.set_state(state, suffix)
                self.names[state_rsi] = prefix
            else:
                state_rsi.set_state(state, name)
                self.names[state_rsi] = name

        return list(groups.values())
Ejemplo n.º 5
0
    def _split(self) -> List[Rsi]:
        groups: Dict[str, Rsi] = {}
        pattern = re.compile("([^0-9]*)([0-9]*)")

        for name, state in self.rsi.states.items():
            match = pattern.match(name)
            prefix = match.group(1)  # type: ignore
            suffix = match.group(2) if len(
                match.groups()) > 1 else ""  # type: ignore
            state_rsi = groups.setdefault(prefix, Rsi(self.rsi.size))

            if prefix != suffix:
                state.name = suffix
                state_rsi.set_state(state, suffix)
                self.names[state_rsi] = prefix
            else:
                state_rsi.set_state(state, name)
                self.names[state_rsi] = name

        return list(groups.values())
Ejemplo n.º 6
0
def new_rsi(loc: Path, dimensions: str, rsi_copyright: Optional[str],
            rsi_license: Optional[str], make_parents: bool) -> int:
    try:
        dimsplit = dimensions.split("x")
        if len(dimsplit) != 2:
            print("Incorrect amount of dimensions passed, expected exactly 2.")
            return 1
        x = int(dimsplit[0])
        y = int(dimsplit[1])

    except ValueError:
        print("Invalid dimensions passed.")
        return 1

    if not loc.parent.exists() and not make_parents:
        print("Parent directories do not exist. Aborting.")
        return 1

    rsi = Rsi((x, y))
    rsi.license = rsi_license
    rsi.copyright = rsi_copyright
    rsi.write(loc, make_parents)

    return 0
Ejemplo n.º 7
0
def from_dmi(input: Path, output: Path) -> None:
    rsi = Rsi.from_dmi(input)
    rsi.write(output)