]> jfr.im git - yt-dlp.git/blame - devscripts/utils.py
[extractor/lefigaro] Add extractors (#6309)
[yt-dlp.git] / devscripts / utils.py
CommitLineData
115add43 1import argparse
2import functools
3
4
5def read_file(fname):
6 with open(fname, encoding='utf-8') as f:
7 return f.read()
8
9
7d61d230
L
10def write_file(fname, content, mode='w'):
11 with open(fname, mode, encoding='utf-8') as f:
115add43 12 return f.write(content)
13
14
15# Get the version without importing the package
16def read_version(fname='yt_dlp/version.py'):
17 exec(compile(read_file(fname), fname, 'exec'))
18 return locals()['__version__']
19
20
21def get_filename_args(has_infile=False, default_outfile=None):
22 parser = argparse.ArgumentParser()
23 if has_infile:
24 parser.add_argument('infile', help='Input file')
25 kwargs = {'nargs': '?', 'default': default_outfile} if default_outfile else {}
26 parser.add_argument('outfile', **kwargs, help='Output file')
27
28 opts = parser.parse_args()
29 if has_infile:
30 return opts.infile, opts.outfile
31 return opts.outfile
32
33
34def compose_functions(*functions):
35 return lambda x: functools.reduce(lambda y, f: f(y), functions, x)