Skip to content

Commit 22d9131

Browse files
ShivangNagtasev-
authored andcommitted
INTEGRITY: Add possible merge button inside filesets dashboard
1 parent d335d91 commit 22d9131

File tree

3 files changed

+117
-13
lines changed

3 files changed

+117
-13
lines changed

db_functions.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ def set_process(
947947

948948
# Mac files in set.dat are not represented properly and they won't find a candidate fileset for a match, so we can drop them.
949949
if len(candidate_filesets) == 0:
950-
category_text = "Drop set fileset - A"
950+
category_text = "Drop fileset - No Candidates"
951951
fileset_name = fileset["name"] if "name" in fileset else ""
952952
fileset_description = (
953953
fileset["description"] if "description" in fileset else ""
@@ -988,7 +988,7 @@ def set_process(
988988

989989
for set_fileset in set_filesets:
990990
fileset = id_to_fileset_dict[set_fileset]
991-
category_text = "Drop set fileset - B"
991+
category_text = "Drop fileset - Duplicates"
992992
fileset_name = fileset["name"] if "name" in fileset else ""
993993
fileset_description = (
994994
fileset["description"] if "description" in fileset else ""
@@ -1098,15 +1098,15 @@ def set_perform_match(
10981098
else:
10991099
category_text = "Mismatch"
11001100
log_text = f"Fileset:{fileset_id} mismatched with Fileset:{matched_fileset_id} with status:{status}. Try manual merge."
1101-
print(
1102-
f"Merge Fileset:{fileset_id} manually with Fileset:{matched_fileset_id}. Unmatched files: {len(unmatched_files)}."
1103-
)
1101+
print_text = f"Merge Fileset:{fileset_id} manually with Fileset:{matched_fileset_id}. Unmatched files: {len(unmatched_files)}."
11041102
mismatch_filesets += 1
1105-
# print(f"Merge Fileset:{fileset_id} manually with Fileset:{matched_fileset_id}. Unmatched files: {', '.join(filename for filename in unmatched_files)}.")
1106-
create_log(
1107-
escape_string(category_text),
1103+
add_manual_merge(
1104+
[matched_fileset_id],
1105+
fileset_id,
1106+
category_text,
1107+
log_text,
1108+
print_text,
11081109
user,
1109-
escape_string(log_text),
11101110
conn,
11111111
)
11121112

@@ -1134,11 +1134,16 @@ def set_perform_match(
11341134
if not found_match:
11351135
category_text = "Manual Merge Required"
11361136
log_text = f"Merge Fileset:{fileset_id} manually. Possible matches are: {', '.join(f'Fileset:{id}' for id in candidate_filesets)}."
1137-
print(log_text)
1138-
create_log(
1139-
escape_string(category_text), user, escape_string(log_text), conn
1140-
)
11411137
manual_merged_filesets += 1
1138+
add_manual_merge(
1139+
candidate_filesets,
1140+
fileset_id,
1141+
category_text,
1142+
log_text,
1143+
log_text,
1144+
user,
1145+
conn,
1146+
)
11421147

11431148
return (
11441149
fully_matched_filesets,
@@ -1148,6 +1153,26 @@ def set_perform_match(
11481153
)
11491154

11501155

1156+
def add_manual_merge(
1157+
child_filesets, parent_fileset, category_text, log_text, print_text, user, conn
1158+
):
1159+
"""
1160+
Adds the manual merge entries to a table called possible_merges.
1161+
"""
1162+
with conn.cursor() as cursor:
1163+
for child_fileset in child_filesets:
1164+
query = """
1165+
INSERT INTO possible_merges
1166+
(child_fileset, parent_fileset)
1167+
VALUES
1168+
(%s, %s)
1169+
"""
1170+
cursor.execute(query, (child_fileset, parent_fileset))
1171+
1172+
create_log(escape_string(category_text), user, escape_string(log_text), conn)
1173+
print(print_text)
1174+
1175+
11511176
def is_full_checksum_match(candidate_fileset, fileset, conn):
11521177
"""
11531178
Return type - (Boolean, List of unmatched files)

fileset.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def fileset():
164164
"""
165165
html += f"<button type='button' onclick=\"location.href='/fileset/{id}/merge'\">Manual Merge</button>"
166166
html += f"<button type='button' onclick=\"location.href='/fileset/{id}/match'\">Match and Merge</button>"
167+
html += f"<button type='button' onclick=\"location.href='/fileset/{id}/possible_merge'\">Possible Merges</button>"
167168
html += f"""
168169
<form action="/fileset/{id}/mark_full" method="post" style="display:inline;">
169170
<button type='submit'>Mark as full</button>
@@ -603,6 +604,75 @@ def merge_fileset(id):
603604
"""
604605

605606

607+
@app.route("/fileset/<int:id>/possible_merge", methods=["GET", "POST"])
608+
def possible_merge_filesets(id):
609+
base_dir = os.path.dirname(os.path.abspath(__file__))
610+
config_path = os.path.join(base_dir, "mysql_config.json")
611+
with open(config_path) as f:
612+
mysql_cred = json.load(f)
613+
614+
connection = pymysql.connect(
615+
host=mysql_cred["servername"],
616+
user=mysql_cred["username"],
617+
password=mysql_cred["password"],
618+
db=mysql_cred["dbname"],
619+
charset="utf8mb4",
620+
cursorclass=pymysql.cursors.DictCursor,
621+
)
622+
623+
try:
624+
with connection.cursor() as cursor:
625+
query = """
626+
SELECT
627+
fs.*,
628+
g.name AS game_name,
629+
g.engine AS game_engine,
630+
g.platform AS game_platform,
631+
g.language AS game_language,
632+
g.extra AS extra
633+
FROM
634+
fileset fs
635+
LEFT JOIN
636+
game g ON fs.game = g.id
637+
JOIN
638+
possible_merges pm ON pm.child_fileset = fs.id
639+
WHERE pm.parent_fileset = %s
640+
"""
641+
cursor.execute(query, (id,))
642+
results = cursor.fetchall()
643+
644+
html = f"""
645+
<!DOCTYPE html>
646+
<html>
647+
<head>
648+
<link rel="stylesheet" type="text/css" href="{{{{ url_for('static', filename='style.css') }}}}">
649+
</head>
650+
<body>
651+
<h2>Possible Merges for fileset-'{id}'</h2>
652+
<table>
653+
<tr><th>ID</th><th>Game Name</th><th>Platform</th><th>Language</th><th>Extra</th><th>Details</th><th>Action</th></tr>
654+
"""
655+
for result in results:
656+
html += f"""
657+
<tr>
658+
<td>{result["id"]}</td>
659+
<td>{result["game_name"]}</td>
660+
<td>{result["game_platform"]}</td>
661+
<td>{result["game_language"]}</td>
662+
<td>{result["extra"]}</td>
663+
<td><a href="/fileset?id={result["id"]}">View Details</a></td>
664+
<td><a href="/fileset/{id}/merge/confirm?target_id={result["id"]}">Select</a></td>
665+
</tr>
666+
"""
667+
html += "</table>\n"
668+
html += "</body>\n</html>"
669+
670+
return render_template_string(html)
671+
672+
finally:
673+
connection.close()
674+
675+
606676
@app.route("/fileset/<int:id>/merge/confirm", methods=["GET", "POST"])
607677
def confirm_merge(id):
608678
target_id = (

schema.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@
132132
fileset INT NOT NULL
133133
)
134134
""",
135+
"possible_merges": """
136+
CREATE TABLE IF NOT EXISTS possible_merges (
137+
id INT AUTO_INCREMENT PRIMARY KEY,
138+
child_fileset INT,
139+
parent_fileset INT,
140+
FOREIGN KEY (child_fileset) REFERENCES fileset(id) ON DELETE CASCADE,
141+
FOREIGN KEY (parent_fileset) REFERENCES fileset(id) ON DELETE CASCADE
142+
)
143+
""",
135144
}
136145

137146
for table, definition in tables.items():

0 commit comments

Comments
 (0)