File: template_simple.py

package info (click to toggle)
python-pbcommand 2.1.1%2Bgit20231020.28d1635-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,016 kB
  • sloc: python: 7,676; makefile: 220; sh: 73
file content (51 lines) | stat: -rw-r--r-- 1,330 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Simple Example Template for creating a CLI tool
"""

import logging
import os
import sys

from pbcommand.validators import validate_file
from pbcommand.utils import setup_log
from pbcommand.cli import get_default_argparser_with_base_opts, pacbio_args_runner

log = logging.getLogger(__name__)

__version__ = "0.1.0"


def get_parser():
    """Define Parser. Use the helper methods in validators to validate input"""
    p = get_default_argparser_with_base_opts(__version__, __doc__)
    p.add_argument('path_to_file', type=validate_file, help="Path to File")
    return p


def run_main(path, value=8):
    """
    Main function that should be called. Typically this is imported from your
    library code.

    This should NOT reference args.*
    """
    log.info("Running path {p} with value {v}".format(p=path, v=value))
    log.info("Found path? {t} {p}".format(p=path, t=os.path.exists(path)))
    return 0


def args_runner(args):
    log.info("Raw args {a}".format(a=args))
    return run_main(args.path_to_file, value=100)


def main(argv):
    return pacbio_args_runner(argv[1:],
                              get_parser(),
                              args_runner,
                              log,
                              setup_log_func=setup_log)


if __name__ == '__main__':
    sys.exit(main(sys.argv))