-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupload_progress.py
141 lines (105 loc) · 4.94 KB
/
upload_progress.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""
Script for uploading progress to the frogress.
Adapted from https://github.com/zeldaret/af/blob/aeb01dcb95e8281f89f355604dbeba519ef073d5/tools/progress.py
MIT License: https://opensource.org/license/mit
"""
from pathlib import Path
from datetime import datetime
import argparse
import mapfile_parser
ASMPATH = Path("asm")
NONMATCHINGS = "nonmatchings"
BASE_URL = "https://progress.deco.mp"
SLUG = "sotc"
VERSION = "preview"
def getProgressFromMapFile(mapFile: mapfile_parser.MapFile, asmPath: Path, nonmatchings: Path, aliases: dict[str, str]=dict(), pathIndex: int=2) -> tuple[mapfile_parser.ProgressStats, dict[str, mapfile_parser.ProgressStats]]:
totalStats = mapfile_parser.ProgressStats()
progressPerFolder: dict[str, mapfile_parser.ProgressStats] = dict()
for segment in mapFile:
for file in segment:
if len(file) == 0:
continue
folder = file.filepath.parts[pathIndex]
if ".a" in folder:
folder = folder.split('.a')[0]
if folder in aliases:
folder = aliases[folder]
if folder not in progressPerFolder:
progressPerFolder[folder] = mapfile_parser.ProgressStats()
originalFilePath = Path(*file.filepath.parts[pathIndex:])
extensionlessFilePath = originalFilePath
while extensionlessFilePath.suffix:
extensionlessFilePath = extensionlessFilePath.with_suffix("")
fullAsmFile = asmPath / extensionlessFilePath.with_suffix(".s")
handwrittenAsmFiles = [Path("sdk/crt0.o")]
if originalFilePath in handwrittenAsmFiles:
wholeFileIsUndecomped = False
else:
wholeFileIsUndecomped = fullAsmFile.exists()
for func in file:
funcAsmPath = nonmatchings / extensionlessFilePath / f"{func.name}.s"
symSize = 0
if func.size is not None:
symSize = func.size
if wholeFileIsUndecomped:
totalStats.undecompedSize += symSize
progressPerFolder[folder].undecompedSize += symSize
elif funcAsmPath.exists():
totalStats.undecompedSize += symSize
progressPerFolder[folder].undecompedSize += symSize
else:
totalStats.decompedSize += symSize
progressPerFolder[folder].decompedSize += symSize
return totalStats, progressPerFolder
def getProgress(mapPath: str, asmPath: str) -> tuple[mapfile_parser.ProgressStats, dict[str, mapfile_parser.ProgressStats]]:
"""
Gets the progress of the project using the mapfile parser.
"""
mapFile = mapfile_parser.MapFile()
mapFile.readMapFile(mapPath)
for segment in mapFile:
for file in segment:
if len(file) == 0:
continue
filepathParts = list(file.filepath.parts)
file.filepath = Path(*filepathParts)
asmPath = ASMPATH / Path(asmPath)
nonMatchingsPath = asmPath / NONMATCHINGS
print(f"ASM path: {asmPath}")
print(f"Nonmatchings path: {nonMatchingsPath}")
progress = getProgressFromMapFile(mapFile.filterBySectionType(".text"), asmPath, nonMatchingsPath)
return progress
def processMapFiles(mapFiles: list[tuple[str,str]], frogress_api_key: str) -> None:
"""
Processes a list of map files and uploads their progress to frogress.
"""
for mapfilePathStr, mapfileAsmDir in mapFiles:
print(f"Processing map file: {mapfilePathStr}")
# Get progress stats for the current map file
codeTotalStats, codeProgressPerFolder = getProgress(mapfilePathStr, mapfileAsmDir)
codeEntries = mapfile_parser.frontends.upload_frogress.getFrogressEntriesFromStats(
codeTotalStats, codeProgressPerFolder, verbose=True
)
# Print stats for debugging
mapfile_parser.progress_stats.printStats(codeTotalStats, codeProgressPerFolder)
url = mapfile_parser.utils.generateFrogressEndpointUrl(BASE_URL, SLUG, VERSION)
# Reuse asm directory as the category name
mapfile_parser.frontends.upload_frogress.uploadEntriesToFrogress(codeEntries, mapfileAsmDir, url, apikey=frogress_api_key, verbose=True)
def main(args: argparse.ArgumentParser) -> None:
"""
Main function, calculates the progress and uploads it to frogress.
"""
frogress_api_key = args.frogress_api_key
if not frogress_api_key:
raise ValueError("Missing frogress API key.")
# Map files and their asm directories
mapFiles = [
("build/SCPS_150.97.map", "loader"),
("build/KERNEL.XFF.map", "kernel")
]
processMapFiles(mapFiles, frogress_api_key)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Upload progress to the frogress")
parser.add_argument("--frogress_api_key", help="API key for the frogress")
args = parser.parse_args()
main(args)