MCPcopy Create free account
hub / github.com/smacke/ffsubsync / make_test_case

Function make_test_case

ffsubsync/ffsubsync.py:62–101  ·  view source on GitHub ↗
(
    args: argparse.Namespace, npy_savename: Optional[str], sync_was_successful: bool
)

Source from the content-addressed store, hash-verified

60
61
62def make_test_case(
63 args: argparse.Namespace, npy_savename: Optional[str], sync_was_successful: bool
64) -> int:
65 if npy_savename is None:
66 raise ValueError("need non-null npy_savename")
67 tar_dir = "{}.{}".format(
68 args.reference, datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
69 )
70 logger.info("creating test archive {}.tar.gz...".format(tar_dir))
71 os.mkdir(tar_dir)
72 try:
73 log_path = "ffsubsync.log"
74 if args.log_dir_path is not None and os.path.isdir(args.log_dir_path):
75 log_path = os.path.join(args.log_dir_path, log_path)
76 shutil.copy(log_path, tar_dir)
77 shutil.copy(args.srtin[0], tar_dir)
78 if sync_was_successful:
79 shutil.move(args.srtout, tar_dir)
80 if _ref_format(args.reference) in SUBTITLE_EXTENSIONS:
81 shutil.copy(args.reference, tar_dir)
82 elif args.serialize_speech or args.reference == npy_savename:
83 shutil.copy(npy_savename, tar_dir)
84 else:
85 shutil.move(npy_savename, tar_dir)
86 supported_formats = set(list(zip(*shutil.get_archive_formats()))[0])
87 preferred_formats = ["gztar", "bztar", "xztar", "zip", "tar"]
88 for archive_format in preferred_formats:
89 if archive_format in supported_formats:
90 shutil.make_archive(tar_dir, archive_format, os.curdir, tar_dir)
91 break
92 else:
93 logger.error(
94 "failed to create test archive; no formats supported "
95 "(this should not happen)"
96 )
97 return 1
98 logger.info("...done")
99 finally:
100 shutil.rmtree(tar_dir)
101 return 0
102
103
104def _resolve_srtout(args: argparse.Namespace, srtin: Optional[str]) -> Optional[str]:

Callers 1

runFunction · 0.85

Calls 1

_ref_formatFunction · 0.85

Tested by

no test coverage detected