forked from Shuffle/python-apps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyze.py
100 lines (80 loc) · 3.16 KB
/
analyze.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import yaml
import os
import subprocess
basedir = "."
dirs = os.listdir(basedir)
#print(dirs)
#basename = "testing"
for basename in dirs:
if basename == ".gitignore" or basename == ".github" or basename == "README.md" or basename == ".git" or basename == "unsupported" or ".swp" in basename or ".swo" in basename:
continue
print(f"\n[DEBUG] Analyzing: {basename}")
try:
versions = os.listdir("./%s" % basename)
except NotADirectoryError:
continue
for version in versions:
filepath = "%s/%s/api.yaml" % (basename, version)
try:
with open(filepath, "r") as tmp:
try:
ret = yaml.full_load(tmp.read())
except yaml.scanner.ScannerError as e:
print(f"Bad yaml in {filepath} (2): {e}")
continue
newname = ret["name"].lower().replace(" ", "-", -1).replace(".", "-", -1)
if newname != basename:
print("Bad name: %s vs %s" % (basename, newname))
if ret["app_version"] != version:
print("Bad version (%s): %s vs %s" % (basename, version, ret["app_version"]))
if "svg" in ret["large_image"]:
print("Unsupported large_image format: svg")
#else:
# print("%s:%s is valid" % (basename, version))
except (NotADirectoryError, FileNotFoundError) as e:
#print("Error inner file: %s" % e)
pass
try:
subfolders = os.listdir(f"{basedir}/{basename}")
except:
continue
for subfolder in subfolders:
apifile = f"{basedir}/{basename}/{subfolder}/api.yaml"
pythonfile = f"{basedir}/{basename}/{subfolder}/src/app.py"
action_names = []
try:
with open(apifile, "r") as tmp:
try:
apidata = yaml.full_load(tmp.read())
except yaml.scanner.ScannerError as e:
print(f"Bad yaml in {apifile} (2): {e}")
continue
for item in apidata["actions"]:
action_names.append(item["name"])
except NotADirectoryError as e:
continue
with open(pythonfile, "r") as tmp:
pythondata = tmp.read()
for action_name in action_names:
if not action_name in pythondata:
print(f"===> Couldn't find action \"{action_name}\" from {apifile} in script {pythonfile}")
code = f"python3 {pythonfile}"
process = subprocess.Popen(
code,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
shell=True, # nosec
)
stdout = process.communicate()
item = ""
if len(stdout[0]) > 0:
#print("Succesfully ran bash!")
item = stdout[0]
else:
item = stdout[1]
if "ModuleNotFoundError" in item:
continue
print(f"FAILED to run bash with code {code}: {item}")
#break
#for item in