Coverage for /opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/vfx_seqtools/actions/seqexp.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-05-30 00:30 +0000

1import logging 

2from typing import Annotated 

3 

4import fileseq 

5import typer 

6 

7from vfx_seqtools import common_options 

8from vfx_seqtools.decorators import attach_hook 

9 

10 

11def pad_frame(frame: int, pad: int = 0) -> str: 

12 """Return a padded frame number. 

13 

14 Args: 

15 frame (int): the frame number to pad 

16 pad (int): the number of zeros to pad the frame number with 

17 

18 Returns: 

19 str: string representation of the number - padded or unpadded. 

20 """ 

21 # handle padding for negative numbers 

22 if frame < 0: 

23 pad = pad + 1 if pad else 0 

24 return f"{frame:0{pad}d}" if pad else str(frame) 

25 

26 

27@attach_hook(common_options.logging_options, hook_output_kwarg="logger") 

28@attach_hook(common_options.version_option, hook_output_kwarg="show_version") 

29def seqexp( 

30 frameseq: Annotated[ 

31 str, typer.Argument(help="A frame sequence to expand, ex. 1-10x3.") 

32 ], 

33 show_version: bool, 

34 logger: logging.Logger, 

35 pad: Annotated[ 

36 int, 

37 typer.Option( 

38 "--pad", 

39 "-p", 

40 help="List frame numbers with zero padding, number of zeros to pad.", 

41 ), 

42 ] = 0, 

43 comma_separate: Annotated[ 

44 bool, 

45 typer.Option( 

46 "--comma-separate", 

47 "-c", 

48 help="Separate frame numbers with commas (default is spaces).", 

49 ), 

50 ] = False, 

51 long_list: Annotated[ 

52 bool, 

53 typer.Option( 

54 "--long-list", 

55 "-l", 

56 help="Long listing of frame numbers, one per line.", 

57 ), 

58 ] = False, 

59) -> None: 

60 """ 

61 Expand a frame sequence to individual frame numbers - quickly evaluate a frame sequence. 

62 

63 'seqexp 1-10x3' - will expand the frame sequence to 1 4 7 10. 

64 """ 

65 seq = fileseq.FrameSet(frameseq) 

66 

67 if long_list: 

68 for frame in seq: 

69 print(pad_frame(frame, pad)) 

70 else: 

71 if comma_separate: 

72 print(",".join(str(pad_frame(frame, pad)) for frame in seq)) 

73 else: 

74 print(" ".join(str(pad_frame(frame, pad)) for frame in seq))