• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024, The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Module to assist users providing feedback."""
16
17import sys
18from atest.logstorage import log_uploader
19from atest.metrics import metrics
20
21
22# Keep it disabled until we can tell the capability of tmux.
23_DISABLE_HYPER_LINK_FORMAT_BY_DEFAULT = True
24
25
26_non_redirected_sys_stdout = sys.stdout
27
28
29def print_feedback_message(
30    is_internal_user=None, is_uploading_logs=None, use_hyper_link=None
31):
32  """Print the feedback message to console."""
33  if is_internal_user is None:
34    is_internal_user = metrics.is_internal_user()
35  if is_uploading_logs is None:
36    is_uploading_logs = log_uploader.is_uploading_logs()
37  if use_hyper_link is None:
38    use_hyper_link = (
39        not _DISABLE_HYPER_LINK_FORMAT_BY_DEFAULT
40        and getattr(_non_redirected_sys_stdout, 'isatty', lambda: False)()
41    )
42
43  if not is_internal_user:
44    return
45
46  if use_hyper_link:
47    print_link = lambda text, target: print(
48        f'\u001b]8;;{target}\u001b\\{text}\u001b]8;;\u001b\\'
49    )
50    if is_uploading_logs:
51      print_link(
52          'Click here to share feedback about this atest run.',
53          f'http://go/atest-feedback/{metrics.get_run_id()}',
54      )
55    else:
56      print_link(
57          'Click here to share feedback about atest.',
58          'http://go/atest-feedback-aosp',
59      )
60  else:
61    if is_uploading_logs:
62      print(
63          'To share feedback about this run:\n'
64          f'http://go/atest-feedback/{metrics.get_run_id()}'
65      )
66    else:
67      print('To share feedback about atest: http://go/atest-feedback-aosp')
68