Coverage for /opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/vfx_seqtools/common_options.py: 89%
45 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-05-30 00:30 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-05-30 00:30 +0000
1import logging
2import pathlib
3from typing import Annotated, Optional
5import typer
7from vfx_seqtools import __version__
10def version_callback(value: bool) -> None:
11 """Display the version of the package."""
12 if value:
13 typer.echo(f"vfx-seqtools, version {__version__}")
14 raise typer.Exit()
17def version_option(
18 version: bool = typer.Option(
19 False,
20 "--version",
21 is_eager=True,
22 help="Show the version of the package.",
23 callback=version_callback,
24 ),
25) -> None:
26 """Utilities for working with VFX frame sequences."""
27 pass
30def dry_run_option(
31 dry_run: Annotated[
32 bool,
33 typer.Option(
34 "--dry-run",
35 "-n",
36 help="Show what would be done, but do not do it.",
37 ),
38 ] = False,
39) -> bool:
40 return dry_run
43def logging_options(
44 log_level: Annotated[
45 int,
46 typer.Option(help="Log level. Must be a Python log level (10,20,30,40,50)."),
47 ] = logging.INFO,
48 log_to_file: Annotated[
49 Optional[pathlib.Path], typer.Option(help="A file to stream logs to.")
50 ] = None,
51) -> logging.Logger:
52 logger = logging.getLogger("vfx_seqtools")
53 logger.setLevel(log_level)
54 # set a simple format for basic logging
56 if log_level <= 20:
57 formatter = logging.Formatter("%(name)-12s: %(levelname)-8s %(message)s")
58 else:
59 formatter = logging.Formatter(
60 "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
61 )
62 console_handler = logging.StreamHandler()
63 console_handler.setFormatter(formatter)
64 logger.addHandler(console_handler)
65 if log_to_file:
66 file_handler = logging.FileHandler(log_to_file)
67 file_handler.setFormatter(formatter)
68 logger.addHandler(file_handler)
69 return logger
72def interactive_option(
73 interactive: Annotated[
74 Optional[bool],
75 typer.Option(
76 "--interactive",
77 "-i",
78 help="Request confirmation before attempting to act on each file.",
79 ),
80 ] = False,
81) -> Optional[bool]:
82 return interactive
85def verbose_option(
86 verbose: Annotated[
87 Optional[bool],
88 typer.Option(
89 "--verbose",
90 "-v",
91 help="Be verbose when acting, showing actions as they are taken.",
92 ),
93 ] = False,
94) -> Optional[bool]:
95 return verbose
98def strict_option(
99 strict: Annotated[
100 Optional[bool],
101 typer.Option(help="Be strict; stop on errors."),
102 ] = False,
103) -> Optional[bool]:
104 return strict
107def quiet_option(
108 quiet: Annotated[
109 Optional[bool],
110 typer.Option("--quiet", "-q", help="Be quiet; produce minimal output."),
111 ] = False,
112) -> Optional[bool]:
113 return quiet
116def sequence_only_option(
117 only_sequences: Annotated[
118 Optional[bool],
119 typer.Option(
120 "--only-sequences",
121 "-o",
122 help="Only consider sequences; ignore non-sequence files.",
123 ),
124 ] = False,
125) -> Optional[bool]:
126 return only_sequences
129def missing_frames_option(
130 missing_frames: Annotated[
131 Optional[bool],
132 typer.Option(
133 "--missing-frames",
134 "-m",
135 help="Show missing frames in sequences.",
136 ),
137 ] = False,
138) -> Optional[bool]:
139 return missing_frames
142def frame_range_options(
143 frame_start: Annotated[
144 int,
145 typer.Option("--frame-start", "-fs", help="frame start. must be an integer."),
146 ] = 0,
147 frame_end: Annotated[
148 int, typer.Option("--frame-end", "-fe", help="frame end. must be an integer.")
149 ] = 0,
150 frame_increment: Annotated[
151 Optional[int],
152 typer.Option(
153 "--frame-increment",
154 "-fi",
155 help="frame increment. optional, must be an integer, default=1.",
156 ),
157 ] = 1,
158) -> tuple[int, int, Optional[int]]:
159 return frame_start, frame_end, frame_increment
162def frame_seq_options(
163 frameseq: Annotated[
164 str,
165 typer.Option(
166 "--frame-seq", "-f", help="A frame sequence to expand, ex. 1-10x3."
167 ),
168 ] = "",
169) -> Optional[str]:
170 return frameseq
173def threading_option(
174 threads: Annotated[
175 Optional[int],
176 typer.Option(
177 "--threads",
178 "-t",
179 help="Number of threads to use; default=0 (all threads). Negative integers will use all but n threads.",
180 ),
181 ] = 0,
182) -> Optional[int]:
183 return threads