Debian Codegraph @

app/lomiri-calculator-app-migrate.py

raw symbols SCIP
1 #!/usr/bin/python3
2
3 import hashlib
4 import os
5 import sys
6 from pathlib import Path
7
8 organization = "calculator.ubports"
9 application = "calculator.ubports"
10 old_application = "com.ubuntu.calculator_reboot"
11
12 xdg_data_home = Path(
13 os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share")
14 )
15 db_file = (
16 xdg_data_home / organization / "Databases" /
17 f"{hashlib.md5(application.encode()).hexdigest()}.sqlite"
18 )
19 old_db_file = (
20 db_file.parent /
21 f"{hashlib.md5(old_application.encode()).hexdigest()}.sqlite"
22 )
23
24 if old_db_file.with_suffix(".ini").is_file() and not db_file.exists():
25 with old_db_file.with_suffix(".ini").open() as old, \
26 db_file.with_suffix(".ini").open(mode="w+") as new:
27 for line in old:
28 if line.strip() == f"Name={old_application}":
29 line = f"Name={application}\n"
30 new.write(line)
31 old_db_file.with_suffix(".ini").unlink()
32 old_db_file.rename(db_file)
33
34 if len(sys.argv) > 1:
35 os.execvp(sys.argv[1], sys.argv[1:])