ca0c31de09f0b88ca2a5c9b5c6d897768470740e hiram Thu Sep 11 13:19:22 2025 -0700 quickLiftChain table entry script refs #35575 diff --git src/hg/utils/automation/addQuickLift.py src/hg/utils/automation/addQuickLift.py new file mode 100755 index 00000000000..d5b6728a270 --- /dev/null +++ src/hg/utils/automation/addQuickLift.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 +######################################################################## +### addQuickLift.py fromDb toDb path +### +### adds entry to quickLiftChain hgcentral table if the entry does not +### yet exist +######################################################################## + +import subprocess +import sys + +def runHgsql(sql): + cmd = ["hgsql", "hgcentraltest", "-N", "-e", sql] + result = subprocess.run(cmd, capture_output=True, text=True) + if result.returncode != 0: + sys.stderr.write(result.stderr) + sys.exit(result.returncode) + return result.stdout.strip() + +def main(): + if len(sys.argv) != 4: + print(f"Usage: addQuickLift.py fromDb toDb path", file=sys.stderr) + print(f"\nAdds entry to quickLiftChain hgcentral table if the entry does\nnot yet exist.", file=sys.stderr) + sys.exit(255) + + fromDb, toDb, path = sys.argv[1], sys.argv[2], sys.argv[3] + + # Check if entry already exists + sql = f"SELECT path FROM quickLiftChain WHERE fromDb='{fromDb}' AND toDb='{toDb}'" + rows = runHgsql(sql).splitlines() + if len(rows) > 1: + print(f"ERROR: duplicate entries for {fromDb}.{toDb} found.") + sys.exit(255) + + existingPath = rows[0] if rows else "" + if existingPath: + if existingPath == path: + print(f"Entry {fromDb}.{toDb} already exists with identical path.") + sys.exit(0) + else: + print(f"Error: entry for {fromDb}.{toDb} exists with different path: {existingPath} != {path}", file=sys.stderr) + sys.exit(255) + else: + # Insert new entry + sql = f"INSERT INTO quickLiftChain (fromDb, toDb, path) VALUES ('{fromDb}', '{toDb}', '{path}')" + sqlResult = runHgsql(sql) + +if __name__ == "__main__": + main()