Skip to content

Commit

Permalink
Merge pull request #252 from xen0n/telemetry-verbose-status
Browse files Browse the repository at this point in the history
Implement verbose output of telemetry status
  • Loading branch information
xen0n authored Dec 28, 2024
2 parents 3b0789c + 819a01f commit 7a80a86
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
30 changes: 22 additions & 8 deletions ruyi/telemetry/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,16 @@ def has_upload_consent(self, time_now: float | None = None) -> bool:
time_now = time.time()
return self.upload_consent_time.timestamp() <= time_now

def print_telemetry_notice(self) -> None:
def print_telemetry_notice(self, for_cli_verbose_output: bool = False) -> None:
if self.local_mode:
if for_cli_verbose_output:
log.I(
"telemetry mode is [green]local[/]: local data collection only, no uploads"
)
return

now = time.time()
if self.has_upload_consent(now):
if self.has_upload_consent(now) and not for_cli_verbose_output:
log.D("user has consented to telemetry upload")
return

Expand All @@ -190,9 +194,17 @@ def print_telemetry_notice(self) -> None:

today_is_upload_day = self.is_upload_day(now)
has_uploaded_today = self.has_uploaded_today(now)
log.W(
f"this [yellow]ruyi[/] installation has telemetry mode set to [yellow]on[/], and [bold]will upload non-tracking usage information to RuyiSDK-managed servers[/] [bold green]every {upload_wday_name}[/]"
)
if for_cli_verbose_output:
log.I(
"telemetry mode is [green]on[/]: data is collected and periodically uploaded"
)
log.I(
f"non-tracking usage information will be uploaded to RuyiSDK-managed servers [bold green]every {upload_wday_name}[/]"
)
else:
log.W(
f"this [yellow]ruyi[/] installation has telemetry mode set to [yellow]on[/], and [bold]will upload non-tracking usage information to RuyiSDK-managed servers[/] [bold green]every {upload_wday_name}[/]"
)
if today_is_upload_day:
if has_uploaded_today:
if last_upload_time := self.last_upload_timestamp:
Expand All @@ -210,9 +222,11 @@ def print_telemetry_notice(self) -> None:
log.I(
f"the next upload will happen anytime [yellow]ruyi[/] is executed between [bold green]{next_upload_day_str}[/] and [bold green]{next_upload_day_end_str}[/]"
)
log.I("in order to hide this banner:")
log.I("- opt out with [yellow]ruyi telemetry optout[/]")
log.I("- or give consent with [yellow]ruyi telemetry consent[/]")

if not for_cli_verbose_output:
log.I("in order to hide this banner:")
log.I("- opt out with [yellow]ruyi telemetry optout[/]")
log.I("- or give consent with [yellow]ruyi telemetry consent[/]")

def next_upload_day(self, time_now: float | None = None) -> int | None:
upload_wday = self.upload_weekday()
Expand Down
18 changes: 16 additions & 2 deletions ruyi/telemetry/telemetry_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,23 @@ class TelemetryStatusCommand(
):
@classmethod
def configure_args(cls, p: argparse.ArgumentParser) -> None:
pass
p.add_argument(
"--verbose",
"-v",
action="store_true",
help="Enable verbose output",
)

@classmethod
def main(cls, cfg: config.GlobalConfig, args: argparse.Namespace) -> int:
log.stdout(cfg.telemetry_mode)
verbose: bool = args.verbose
if not verbose:
log.stdout(cfg.telemetry_mode)
return 0

if cfg.telemetry is None:
log.I("telemetry mode is [green]off[/]: no further data will be collected")
return 0

cfg.telemetry.print_telemetry_notice(for_cli_verbose_output=True)
return 0

0 comments on commit 7a80a86

Please sign in to comment.