|
1 | 1 | import os |
2 | 2 | import csv |
3 | 3 | import sys |
| 4 | +import subprocess |
4 | 5 |
|
5 | 6 | SOLUTIONS_FILENAME = "_control/solutions.csv" |
6 | 7 |
|
7 | 8 |
|
| 9 | +INCLUDE = set() |
| 10 | + |
8 | 11 | def install_solution(solution_name): |
9 | 12 | min_setup_file_name = f"./{solution_name}/min-setup-{solution_name}.sh" |
10 | 13 | setup_file_name = f"./{solution_name}/setup-{solution_name}.sh" |
| 14 | + upgrade_file_name = f"./{solution_name}/upg-{solution_name}.sh" |
| 15 | + get_version_filename = f"./{solution_name}/ver-{solution_name}.sh" |
11 | 16 | print(f"Installing {solution_name}") |
12 | | - if os.path.exists(min_setup_file_name): |
13 | | - os.system(min_setup_file_name) |
14 | | - elif os.path.exists(setup_file_name): |
15 | | - os.system(setup_file_name) |
| 17 | + do_install = False |
| 18 | + try: |
| 19 | + subprocess.call([get_version_filename], stdout="/dev/null") |
| 20 | + except Exception as e: |
| 21 | + do_install = True |
| 22 | + |
| 23 | + if do_install: |
| 24 | + if os.path.exists(min_setup_file_name): |
| 25 | + subprocess.call([min_setup_file_name]) |
| 26 | + elif os.path.exists(setup_file_name): |
| 27 | + subprocess.call([setup_file_name]) |
| 28 | + else: |
| 29 | + # print(f"no script for {setup_file_name} or {min_setup_file_name}") |
| 30 | + raise Exception(f"No script to install {solution_name}") |
16 | 31 | else: |
17 | | - # print(f"no script for {setup_file_name} or {min_setup_file_name}") |
18 | | - raise Exception(f"No script to install {solution_name}") |
| 32 | + subprocess.call([upgrade_file_name]) |
19 | 33 |
|
20 | 34 | # based on the name of the solution, run the {{solution}}/min-setup-{{solution}}.sh file. |
21 | 35 | # if there is no min-setup-{{solution}}.sh, then run setup-{{solution}}.sh. |
22 | 36 | # if error, exit with an error |
23 | 37 | # else don't |
24 | | -def install_all_solutions(): |
25 | | - install_solutions = set() |
| 38 | +def include_all_solutions(): |
| 39 | + global INCLUDE |
26 | 40 | with open(SOLUTIONS_FILENAME, newline="") as solutions_file: |
27 | 41 | solutions = csv.DictReader(solutions_file, delimiter=',') |
28 | 42 | for row in solutions: |
29 | 43 | if row['solution'] == "data.table": |
30 | | - install_solutions.add("datatable") |
| 44 | + INCLUDE.add("datatable") |
31 | 45 | else: |
32 | | - install_solutions.add(row['solution']) |
33 | | - for solution in install_solutions: |
34 | | - install_solution(solution) |
| 46 | + INCLUDE.add(row['solution']) |
35 | 47 |
|
36 | 48 | if len(sys.argv) == 0: |
37 | | - print("Usage: python3 install_all_solutions.py solution_name solution_name ...") |
| 49 | + print(""" |
| 50 | +Usage: python3 install_all_solutions.py solution_name solution_name ... |
| 51 | + python3 install_all_solutions.py all --exclude clickhouse polars |
| 52 | +""") |
38 | 53 | exit(1) |
39 | 54 |
|
40 | 55 | # first argument is file name |
41 | | -for solution in sys.argv[1:]: |
42 | | - if solution.strip() == "all": |
43 | | - install_all_solutions() |
44 | | - else: |
45 | | - if solution == "data.table": |
46 | | - install_solution("datatable") |
47 | | - elif solution == "clickhouse": |
48 | | - install_solution("clickhouse") |
49 | | - install_solution("polars") |
| 56 | + |
| 57 | +def main(): |
| 58 | + global INCLUDE |
| 59 | + including = True |
| 60 | + for solution in sys.argv[1:]: |
| 61 | + if solution.strip() == "all": |
| 62 | + include_all_solutions() |
| 63 | + elif solution.strip() == "--exclude": |
| 64 | + including = False |
50 | 65 | else: |
51 | | - install_solution(solution) |
52 | | - |
| 66 | + if including: |
| 67 | + if solution == "data.table": |
| 68 | + INCLUDE.add("datatable") |
| 69 | + elif solution == "clickhouse": |
| 70 | + INCLUDE.add("clickhouse") |
| 71 | + else: |
| 72 | + INCLUDE.add(solution) |
| 73 | + else: |
| 74 | + sol = solution.strip() |
| 75 | + INCLUDE.remove(sol) |
| 76 | + |
| 77 | + for solution in INCLUDE: |
| 78 | + install_solution(solution) |
| 79 | + |
| 80 | + |
| 81 | +if __name__ == "__main__": |
| 82 | + main() |
| 83 | + |
0 commit comments