Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # encoding: utf-8
- import os
- import sys
- import argparse
- import json
- import re
- import subprocess
- ### Require python3
- if sys.version_info[0] != 3:
- print("This script requires Python 3")
- exit()
- def main():
- myargs = []
- with open('substitution.conf','r') as f:
- while(True):
- a = f.readline().strip()
- if(a == ''):
- break
- myargs.append(a)
- if(len(myargs) == 0):
- print('Nothing to do.')
- exit(2)
- parser1 = argparse.ArgumentParser()
- parser1.add_argument('filename')
- args = parser1.parse_args()
- parser2 = argparse.ArgumentParser()
- parser2.add_argument('command')
- parser2.add_argument('--dry-run', action='store_true', default=False, help='dry run')
- parser2.add_argument('args', nargs='+')
- args2 = parser2.parse_args(myargs)
- cmd= [args2.command,args.filename]+ args2.args
- if(args2.dry_run):
- print('$ {}'.format(cmd))
- else:
- subprocess.call(cmd)
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment