-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAugmentCommandNotFoundDatabase
executable file
·98 lines (89 loc) · 3.12 KB
/
AugmentCommandNotFoundDatabase
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# AugmentCommandNotFoundDatabase - augments the existing database with data from this system
# Copyright (C) 2008 Michael Homer <=mwh>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import sys
import os
import os.path
from PythonUtils import getGoboVariable
goboPrograms = getGoboVariable('goboPrograms')
path = goboPrograms+'/Scripts/Current/Data/CommandNotFound.data'
commands = dict()
if os.path.exists(path) and os.path.getsize(path) > 0:
for entry in open(path).readlines():
entrydata = entry.split()
commands[entrydata[0]] = entrydata[1:]
def out(s):
sys.stdout.write(s)
def eout(s):
sys.stderr.write(s)
changes = 0
programs = os.listdir(goboPrograms)
for prog in programs:
# Skip various problematic entries: local or non-installable
# program entries, renames and case changes
if prog in ('LocalScripts', 'LiveCD', 'Installer', 'LibUngif', 'Koffice',
'ESP-GhostScript', 'Util-Linux', 'MonoDevelop', 'BusyBox'):
continue
# Cover both executable directories
for dtype in ('bin', 'sbin'):
# Not all programs have executables
try:
executables = os.listdir('%s/%s/Current/%s' %
(goboPrograms, prog, dtype))
for ex in executables:
if os.path.isdir('%s/%s/Current/%s/%s' %
(goboPrograms, prog, dtype, ex)):
continue
if ("." == ex[0] or "CVS" == ex or ex.endswith("~")
or ex.endswith('.bin') or ex.endswith(".bak")):
continue
if not ex in commands:
(base, sep, vers) = ex.rpartition('-')
# Short version: skip entries like zsh-4.3.5
if vers and vers.replace('.', '').isdigit():
continue
commands[ex] = []
eout("Adding executable %s\n" % (ex))
if not prog in commands[ex]:
commands[ex].append(prog)
changes += 1
eout("Adding program %s for executable %s\n" % (prog, ex))
except OSError:
pass
eout("Completed scan with %i change%s.\n" %
(changes, changes != 1 and 's' or ''))
if changes == 0:
eout("Nothing to do. No data saved.\n")
exit()
target = path
if len(sys.argv) > 1:
target = sys.argv[1]
try:
if '-' != target:
sys.stdout = open(target, 'w')
eout("Will save data to %s\n"%(target))
except IOError:
eout("No target supplied or target is not writable. "
"Will dump to stdout.\n")
eout("Use AugmentCommandNotFoundDatabase <target file> "
"to save to a file.\n")
eout("<target file> defaults to %s\n" % (path))
if sys.stdout.isatty():
eout("Press enter to continue...\n")
sys.stdin.readline()
# Output data in sorted order so it's deterministic and amenable to
# short diffs when maintained in SVN.
executables = sorted(commands.keys())
for ex in executables:
out(ex + ' ')
out(' '.join(sorted(commands[ex])))
out('\n')