Coverage for .tox/coverage/lib/python3.13/site-packages/wuttatell/cli/tell.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-21 19:19 -0500

1# -*- coding: utf-8; -*- 

2################################################################################ 

3# 

4# WuttaTell -- Telemetry submission for Wutta Framework 

5# Copyright © 2025-2026 Lance Edgar 

6# 

7# This file is part of Wutta Framework. 

8# 

9# Wutta Framework is free software: you can redistribute it and/or modify it 

10# under the terms of the GNU General Public License as published by the Free 

11# Software Foundation, either version 3 of the License, or (at your option) any 

12# later version. 

13# 

14# Wutta Framework is distributed in the hope that it will be useful, but 

15# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 

16# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 

17# more details. 

18# 

19# You should have received a copy of the GNU General Public License along with 

20# Wutta Framework. If not, see <http://www.gnu.org/licenses/>. 

21# 

22################################################################################ 

23""" 

24See also: :ref:`wutta-tell` 

25""" 

26 

27import logging 

28 

29try: 

30 from typing import Annotated 

31except ImportError: # pragma: no cover 

32 from typing_extensions import Annotated 

33 

34import typer 

35 

36from wuttjamaican.cli import wutta_typer 

37 

38log = logging.getLogger(__name__) 

39 

40 

41@wutta_typer.command() 

42def tell( 

43 ctx: typer.Context, 

44 profile: Annotated[ 

45 str, 

46 typer.Option( 

47 "--profile", 

48 "-p", 

49 help="Profile indicating which data to collect and where to submit it. " 

50 "If not specified, default profile is assumed.", 

51 ), 

52 ] = None, 

53 list_profiles: Annotated[ 

54 bool, 

55 typer.Option( 

56 "--list", 

57 "-l", 

58 help="List defined telemetry profiles.", 

59 ), 

60 ] = False, 

61 dry_run: Annotated[ 

62 bool, 

63 typer.Option( 

64 "--dry-run", 

65 help="Go through motions and log actions, but do not submit data.", 

66 ), 

67 ] = False, 

68): 

69 """ 

70 Collect and submit telemetry data 

71 """ 

72 config = ctx.parent.wutta_config 

73 app = config.get_app() 

74 telemetry = app.get_telemetry_handler() 

75 

76 if list_profiles: 

77 print("telemetry profiles:") 

78 print("-------------------------") 

79 for key in telemetry.get_all_profile_keys(): 

80 profile = telemetry.get_profile(key) 

81 print(key, profile.collect_keys) 

82 return 

83 

84 data = telemetry.collect_all_data(profile=profile) 

85 

86 if dry_run: 

87 log.info("dry run, so will not submit data to server") 

88 else: 

89 telemetry.submit_all_data(profile=profile, data=data) 

90 log.info("data submitted okay")