Debian Codegraph @

mesonbuild/scripts/uninstall.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2016 The Meson development team
3
4 from __future__ import annotations
5
6 import os
7 import typing as T
8
9 logfile = 'meson-logs/install-log.txt'
10
11 def do_uninstall(log: str) -> None:
12 failures = 0
13 successes = 0
14 for line in open(log, encoding='utf-8'):
15 if line.startswith('#'):
16 continue
17 fname = line.strip()
18 try:
19 if os.path.isdir(fname) and not os.path.islink(fname):
20 os.rmdir(fname)
21 else:
22 os.unlink(fname)
23 print('Deleted:', fname)
24 successes += 1
25 except Exception as e:
26 print(f'Could not delete {fname}: {e}.')
27 failures += 1
28 print('\nUninstall finished.\n')
29 print('Deleted:', successes)
30 print('Failed:', failures)
31 print('\nRemember that files created by custom scripts have not been removed.')
32
33 def run(args: T.List[str]) -> int:
34 if args:
35 print('Weird error.')
36 return 1
37 if not os.path.exists(logfile):
38 print('Log file does not exist, no installation has been done.')
39 return 0
40 do_uninstall(logfile)
41 return 0