-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremake.py
More file actions
executable file
·51 lines (41 loc) · 1.48 KB
/
remake.py
File metadata and controls
executable file
·51 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python2.7
from __future__ import print_function
from makefile import Makefile
import argparse
import os
import sys
def read_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', type=str, help='makefile to use')
parser.add_argument('-n', '--just-print', action='store_true',
help='Don\'t run commands. Only print them.')
parser.add_argument('target', nargs='?',
help='target in the makefile to run')
args = parser.parse_args()
return args
def error(msg):
print('Error: {}'.format(msg), file=sys.stderr)
sys.exit(1)
def main():
args = read_arguments()
if args.file:
# if -f flag was used to specify the makefile
file_name = args.file
# quit if this is not a valid file path
if not os.path.exists(file_name) or not os.path.isfile(file_name):
error('The file {} could not be found.'.format(file_name))
else:
file_name = ''
# search the current directory for a makefile
for path in os.listdir(os.getcwd()):
if os.path.isfile(path):
if os.path.basename(path).lower() == 'makefile':
file_name = path
break
# quit if no makefile was found
if not file_name:
error('Makefile not found.')
mkfile = Makefile(file_name, args.target, args.just_print)
mkfile.run_makefile()
if __name__ == '__main__':
main()