-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrqs
executable file
·226 lines (190 loc) · 9.34 KB
/
rqs
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
#!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 = 'rqs'
RQ_TYPE = 'source'
if __name__ == '__main__':
print '%s %s\n' % (RQ_PROG, rq.__version__)
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 (version, release, date)")
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('-p', '--patch', dest="patch", default=False, action="store_true",
help="List patched files when examining a src.rpm")
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('-s', '--skip-tar', dest="skiptar", default=False, action="store_true",
help="Skip tarfile extract when examining a src.rpm")
p.add_option('-S', '--source-only', dest="sourceonly", default=False, action="store_true",
help="Limit query to source files (no patches)")
p.add_option('-T', '--suppresstag', dest="suppresstag", default=False, action="store_true",
help="Suppress Tag and Path label output for queries")
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")
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('-f', '--file', dest="src_examine", metavar="FILE",
help="Examine a src.rpm FILE and output to stdout")
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('-q', '--query', dest="query", metavar="STRING",
help="Query database for substring match on files")
group.add_option('-b', '--buildreqs', dest="buildreqs", metavar="STRING",
help="Query database for substring match on BuildRequires")
group.add_option('-o', '--info', dest="showinfo", metavar="STRING",
help="Show all info on specified srpm")
group.add_option('-z', '--ctags', dest="ctags", metavar="STRING",
help="Query database for substring match on ctags data (functions, etc.)")
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.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)
rqs = rq.source.Source(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.listupdates:
if not options.tag:
logging.critical('The --list-updates option requires a tag entry!')
sys.exit(1)
rqs.list_updates(options.tag)
sys.exit(0)
if options.tag:
logging.debug('Tag:\t%s\n' % options.tag)
if options.tagdelete:
rtag.delete_entries(options.tagdelete)
sys.exit(0)
if options.query:
rqs.query('files')
sys.exit(0)
if options.ctags:
rqs.query('ctags')
sys.exit(0)
if options.buildreqs:
rqs.query('buildreqs')
sys.exit(0)
if options.showinfo:
rqs.showinfo()
sys.exit(0)
if options.src_examine:
rqs.examine(options.src_examine)
sys.exit(0)
if options.createpath:
createpath = os.path.abspath(options.createpath)
logging.debug('Dir:\t%s' % createpath)
if not options.tag:
print 'The --createpath option requires a tag entry!'
sys.exit(1)
if not options.updatepath:
logging.critical('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'
rqs.rpm_add_directory(options.tag, createpath, updatepath)
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(rqs, options.tagupdate)
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(rqs, options.tag, options.list_to_update)
sys.exit(0)
# if we get here, we have completely invalid arguments
p.print_help()
sys.exit(0)