Esempio n. 1
0
def point_of_interest():
    """Leave a pseudo-breakpoint somewhere to ask the user if
       they could pls submit their stacktrace to cmyui <3."""

    # TODO: fix this, circular import thing
    #ver_str = f'Running gulag v{glob.version!r} | cmyui_pkg v{cmyui.__version__}'
    #printc(ver_str, Ansi.LBLUE)

    for fi in inspect.stack()[1:]:
        if fi.function == '_run':
            # go all the way up to server start func
            break

        file = Path(fi.filename)

        # print line num, index, func name & locals for each frame.
        log('[{function}() @ {fname} L{lineno}:{index}] {frame.f_locals}'.
            format(**fi._asdict(), fname=file.name))

    msg_str = '\n'.join((
        "Hey! If you're seeing this, osu! just did something pretty strange,",
        "and the gulag devs have left a breakpoint here. We'd really appreciate ",
        "if you could screenshot the data above, and send it to cmyui, either via ",
        "Discord (cmyui#0425), or by email ([email protected]). Thanks! 😳😳😳"
    ))

    printc(msg_str, Ansi.LRED)
    input('To close this menu & unfreeze, simply hit the enter key.')
Esempio n. 2
0
    async def dispatch(
        self,
        request: Request,
        call_next: RequestResponseEndpoint,
    ) -> Response:
        start_time = time.perf_counter_ns()
        response = await call_next(request)
        end_time = time.perf_counter_ns()

        time_elapsed = end_time - start_time

        # TODO: add metric to datadog

        col = (
            Ansi.LGREEN
            if 200 <= response.status_code < 300
            else Ansi.LYELLOW
            if 300 <= response.status_code < 400
            else Ansi.LRED
        )

        url = f"{request.headers['host']}{request['path']}"

        log(f"[{request.method}] {response.status_code} {url}", col, end=" | ")
        printc(f"Request took: {magnitude_fmt_time(time_elapsed)}", Ansi.LBLUE)

        response.headers["process-time"] = str(round(time_elapsed) / 1e6)
        return response
Esempio n. 3
0
    def _excepthook(
        type_: Type[BaseException],
        value: BaseException,
        traceback: types.TracebackType,
    ):
        if type_ is KeyboardInterrupt:
            print("\33[2K\r", end="Aborted startup.")
            return
        elif type_ is AttributeError and value.args[0].startswith(
                "module 'config' has no attribute", ):
            attr_name = value.args[0][34:-1]
            log(
                "gulag's config has been updated, and has "
                f"added a new `{attr_name}` attribute.",
                Ansi.LMAGENTA,
            )
            log(
                "Please refer to it's value & example in "
                "ext/config.sample.py for additional info.",
                Ansi.LCYAN,
            )
            return

        printc(
            f"gulag v{settings.VERSION} ran into an issue before starting up :(",
            Ansi.RED,
        )
        real_excepthook(type_, value, traceback)  # type: ignore
Esempio n. 4
0
    async def run(self) -> None:
        """Prepare, and run the updater."""
        prev_ver = await self.get_prev_version()

        if not prev_ver:
            # first time running the server.
            prev_ver = self.version

            printc(
                '\n'.join([
                    'Welcome to gulag!',
                    'If you have any issues with the server,',
                    'feel free to join our public Discord :)', '',
                    'https://discord.gg/ShEQgUx', 'Enjoy the server!'
                ]), Ansi.LCYAN)
            input('> Press enter to continue')

        if glob.has_internet:
            await self._update_cmyui()  # pip install -U cmyui
        await self._update_sql(prev_ver)  # run updates.sql
Esempio n. 5
0
async def log_strange_occurrence(obj: object) -> None:
    pickled_obj: bytes = pickle.dumps(obj)
    uploaded = False

    if settings.AUTOMATICALLY_REPORT_PROBLEMS:
        # automatically reporting problems to cmyui's server
        async with http.post(
                url="https://log.cmyui.xyz/",
                headers={
                    "Gulag-Version": settings.VERSION,
                    "Gulag-Domain": settings.DOMAIN,
                },
                data=pickled_obj,
        ) as resp:
            if resp.status == 200 and (await resp.read()) == b"ok":
                uploaded = True
                log("Logged strange occurrence to cmyui's server.", Ansi.LBLUE)
                log("Thank you for your participation! <3", Rainbow)
            else:
                log(
                    f"Autoupload to cmyui's server failed (HTTP {resp.status})",
                    Ansi.LRED,
                )

    if not uploaded:
        # log to a file locally, and prompt the user
        while True:
            log_file = STRANGE_LOG_DIR / f"strange_{secrets.token_hex(4)}.db"
            if not log_file.exists():
                break

        log_file.touch(exist_ok=False)
        log_file.write_bytes(pickled_obj)

        log("Logged strange occurrence to", Ansi.LYELLOW, end=" ")
        printc("/".join(log_file.parts[-4:]), Ansi.LBLUE)

        log(
            "Greatly appreciated if you could forward this to cmyui#0425 :)",
            Ansi.LYELLOW,
        )
Esempio n. 6
0
File: misc.py Progetto: cmyui/gulag
async def log_strange_occurrence(obj: object) -> None:
    if not glob.has_internet:  # requires internet connection
        return

    pickled_obj = pickle.dumps(obj)
    uploaded = False

    if glob.config.automatically_report_problems:
        # automatically reporting problems to cmyui's server
        async with glob.http.post(
                url='https://log.cmyui.xyz/',
                headers={
                    'Gulag-Version': repr(glob.version),
                    'Gulag-Domain': glob.config.domain
                },
                data=pickled_obj,
        ) as resp:
            if (resp.status == 200 and (await resp.read()) == b'ok'):
                uploaded = True
                log("Logged strange occurrence to cmyui's server.", Ansi.LBLUE)
                log("Thank you for your participation! <3", Ansi.LBLUE)
            else:
                log(
                    f"Autoupload to cmyui's server failed (HTTP {resp.status})",
                    Ansi.LRED)

    if not uploaded:
        # log to a file locally, and prompt the user
        while True:
            log_file = STRANGE_LOG_DIR / f'strange_{secrets.token_hex(4)}.db'
            if not log_file.exists():
                break

        log_file.touch(exist_ok=False)
        log_file.write_bytes(pickled_obj)

        log('Logged strange occurrence to', Ansi.LYELLOW, end=' ')
        printc('/'.join(log_file.parts[-4:]), Ansi.LBLUE)

        log("Greatly appreciated if you could forward this to cmyui#0425 :)",
            Ansi.LYELLOW)
Esempio n. 7
0
def point_of_interest():
    """Leave a pseudo-breakpoint somewhere to ask the user if
       they could pls submit their stacktrace to cmyui <3."""
    for fi in inspect.stack()[1:]:
        if fi.function == '_run':
            # go all the way up to server start func
            break

        file = Path(fi.filename)

        # print line num, index, func name & locals for each frame.
        log(
            f'[{fi.function}() @ {file.name} L{fi.lineno}:{fi.index}] {fi.frame.f_locals}',
            Ansi.LBLUE)

    msg = '\n'.join((
        "Hey! If you're seeing this, osu! just did something pretty strange,",
        "and the gulag devs have left a breakpoint here. We'd really appreciate ",
        "if you could screenshot the data above, and send it to cmyui, either via ",
        "Discord (cmyui#0425), or by email ([email protected]). Thanks! 😳😳😳"
    ))

    printc(msg, Ansi.LRED)
    input('To close this menu & unfreeze, simply hit the enter key.')