Debian Codegraph @

cnf-update-db

raw
1 #!/usr/bin/python3
2
3 import apt_pkg
4 import glob
5 import logging
6 import os
7 import sys
8
9 from CommandNotFound.db.creator import DbCreator
10 from CommandNotFound import CommandNotFound
11
12
13 if __name__ == "__main__":
14 if "--debug" in sys.argv[1:]:
15 logging.basicConfig(level=logging.DEBUG)
16 elif "--verbose" in sys.argv[1:]:
17 logging.basicConfig(level=logging.INFO)
18
19 apt_pkg.init_config()
20 db = CommandNotFound.dbpath
21 if not os.access(os.path.dirname(db), os.W_OK):
22 print("datbase directory %s not writable" % db)
23 sys.exit(0)
24
25 if apt_pkg.config.find_b("Acquire::IndexTargets::deb::CNF::DefaultEnabled", True):
26 command_files = glob.glob("/var/lib/apt/lists/*Commands-*")
27 else:
28 command_files = glob.glob("/var/lib/apt/lists/*Contents*")
29 if len(command_files) > 0:
30 umask = os.umask(0o22)
31 col = DbCreator(command_files)
32 col.create(db)
33 os.umask(umask)
34 else:
35 print("Could not find any command metadata")
36 print("Please run 'apt update' before using this command.")
37