1 回答
![?](http://img1.sycdn.imooc.com/545863c10001865402200220-100-100.jpg)
TA贡献1790条经验 获得超9个赞
我现在创建了以下名为 的脚本 runmke.py。
#!/Usr/bin/env python
import argparse
import os
import json
def run_symlink_makefile_cmd(dirname, make_cmds, verbose):
"""
Run common make commands from makefiles from
all symlinked directories that are located
in a specified directory
"""
make_cmds_str = " ".join(make_cmds)
for name in os.listdir(dirname):
if name not in (os.curdir, os.pardir):
full = os.path.join(dirname, name)
if os.path.islink(full):
if verbose:
print(f"\n>>>>> Running the Make command:")
print(f"make -C {full} {make_cmds_str}")
os.system(f"make -C {full} {make_cmds_str}")
def main(dirname, make_cmds, verbose):
# Display parameters passed for the given run (includes defaults)
print(f"""The parameters for this run are:\n {json.dumps(locals(), indent=2, default=str)}""")
run_symlink_makefile_cmd(dirname=dirname,
make_cmds=make_cmds,
verbose=verbose)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--dirname', action='store', default=os.getcwd(),
help='The directory in which symlink directories, default is the current directory')
parser.add_argument('-m', '--make_cmds', nargs='+',
default=["clean", "latex_style"],
help='These are the Makefile commands to run')
parser.add_argument('-v', '--verbose', action='store_true', default=True,
help='If true, print updates while processing.')
argument_parsed = parser.parse_args()
main(
dirname=argument_parsed.dirname,
make_cmds=argument_parsed.make_cmds,
verbose=argument_parsed.verbose
)
它可以在终端使用运行./runmke.py -m latex_style -v
添加回答
举报