Debian Codegraph @

ansible_collections/community/docker/.azure-pipelines/scripts/time-command.py

raw
1 #!/usr/bin/env python
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 """Prepends a relative timestamp to each input line from stdin and writes it to stdout."""
7
8 from __future__ import (absolute_import, division, print_function)
9 __metaclass__ = type
10
11 import sys
12 import time
13
14
15 def main():
16 """Main program entry point."""
17 start = time.time()
18
19 sys.stdin.reconfigure(errors='surrogateescape')
20 sys.stdout.reconfigure(errors='surrogateescape')
21
22 for line in sys.stdin:
23 seconds = time.time() - start
24 sys.stdout.write('%02d:%02d %s' % (seconds // 60, seconds % 60, line))
25 sys.stdout.flush()
26
27
28 if __name__ == '__main__':
29 main()