forked from Serchinastico/Kin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkin.py
executable file
·77 lines (57 loc) · 1.98 KB
/
kin.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
import sys
import os
from verifier import Verifier
from grammar.PBXProjLexer import PBXProjLexer
from grammar.PBXProjParser import PBXProjParser
def check_errors(file):
verifier = Verifier()
errors = verifier.check_errors(file)
return errors
def find_target_files():
target_files = []
if len(sys.argv) == 2:
target_files.append(sys.argv[1])
else:
for f in os.listdir(os.getcwd()):
if f.endswith(".xcodeproj"):
target_files.append(os.path.join(f, "project.pbxproj"))
return target_files
def print_help():
print("USAGE: kin [file]\n" +
"DESCRIPTION: Verifies the correctness of your project.pbxproj " +
"file. If no arguments are supplied, Kin will try to find a " +
"project.pbxproj file in the current project.\nARGUMENTS:\n" +
"\t- file\tOptionally provides the location of your " +
"project.pbxproj file")
def assert_valid_target_files(target_files):
if len(target_files) == 0:
print("ERROR: Unable to find project.pbxproj " +
"file in the current directory\n")
print_help()
sys.exit(-2)
elif len(target_files) > 1:
print("ERROR: Too many project.pbxproj files: " +
str(target_files) + ". Remember you can call Kin with a " +
"parameter to specify the file you want to verify, i.e. \"kin " +
str(target_files[0]) + "\"\n")
print_help()
sys.exit(-3)
def assert_no_errors(errors):
if errors:
sys.exit(-1)
def print_verification_result(errors):
if errors:
for error in errors:
print("ERROR: " + error)
else:
print("CORRECT")
def main():
target_files = find_target_files()
assert_valid_target_files(target_files)
target_file = target_files[0]
errors = check_errors(target_file)
print_verification_result(errors)
assert_no_errors(errors)
if __name__ == '__main__':
main()