示例#1
0
def delete_recursive(path: Path) -> None:
    for inner in path.iterdir():
        if inner.is_dir():
            delete_recursive(inner)
        else:
            inner.unlink()
    path.rmdir()
示例#2
0
    def find_path(self, before: PathLike, after: PathLike) -> Path:
        path: Path = Path(before)
        parts: List[str] = Path(str(after)).parts

        for part in parts:
            if part == CURRENT:
                continue
            elif part == PARENT:
                path = path.parent
            else:
                path /= part

        self.check_env(path)

        return path
示例#3
0
    def __init__(
        self,
        io_in: IO = stdin,
        io_err: IO = stderr,
        io_out: IO = stdout,
        ps_format: str = '{name}@{terminal}:{path}{ps}{end}',
        name: str = 'root',
        term_name: str = 'term',
        end: str = ' ',
        ps: str = '$',
    ) -> None:
        # those are useless for now
        self._in = io_in
        self._err = io_err
        self._out = io_out

        # TODO: add config loading
        self._fs = FS()

        self._format = ps_format
        self._name = name
        self._term_name = term_name
        self._ps = ps
        self._end = end

        self._path: Path = Path(FILE_SYSTEM)

        self._parser = Parser()
        self._load_commands()
示例#4
0
    def format_ps(self, end: Optional[str] = None) -> str:
        if end is None:
            end = self.end

        try:
            path = Path('~') / self.path.relative_to(FILE_SYSTEM)
        except ValueError:
            path = self.path

        return self.format.format(path=path,
                                  name=self.name,
                                  terminal=self.term,
                                  ps=self.ps,
                                  end=end)
示例#5
0
 def is_file(self, path: PathLike) -> bool:
     return Path(path).is_file()
示例#6
0
from kivy.app import App
from kivy.event import EventDispatcher
from kivy.properties import (ObjectProperty, ListProperty, StringProperty,
                             NumericProperty, Clock, partial)
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput

from project.core.path import Path
from project.core.terminal import Terminal

root = Path(__file__).parent.resolve()
font = str(root / 'font.ttf')


class Shell(EventDispatcher):
    __events__ = ('on_output', 'on_complete')
    term = ObjectProperty(None)

    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
        self.term = Terminal()

    def run_command(self, command, show_output=True, *args):
        try:
            result = self.term.run_cmd(command)
        except Exception as exc:
            result = str(exc)

        if result is None:
            result = str()
示例#7
0
from project.core.path import Path

CANNOT_EXIT_ENV = True

ROOT = Path(__file__).parent.parent

FILE_SYSTEM = ROOT / 'file_system'
BIN_DIR = FILE_SYSTEM / 'bin'
示例#8
0
from typing import IO, Optional, NoReturn

from project.core.constants import FILE_SYSTEM
from project.core.path import Path
from project.core.utils import FS
from project.core.parser import Parser

env = dict(
    name='name',
    term_name='term',
    ps='$',
    end=' ',
    format='{name}@{terminal}:{path}{ps}{end}',
)

rc = (Path(__file__).parent.parent / 'file_system' / '.termrc').resolve()

if rc.exists():
    exec(rc.read_text('utf-8'), env)


class Terminal:
    def __init__(
        self,
        io_in: IO = stdin,
        io_err: IO = stderr,
        io_out: IO = stdout,
        ps_format: str = '{name}@{terminal}:{path}{ps}{end}',
        name: str = 'root',
        term_name: str = 'term',
        end: str = ' ',