-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrqp
executable file
·254 lines (215 loc) · 10.5 KB
/
rqp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!flask/bin/python
"""
This program extracts data from RPM and SRPM packages and stores it in
a database for later querying.
based on the srpm script of similar function copyright (c) 2005 Stew Benedict <[email protected]>
copyright (c) 2007-2017 Vincent Danen <[email protected]>
This file is part of rq.
rq 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 3 of the License, or
(at your option) any later version.
rq 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.
You should have received a copy of the GNU General Public License
along with rq. If not, see <http://www.gnu.org/licenses/>.
"""
import optparse
import sys
import logging
import rq
from app import *
RQ_PROG = 'rqp'
RQ_TYPE = 'binary'
if __name__ == '__main__':
print '%s %s\n' % (RQ_PROG, rq.__version__)
# TODO: add options to search files by ownership and sgid/suid status
p = optparse.OptionParser(description="RPM package query tool",
prog=RQ_PROG,
version="%prog " + rq.__version__,
usage="%prog [-h] [-v] [-c <directory>] [-[q|r|p|z] <substring>] [-t <tag>]")
p.add_option('-n', '--config', dest="conffile", metavar="FILE",
help="Optional configuration file")
p.add_option('-c', '--count', dest="count", default=False, action="store_true",
help="Only output the count of query matches")
p.add_option('-d', '--debug', dest="debug", default=False, action="store_true",
help="Enable debugging output")
p.add_option('-e', '--extrainfo', dest="extrainfo", default=False, action="store_true",
help="Show extra info such as file flags on binary files (NX, RELRO, etc.)")
p.add_option('-g', '--regexp', dest="regexp", default=False, action="store_true",
help="Query string is a regular expression")
p.add_option('-l', '--list', dest="list", default=False, action="store_true",
help="List database tags")
p.add_option('-o', '--ownership', dest="ownership", default=False, action="store_true",
help="Display ownership information on files")
p.add_option('-P', '--progress', dest="progress", default=False, action="store_true",
help="Show processing progress")
p.add_option('-Q', '--quiet', dest="quiet", default=False, action="store_true",
help="Quiet query - show tag and package name only (or numeric count only)")
p.add_option('-T', '--suppresstag', dest="suppresstag", default=False, action="store_true",
help="Suppress Tag and Path label output for queries")
# above was only in rqs -- why?
p.add_option('-x', '--statistics', dest="stats", default=False, action="store_true",
help="Show database statistics")
p.add_option('-v', '--verbose', dest="verbose", default=False, action="store_true",
help="Verbose output")
p.add_option('', '--list-updates', dest="listupdates", default=False, action="store_true",
help="List all updated packages for tag")
p.add_option('', '--list-to-update', dest="list_to_update", default=False, action="store_true",
help="List all packages scheduled for update by tag")
p.add_option('', '--show-current', dest="show_current", default=False, action="store_true",
help="Show current package version/release information from database")
p.add_option('', '--show-suid', dest="showsuid", default=False, action="store_true",
help="List all setuid files for tag")
p.add_option('', '--show-sgid', dest="showsgid", default=False, action="store_true",
help="List all setgid files for tag")
dbgroup = optparse.OptionGroup(p, "Database Options")
dbgroup.add_option('-C', '--createpath', dest="createpath", metavar="DIR",
help="Create database entries with TAG from a " + RQ_TYPE + " rpm DIR")
dbgroup.add_option('-U', '--updatepath', dest="updatepath", metavar="DIR",
help="Assign update path for this tag")
dbgroup.add_option('-D', '--delete', dest="tagdelete", metavar="TAG",
help="Delete all TAG entries")
dbgroup.add_option('-t', '--tag', dest="tag", metavar="TAG",
help="TAG for created database entries or database queries")
dbgroup.add_option('-u', '--update', dest="tagupdate", metavar="TAG",
help="Update TAG entries (new/removed files in directory)")
p.add_option_group(dbgroup)
group = optparse.OptionGroup(p, "Query Options")
group.add_option('-p', '--provides', dest="provides", metavar="STRING",
help="Query database for substring match on provides")
group.add_option('-q', '--query', dest="query", metavar="STRING",
help="Query database for substring match on files, or packages when used with --show-current")
group.add_option('-r', '--requires', dest="requires", metavar="STRING",
help="Query database for substring match on requires")
group.add_option('-z', '--symbols', dest="symbols", metavar="STRING",
help="Query database for substring match on symbols in binary files")
p.add_option_group(group)
# 'arguments' is a tuple of non-optioned things
(options, arguments) = p.parse_args()
if len(sys.argv) == 1: # no arguments passed
p.print_help()
sys.exit(0)
# setup the options
if options.provides and options.query:
p.error("--provides and --query are mutually exclusive")
if options.provides and options.requires:
p.error("--provides and --requires are mutually exclusive")
if options.query and options.requires:
p.error("--query and --provides are mutually exclusive")
if options.provides and options.query and options.requires:
p.error("--query, --provides, and --requires are mutually exclusive")
if options.verbose and options.quiet:
p.error("--quiet and --verbose are mutually exclusive")
if options.tag and options.tagdelete:
p.error("--tag and --delete are mutually exclusive; you do not need to use --tag")
# setup logging facilities
LOGFILE = '%s/%s.log' % (os.getcwd(), RQ_PROG)
LEVELS = {'debug' : logging.DEBUG,
'info' : logging.INFO,
'warning': logging.WARNING}
FILELEVEL = LEVELS.get('info', logging.NOTSET)
CONSLEVEL = LEVELS.get('warning', logging.NOTSET)
FILEFMT = '%(asctime)s %(message)s'
if options.debug:
FILELEVEL = LEVELS.get('debug', logging.NOTSET)
CONSLEVEL = LEVELS.get('debug', logging.NOTSET)
FILEFMT = '%(asctime)s %(filename)s(%(funcName)s[%(lineno)d]): %(levelname)s: %(message)s'
if options.verbose:
FILELEVEL = LEVELS.get('info', logging.NOTSET)
CONSLEVEL = LEVELS.get('info', logging.NOTSET)
FILEFMT = '%(asctime)s %(message)s'
logging.basicConfig(level=FILELEVEL,
format=FILEFMT,
datefmt='%b %d %H:%M:%S',
filename=LOGFILE,
filemode='a')
console = logging.StreamHandler()
console.setLevel(CONSLEVEL)
CONSFMT = logging.Formatter('%(message)s')
console.setFormatter(CONSFMT)
logging.getLogger('').addHandler(console)
logging.debug("%s starting, debug mode enabled; type => %s" % (RQ_PROG, RQ_TYPE))
config = rq.basics.Config(options.conffile)
rcommon = rq.basics.Common(options, RQ_TYPE)
rtag = rq.tag.Tag(RQ_TYPE, config, rcommon, options)
rqp = rq.binary.Binary(config, options, rtag, rcommon)
# start doing useful things
if options.list:
rtag.list()
if options.stats:
if options.tag:
rtag.showdbstats(options.tag)
else:
rtag.showdbstats()
if options.tag:
logging.debug('Tag:\t%s\n' % options.tag)
if options.listupdates:
if not options.tag:
logging.critical('The --list-updates option requires a tag entry!')
sys.exit(1)
rqp.list_updates(options.tag)
sys.exit(0)
if options.showsuid:
if not options.tag:
logging.critical('The --show-suid option requires a tag entry!')
sys.exit(1)
rqp.show_sxid('suid', options.tag)
sys.exit(0)
if options.showsgid:
if not options.tag:
logging.critical('The --show-sgid option requires a tag entry!')
sys.exit(1)
rqp.show_sxid('sgid', options.tag)
sys.exit(0)
if options.tagdelete:
rtag.delete_entries(options.tagdelete)
sys.exit(0)
if options.tagupdate:
if options.list_to_update:
logging.critical('The --list-to-update option cannot be used with -u, use -t instead!')
sys.exit(1)
rtag.update_entries(rqp, options.tagupdate)
sys.exit(0)
if options.query:
if options.show_current:
rqp.query('packages')
else:
rqp.query('files')
sys.exit(0)
if options.show_current:
logging.critical('The --show-current option is only used with -q!')
print ''
if options.provides:
rqp.query('provides')
sys.exit(0)
if options.requires:
rqp.query('requires')
sys.exit(0)
if options.symbols:
rqp.query('symbols')
sys.exit(0)
if options.createpath:
createpath = os.path.abspath(options.createpath)
logging.debug('Dir:\t%s' % createpath)
if not options.tag:
print 'The --create option requires a tag entry!'
sys.exit(1)
if not options.updatepath:
print 'The --createpath option also requires the use of --updatepath!'
sys.exit(1)
updatepath = os.path.abspath(options.updatepath)
print 'Searching for rpms to import...\n'
rqp.rpm_add_directory(options.tag, createpath, updatepath)
sys.exit(0)
if options.list_to_update:
if not options.tag:
logging.critical('The --list-to-update option requires a tag entry!')
sys.exit(1)
rtag.update_entries(rqp, options.tag, options.list_to_update)
sys.exit(0)
# if we get here, we have completely invalid arguments
p.print_help()
sys.exit(0)