| #!/usr/bin/env python3 |
| # -*- coding: utf-8 -*- |
| # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """This is a mock ectool command for fingerprint testing.""" |
| |
| from __future__ import print_function |
| |
| import argparse |
| import sys |
| |
| |
| def cmd_fpframe(): |
| """Provides the last fingerprint capture frame to stdout.""" |
| print('Act like I am a raw fingerprint image file.') |
| sys.exit(0) |
| |
| |
| def cmd_fpmode(): |
| """Shows the current fingerprint subsystem's state/mode.""" |
| print('FP mode: (0x0)') |
| sys.exit(0) |
| |
| |
| def get_parser() -> argparse.ArgumentParser: |
| """Return the complete argument parser for ectool.""" |
| parser = argparse.ArgumentParser(description=__doc__) |
| |
| parser.add_argument('--name') |
| parser_subparsers = parser.add_subparsers(dest='action') |
| |
| # fpmode |
| parser_fpmode = parser_subparsers.add_parser('fpmode') |
| parser_fpmode.description = cmd_fpmode.__doc__ |
| parser_fpmode.set_defaults(func=cmd_fpmode) |
| # fpmode capture vendor |
| parser_fpmode_subparsers = parser_fpmode.add_subparsers(dest='fpmode') |
| parser_fpmode_subparsers.add_parser('capture').add_argument( |
| 'capture_type', |
| choices=['vendor'], |
| ) |
| # fpmode fingerup |
| parser_fpmode_subparsers.add_parser('fingerup') |
| |
| # fpframe raw |
| parser_fpframe = parser_subparsers.add_parser('fpframe') |
| parser_fpframe.description = cmd_fpframe.__doc__ |
| parser_fpframe.set_defaults(func=cmd_fpframe) |
| parser_fpframe.add_argument('option', choices=['raw']) |
| return parser |
| |
| |
| def main(argv: list): |
| """Run argument parser and launch subcommand.""" |
| parser = get_parser() |
| opts = parser.parse_args(argv) |
| |
| if opts.name != 'cros_fp': |
| parser.error('--name=cros_fp must be specified') |
| |
| opts.func() |
| |
| |
| if __name__ == '__main__': |
| sys.exit(main(sys.argv[1:])) |