• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4#  Copyright 2021 Google, Inc.
5#
6#  Licensed under the Apache License, Version 2.0 (the "License");
7#  you may not use this file except in compliance with the License.
8#  You may obtain a copy of the License at:
9#
10#  http://www.apache.org/licenses/LICENSE-2.0
11#
12#  Unless required by applicable law or agreed to in writing, software
13#  distributed under the License is distributed on an "AS IS" BASIS,
14#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15#  See the License for the specific language governing permissions and
16#  limitations under the License.
17""" Get contents of given files and pass as args to remaining params.
18
19Example:
20  a.files = [ "foo", "bar" ]
21  b.files = [ "fizz", "buzz" ]
22
23  extract_files_and_call.py a.files b.files -- somebin -a --set foo -c -o
24
25  will result in this call:
26
27  somebin -a --set foo -c -o foo bar fizz buzz
28
29"""
30
31from __future__ import print_function
32
33import subprocess
34import sys
35
36
37def file_to_args(filename):
38    """ Read file and return lines with empties removed.
39    """
40    with open(filename, 'r') as f:
41        return [x.strip() for x in f.readlines() if x.strip()]
42
43
44def main():
45    file_contents = []
46    args = []
47    for i in range(1, len(sys.argv) - 1):
48        if sys.argv[i] == '--':
49            args = sys.argv[i + 1:] + file_contents
50            break
51        else:
52            file_contents.extend(file_to_args(sys.argv[i]))
53
54    subprocess.check_call(args)
55
56
57if __name__ == "__main__":
58    main()
59