Skip to content
Navigation Menu
{{ message }}
forked from python-bugzilla/python-bugzilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbugzilla
More file actions
executable file
·1359 lines (1159 loc) · 50.3 KB
/
Copy pathbugzilla
File metadata and controls
executable file
·1359 lines (1159 loc) · 50.3 KB
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python -tt
#
# bugzilla - a commandline frontend for the python bugzilla module
#
# Copyright (C) 2007, 2008, 2009, 2010, 2011 Red Hat Inc.
# Author: Will Woods <wwoods@redhat.com>
#
# 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. See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.
from __future__ import print_function
import locale
from logging import DEBUG, INFO, WARN, StreamHandler, Formatter
import optparse
import os
import re
import socket
import sys
import tempfile
if hasattr(sys.version_info, "major") and sys.version_info.major >= 3:
# pylint: disable=F0401,W0622
from xmlrpc.client import Fault, ProtocolError
basestring = (str, bytes)
else:
from xmlrpclib import Fault, ProtocolError
import requests.exceptions
import bugzilla
default_bz = 'https://bugzilla.redhat.com/xmlrpc.cgi'
_is_unittest = bool(os.getenv("__BUGZILLA_UNITTEST"))
cmdlist = ['login', 'new', 'query', 'modify', 'attach', 'info']
format_field_re = re.compile("%{([a-z0-9_]+)(?::([^}]*))?}")
log = bugzilla.log
handler = StreamHandler(sys.stderr)
handler.setFormatter(Formatter(
"[%(asctime)s] %(levelname)s (%(module)s:%(lineno)d) %(message)s",
"%H:%M:%S"))
log.addHandler(handler)
################
# Util helpers #
################
def to_encoding(ustring):
string = ''
if isinstance(ustring, basestring):
string = ustring
elif ustring is not None:
string = str(ustring)
if hasattr(sys.version_info, "major") and sys.version_info.major >= 3:
return string
preferred = locale.getpreferredencoding()
if _is_unittest:
preferred = "UTF-8"
return string.encode(preferred, 'replace')
def open_without_clobber(name, *args):
'''Try to open the given file with the given mode; if that filename exists,
try "name.1", "name.2", etc. until we find an unused filename.'''
fd = None
count = 1
orig_name = name
while fd is None:
try:
fd = os.open(name, os.O_CREAT | os.O_EXCL, 0o666)
except OSError:
err = sys.exc_info()[1]
if err.errno == os.errno.EEXIST:
name = "%s.%i" % (orig_name, count)
count += 1
else:
raise IOError(err.errno, err.strerror, err.filename)
fobj = open(name, *args)
if fd != fobj.fileno():
os.close(fd)
return fobj
##################
# Option parsing #
##################
def setup_parser():
u = ("%%prog [global options] COMMAND [command-options]"
"\n\nCommands: %s" % ', '.join(sorted(cmdlist)))
p = optparse.OptionParser(usage=u, version=bugzilla.__version__)
p.disable_interspersed_args()
p.epilog = 'Try "bugzilla COMMAND --help" for command-specific help.'
# General bugzilla connection options
p.add_option('--bugzilla', default=default_bz,
help="bugzilla XMLRPC URI. default: %s" % default_bz)
p.add_option("--nosslverify", dest="sslverify",
action="store_false", default=True,
help="Don't error on invalid bugzilla SSL certificate")
p.add_option('--login', action="store_true",
help='Run interactive "login" before performing the '
'specified command.')
p.add_option('--username', help="Log in with this username")
p.add_option('--password', help="Log in with this password")
p.add_option('--ensure-logged-in', action="store_true",
help="Raise an error if we aren't logged in to bugzilla. "
"Consider using this if you are depending on "
"cached credentials, to ensure that when they expire the "
"tool errors, rather than subtly change output.")
p.add_option('--no-cache-credentials',
action='store_false', default=True, dest='cache_credentials',
help="Don't save any bugzilla cookies or tokens to disk, and "
"don't use any pre-existing credentials.")
p.add_option('--cookiefile', default=None,
help="cookie file to use for bugzilla authentication")
p.add_option('--tokenfile', default=None,
help="token file to use for bugzilla authentication")
p.add_option('--verbose', action='store_true',
help="give more info about what's going on")
p.add_option('--debug', action='store_true',
help="output bunches of debugging info")
# Generate the man page, dump to stdout. Not for end users
p.add_option('--generate-man', action='store_true',
help=optparse.SUPPRESS_HELP)
# Allow user to specify BZClass to initialize. Kinda weird for the
# CLI, I'd rather people file bugs about this so we can fix our detection.
# So hide it from the help output but keep it for back compat
p.add_option('--bztype', default='auto', help=optparse.SUPPRESS_HELP)
return p
def setup_action_parser(action):
p = optparse.OptionParser(usage="%%prog %s [options]" % action)
if action == 'new':
p.set_description("Create a new bug report.")
p.add_option('-p', '--product', help="REQUIRED: product name")
p.add_option('-v', '--version', help="REQUIRED: product version")
p.add_option('-c', '--component', help="REQUIRED: component name")
p.add_option("--sub-component", help="Optional sub component name")
p.add_option('-s', '--short_desc', '--summary', dest='summary',
help="REQUIRED: bug summary")
p.add_option('-l', '--comment', dest='description',
help="initial bug comment")
p.add_option('-o', '--os', help="Operating system")
p.add_option('-a', '--arch', help="Arch this bug occurs on")
p.add_option('--severity', help="Bug severity")
p.add_option('--priority', help="Bug priority")
p.add_option('-u', '--url', help="URL for further bug info")
p.add_option('--cc',
metavar='CC[, CC, ...]', action="append",
help="add emails to initial CC list")
p.add_option('--blocked',
metavar='BUGID[, BUGID, ...]', action="append",
help="add bug_ids blocked by this bug")
p.add_option('--dependson',
metavar='BUGID[, BUGID, ...]', action="append",
help="add bug_ids that this bug depends on")
p.add_option('--groups',
metavar='GROUP[, GROUP, ...]', action="append",
help="add groups to which bug is visible")
p.add_option('--assigned_to',
help='Assign bugzilla to specified email address')
p.add_option('--qa_contact',
help='Set QA contact to specified email address')
p.add_option('--keywords',
metavar='KEYWORD[, KEYWORD, ...]', action="append",
help="Set specified keywords on new bugzilla")
p.add_option('--alias',
help='An alias (name) for the bug (must be unique)')
elif action == 'query':
p.set_description("List bug reports that match the given criteria.")
# General bug metadata
p.add_option('-b', '--bug_id', default=None,
help="specify individual bugs by IDs, separated with commas")
p.add_option('-p', '--product',
help="product name, comma-separated "
"(list with 'bugzilla info --products')")
p.add_option('-v', '--version',
help="product version, comma-separated")
p.add_option('-c', '--component',
help="component name(s), comma-separated "
"(list with 'bugzilla info --components PRODUCT')")
p.add_option("--sub-component", action="append",
help="Sub component. Can be specified multiple times")
p.add_option('--components_file', default=None,
help="list of component names from a file, one component "
"per line (list with 'bugzilla info -c PRODUCT')")
p.add_option('-l', '--long_desc',
help="search inside bug comments")
p.add_option('-m', '--target_milestone',
help="search for a target milestone")
p.add_option('-s', '--short_desc',
help="search bug summaries")
p.add_option('-t', '--bug_status', default="ALL",
help="comma-separated list of bug statuses to accept "
"[Default:all]")
p.add_option('-x', '--bug_severity', '--severity',
help="search severities, comma-separated")
p.add_option('-z', '--priority',
help="search priorities, comma-separated")
# Email
malg = optparse.OptionGroup(p, "Email Options")
malg.add_option('-E', '--emailtype', default="substring",
help="Email: specify searching option for emails, "
"ie. substring, notsubstring, exact, ... "
"[Default: substring]")
malg.add_option('-o', '--cc',
help="Email: search cc lists for given address")
malg.add_option('-r', '--reporter',
help="Email: search reporter email for given address")
malg.add_option('-a', '--assigned_to',
help="Email: search for bugs assigned to this address")
malg.add_option('-q', '--qa_contact',
help="Email: search for bugs which have QA Contact "
"assigned to this address")
p.add_option_group(malg)
# Strings
stro = optparse.OptionGroup(p, "String search options")
stro.add_option('-u', '--url',
help="search keywords field for given url")
stro.add_option('-U', '--url_type',
help="specify searching option for urls, "
"ie. anywords, allwords, nowords")
stro.add_option('-k', '--keywords',
help="search keywords field for specified words")
stro.add_option('-K', '--keywords_type',
help="specify searching option for keywords, "
"ie. anywords, allwords, nowords")
stro.add_option('-w', '--status_whiteboard',
help="search Status Whiteboard field for specified words")
stro.add_option('-W', '--status_whiteboard_type',
help="specify searching option for Status Whiteboard, "
"ie. anywords, allwords, nowords")
stro.add_option("--tags", help="Search bug 'tags' field")
p.add_option_group(stro)
# Precomposed queries
p.add_option('--from-url',
help="Use the query given by a query.cgi URL. (Use quotes!)")
p.add_option('--quicksearch',
help="Search using bugzilla's quicksearch functionality.")
p.add_option('--savedsearch',
help="Name of a bugzilla saved search. If you don't own this "
"saved search, you must passed --savedsearch_sharer_id.")
p.add_option('--savedsearch-sharer-id',
help="Owner ID of the --savedsearch. You can get this ID from "
"the URL bugzilla generates when running the saved search "
"from the web UI.")
# Boolean Charts
bgrp = optparse.OptionGroup(p, "Boolean options")
bgrp.add_option('-B', '--booleantype', default="substring",
help="specify searching option for booleans, ie. substring, "
"notsubstring, exact, ... [Default: substring]")
bgrp.add_option('--boolean_query', action="append",
help="Create your own query. Format: "
"BooleanName-Condition-Parameter &/| ... . ie, "
"keywords-substring-Partner & "
"keywords-notsubstring-OtherQA")
bgrp.add_option('--blocked', action="append",
help="Search for bugs that block this bug ID")
bgrp.add_option('--dependson', action="append",
help="Search for bugs that depend on this bug ID")
bgrp.add_option('--flag', action='append',
help="Search for bugs that have certain "
"flag states present. Ex --flags=dev_ack+")
bgrp.add_option('--qa_whiteboard', action="append",
help="search for bugs that have certain QA "
"Whiteboard text present")
bgrp.add_option('--devel_whiteboard', action="append",
help="search for bugs that have certain "
"Devel Whiteboard text present")
bgrp.add_option('--alias', action="append",
help="search for bugs that have the provided alias")
bgrp.add_option('--fixed_in', action="append",
help="search Status Whiteboard field for specified words")
p.add_option_group(bgrp)
elif action == 'info':
p.set_description("Get information about the bugzilla server.")
p.add_option('-p', '--products', action='store_true',
help='Get a list of products')
p.add_option('-c', '--components', metavar="PRODUCT",
help='List the components in the given product')
p.add_option('-o', '--component_owners', metavar="PRODUCT",
help='List components (and their owners)')
p.add_option('-v', '--versions', metavar="VERSION",
help='List the versions for the given product')
elif action == 'modify':
p.set_usage("%prog modify [options] BUGID [BUGID...]")
p.set_description("Modify one or more bugs.")
bgrp = optparse.OptionGroup(p, "Bug details")
bgrp.add_option('--product',
help="Reassign bug to different product")
bgrp.add_option('-c', '--component',
help="Reassign bug to different component")
bgrp.add_option("--sub-component",
help="Reassign bug to different sub-component (rhbz extension)")
bgrp.add_option("-v", '--version',
help="Reassign bug to different version")
bgrp.add_option('-o', '--os',
help="Change operating system this bug occurs on")
bgrp.add_option('-a', '--arch',
help="Change arch this bug occurs on")
bgrp.add_option('-u', '--url',
help="URL for further bug info")
bgrp.add_option('--alias',
help='An alias (name) for the bug (must be unique)')
p.add_option_group(bgrp)
sgrp = optparse.OptionGroup(p, "Bug status options")
sgrp.add_option('-s', '--status',
help='Change status of bug')
sgrp.add_option('-k', '--close', metavar="RESOLUTION",
help='Close with the given resolution')
sgrp.add_option('-d', '--dupeid', metavar="ORIGINAL",
help='ID of original bug (implies -k DUPLICATE)')
sgrp.add_option('-F', '--fixed_in', metavar="VERSION",
help='"Fixed in version" field')
p.add_option_group(sgrp)
cgrp = optparse.OptionGroup(p, "Comment options")
cgrp.add_option('-l', '--comment',
help='Add a comment')
cgrp.add_option('-p', '--private', action='store_true', default=False,
help='Mark new comment as private')
cgrp.add_option("--summary", help="Change bug summary")
p.add_option_group(cgrp)
egrp = optparse.OptionGroup(p, "Contact options")
egrp.add_option('--assignee',
help='Assign bugzilla to assignee')
egrp.add_option('--cc', action='append', metavar="EMAIL",
help='Alter CC list. EMAIL appends, -EMAIL removes.')
egrp.add_option('--qa_contact',
help='Change QA contact')
egrp.add_option('--reset-assignee', action="store_true",
help='Reset assignee to component default')
egrp.add_option('--reset-qa-contact', action="store_true",
help='Reset QA contact to component default')
egrp.add_option('--groups', metavar='GROUP[, GROUP, ...]',
action="append",
help="add groups to which bug is visible")
p.add_option_group(egrp)
tgrp = optparse.OptionGroup(p, "Tracking options")
tgrp.add_option('-f', '--flag', action='append',
help='Update bugzilla flags with requested type, '
'ie fedora-cvs?, or needinfoX to clear '
'(Use a new option for each flag)')
tgrp.add_option('--severity', help="Change bug severity")
tgrp.add_option('--priority', help="Change bug priority")
tgrp.add_option('--target_milestone', help="Set target milestone")
tgrp.add_option('--target_release', help="Set target release")
tgrp.add_option('--blocked',
metavar='BUGID[, BUGID, ...]', action="append",
help="Add bug_ids blocked by this bug. BUGID appends, "
"-BUGID removes, =BUGID overwrites")
tgrp.add_option('--dependson', metavar='BUGID[, BUGID, ...]',
action="append",
help=('Alter depends_on list. BUGID appends, '
'-BUGID removes, =BUGID overwrites'))
tgrp.add_option('--keywords',
metavar='KEYWORD', action="append",
help="Alter bug keywords list. KEYWORD appends, "
"-KEYWORD removes, =KEYWORD overwrites")
tgrp.add_option("", "--whiteboard", metavar="TEXT", action="append",
help='Alter status whiteboard text. '
'TEXT appends, -TEXT removes, =TEXT overwrites')
tgrp.add_option("--devel_whiteboard",
metavar="TEXT", action="append",
help='Alter devel whiteboard text. '
'TEXT appends, -TEXT removes, =TEXT overwrites')
tgrp.add_option("--internal_whiteboard",
metavar="TEXT", action="append",
help='Alter internal whiteboard text. '
'TEXT appends, -TEXT removes, =TEXT overwrites')
tgrp.add_option("--qa_whiteboard",
metavar="TEXT", action="append",
help='Alter QA whiteboard. '
'TEXT appends, -TEXT removes, =TEXT overwrites')
tgrp.add_option("--tags", metavar="TEXT", action="append",
help="Alter bug 'tags' field"
"TEXT appends, -TEXT removes")
p.add_option_group(tgrp)
elif action == 'attach':
p.set_usage('''
%prog attach --file=FILE --desc=DESC [--type=TYPE] BUGID [BUGID...]
%prog attach --get=ATTACHID --getall=BUGID [...]
%prog attach --type=TYPE BUGID [BUGID...]''')
p.set_description("Attach files or download attachments.")
p.add_option('-f', '--file', metavar="FILENAME",
help='File to attach, or filename for data provided on stdin')
p.add_option('-d', '--description', metavar="DESCRIPTION", dest='desc',
help="A short description of the file being attached")
p.add_option('-t', '--type', metavar="MIMETYPE",
help="Mime-type for the file being attached")
p.add_option('-g', '--get', metavar="ATTACHID", action="append",
default=[], help="Download the attachment with the given ID")
p.add_option("--getall", "--get-all", metavar="BUGID", action="append",
default=[], help="Download all attachments on the given bug")
elif action == 'login':
p.set_usage('%prog login [username [password]]')
p.set_description(
"Log into bugzilla and save a login cookie or token.")
if action in ['new', 'query']:
outg = optparse.OptionGroup(p, "Output format options")
outg.add_option('-f', '--full', action='store_const', dest='output',
const='full', default='normal',
help="output detailed bug info")
outg.add_option('-i', '--ids', action='store_const', dest='output',
const='ids', help="output only bug IDs")
outg.add_option('-e', '--extra', action='store_const',
dest='output', const='extra',
help="output additional bug information "
"(keywords, Whiteboards, etc.)")
outg.add_option('--oneline', action='store_const', dest='output',
const='oneline',
help="one line summary of the bug (useful for scripts)")
outg.add_option('--raw', action='store_const', dest='output',
const='raw', help="raw output of the bugzilla contents")
outg.add_option('--outputformat',
help="Print output in the form given. "
"You can use RPM-style tags that match bug "
"fields, e.g.: '%{id}: %{summary}'. See the man page "
"section 'OUTPUT FORMAT' for more details.")
p.add_option_group(outg)
if action in ['new', 'query', 'modify']:
message = {
'new': 'Set a specified field.',
'query': 'Query a specified field.',
'modify': 'Modify a specified field.'
}.get(action)
p.add_option('--field', help="%s FIELD is expected to be \
the raw name used by the bugzilla instance. No safety \
checks are perfomed when using this option." % (message),
action="append", type="str", dest="fields",
metavar="FIELD=VALUE")
# Used by unit tests, not for end user consumption
if action in ['new', 'query', 'modify']:
p.add_option('--test-return-result', action="store_true",
help=optparse.SUPPRESS_HELP)
return p
####################
# Command routines #
####################
def generate_man_page():
from logilab.common.optik_ext import ManHelpFormatter
import datetime
today = datetime.date.today()
datestr = today.strftime("%B %d, %Y")
# pylint: disable=W1401
# Anomalous backslash in string, man format confuses pylint
manpage = \
'''.TH bugzilla 1 "%s" "version %s" "User Commands"
.SH NAME
bugzilla \- command-line interface to Bugzilla over XML-RPC
.SH SYNOPSIS
.B bugzilla
[\\fIoptions\\fR] [\\fIcommand\\fR] [\\fIcommand-options\\fR]
.SH DESCRIPTION
.PP
.BR bugzilla
is a command-line utility that allows access to the XML-RPC interface provided
by Bugzilla.
.PP
\\fIcommand\\fP is one of:
.br
.I \\fR * login - log into the given bugzilla instance
.br
.I \\fR * new - create a new bug
.br
.I \\fR * query - search for bugs matching given criteria
.br
.I \\fR * modify - modify existing bugs
.br
.I \\fR * attach - attach files to existing bugs, or get attachments
.br
.I \\fR * info - get info about the given bugzilla instance
''' % (datestr, bugzilla.__version__)
manformatter = ManHelpFormatter()
parser = setup_parser()
parser.formatter = manformatter
opt_section = parser.format_option_help()
manpage += opt_section.replace("OPTIONS", "GLOBAL OPTIONS")
for action in cmdlist:
action_parser = setup_action_parser(action)
action_parser.remove_option("--help")
action_parser.formatter = manformatter
opt_section = action_parser.format_option_help()
manpage += opt_section.replace("OPTIONS",
'\[oq]%s\[cq] OPTIONS' % action.upper())
manpage += \
'''.SH OUTPUT FORMAT
The output of the bugzilla tool should NEVER BE PARSED unless you are using a
custom --outputformat. For everything else, just don't parse it, the formats
are not stable and are subject to change.
--outputformat allows printing arbitrary bug data in a user preferred format.
For example, to print a returned bug ID, component, and product, separated
with ::, do:
--outputformat "%{id}::%{component}::%{product}"
The fields (like 'id', 'component', etc.) are the names of the values returned
by bugzilla's XMLRPC interface. To see a list of all fields, check the API
documentation in the 'SEE ALSO' section. Alternatively, run a 'bugzilla
--debug query ...' and look at the key names returned in the query results.
Also, in most cases, using the name of the associated command line switch
should work, like --bug_status becomes %{bug_status}, etc.
.SH AUTHENTICATION COOKIES AND TOKENS
Older bugzilla instances use cookie-based authentication, and
bugzilla.redhat.com uses a non-cookie token system.
When you log into bugzilla with the "login" subcommand or the "--login"
argument, we cache the cookie in ~/.bugzillacookies. If you are using
bugzilla.redhat.com, we also cache the token in ~/.bugzillatoken.
To perform an authenticated bugzilla command on a new machine, run a one time
"bugzilla login" to cache credentials before running the desired command. You
can also run "bugzilla --login" and the login process will be initiated before
invoking the command.
Additionally, the --no-cache-credentials option will tell the bugzilla tool to
_not_ save any credentials to ~/.bugzillacookies or ~/.bugzillatoken.
.SH EXAMPLES
.PP
.RS 0
bugzilla query --bug_id 62037
bugzilla query --version 15 --component python-bugzilla
# All boolean options can be formatted like this
.br
bugzilla query --blocked "123456 | 224466"
bugzilla login
bugzilla new -p Fedora -v rawhide -c python-bugzilla \\\\
--summary "python-bugzilla causes headaches" \\\\
--comment "python-bugzilla made my brain hurt when I used it."
bugzilla attach --file ~/Pictures/cam1.jpg --desc "me, in pain" $BUGID
bugzilla attach --getall $BUGID
bugzilla modify --close NOTABUG --comment "Actually, you're hungover." $BUGID
.SH EXIT STATUS
.BR bugzilla
normally returns 0 if the requested command was successful.
Otherwise, exit status is 1 if
.BR bugzilla
is interrupted by the user (or a login attempt fails), 2 if a
socket error occurs (e.g. TCP connection timeout), and 3 if the server returns
an XML-RPC fault.
.SH BUGS
Please report any bugs as github issues at
.br
https://github.com/python-bugzilla/python-bugzilla
.br
to the mailing list at
.br
https://fedorahosted.org/mailman/listinfo/python-bugzilla
.SH SEE ALSO
.nf
http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html
https://bugzilla.redhat.com/docs/en/html/api/Bugzilla/WebService/Bug.html'''
print(manpage)
def _merge_field_opts(query, opt, parser):
# Add any custom fields if specified
if opt.fields is None:
return
for f in opt.fields:
try:
f, v = f.split('=', 1)
query[f] = v
except:
parser.error("Invalid field argument provided: %s" % (f))
def _do_query(bz, opt, parser):
# Construct the query from the list of queryable options
q = dict()
# Parse preconstructed queries.
u = getattr(opt, 'from_url', None)
if u:
q = bz.url_to_query(u)
if opt.components_file:
# Components slurped in from file (one component per line)
# This can be made more robust
clist = []
f = open(opt.components_file, 'r')
for line in f.readlines():
line = line.rstrip("\n")
clist.append(line)
opt.component = clist
if opt.bug_status:
val = opt.bug_status
stat = val
if val == 'ALL':
# leaving this out should return bugs of any status
stat = None
elif val == 'DEV':
# Alias for all development bug statuses
stat = ['NEW', 'ASSIGNED', 'NEEDINFO', 'ON_DEV',
'MODIFIED', 'POST', 'REOPENED']
elif val == 'QE':
# Alias for all QE relevant bug statuses
stat = ['ASSIGNED', 'ON_QA', 'FAILS_QA', 'PASSES_QA']
elif val == 'EOL':
# Alias for EndOfLife bug statuses
stat = ['VERIFIED', 'RELEASE_PENDING', 'CLOSED']
elif val == 'OPEN':
# non-Closed statuses
stat = ['NEW', 'ASSIGNED', 'MODIFIED', 'ON_DEV', 'ON_QA',
'VERIFIED', 'RELEASE_PENDING', 'POST']
opt.bug_status = stat
# Convert all comma separated list parameters to actual lists,
# which is what bugzilla wants
# According to bugzilla docs, any parameter can be a list, but
# let's only do this for options we explicitly mention can be
# comma separated.
for optname in ["bug_severity", "bug_id", "bug_status", "component",
"priority", "product", "version"]:
val = getattr(opt, optname, None)
if not isinstance(val, str):
continue
setattr(opt, optname, val.split(","))
include_fields = None
if opt.output == 'raw':
# 'raw' always does a getbug() call anyways, so just ask for ID back
include_fields = ['id']
elif opt.outputformat:
include_fields = []
for fieldname, rest in format_field_re.findall(opt.outputformat):
if fieldname == "whiteboard" and rest:
fieldname = rest + "_" + fieldname
elif fieldname == "flag":
fieldname = "flags"
elif fieldname == "cve":
fieldname = ["keywords", "blocks"]
elif fieldname == "__unicode__":
# Needs to be in sync with bug.__unicode__
fieldname = ["id", "status", "assigned_to", "summary"]
flist = isinstance(fieldname, list) and fieldname or [fieldname]
for f in flist:
if f not in include_fields:
include_fields.append(f)
if include_fields is not None:
include_fields.sort()
built_query = bz.build_query(
product=getattr(opt, "product", None),
component=getattr(opt, "component", None),
sub_component=getattr(opt, "sub_component", None),
version=getattr(opt, "version", None),
reporter=getattr(opt, "reporter", None),
bug_id=getattr(opt, "bug_id", None),
short_desc=getattr(opt, "short_desc", None),
long_desc=getattr(opt, "long_desc", None),
cc=getattr(opt, "cc", None),
assigned_to=getattr(opt, "assigned_to", None),
qa_contact=getattr(opt, "qa_contact", None),
status=getattr(opt, "bug_status", None),
blocked=getattr(opt, "blocked", None),
dependson=getattr(opt, "dependson", None),
keywords=getattr(opt, "keywords", None),
keywords_type=getattr(opt, "keywords_type", None),
url=getattr(opt, "url", None),
url_type=getattr(opt, "url_type", None),
status_whiteboard=getattr(opt, "status_whiteboard", None),
status_whiteboard_type=getattr(opt, "status_whiteboard_type", None),
fixed_in=getattr(opt, "fixed_in", None),
fixed_in_type=getattr(opt, "fixed_in_type", None),
flag=getattr(opt, "flag", None),
alias=getattr(opt, "alias", None),
qa_whiteboard=getattr(opt, "qa_whiteboard", None),
devel_whiteboard=getattr(opt, "devel_whiteboard", None),
boolean_query=getattr(opt, "boolean_query", None),
bug_severity=getattr(opt, "bug_severity", None),
priority=getattr(opt, "priority", None),
target_milestone=getattr(opt, "target_milestone", None),
emailtype=opt.emailtype,
booleantype=opt.booleantype,
include_fields=include_fields,
quicksearch=getattr(opt, "quicksearch", None),
savedsearch=getattr(opt, "savedsearch", None),
savedsearch_sharer_id=getattr(opt, "savedsearch_sharer_id", None),
tags=getattr(opt, "tags", None))
_merge_field_opts(built_query, opt, parser)
built_query.update(q)
q = built_query
if not q:
parser.error("'query' command requires additional arguments")
if opt.test_return_result:
return q
return bz.query(q)
def _do_info(bz, opt):
"""
Handle the 'info' subcommand
"""
# All these commands call getproducts internally, so do it up front
# with minimal include_fields for speed
include_fields = ["name", "id"]
if opt.versions:
include_fields.append("versions")
products = bz.getproducts(include_fields=include_fields)
if opt.products:
for name in sorted([p["name"] for p in products]):
print(name)
if opt.components:
for name in sorted(bz.getcomponents(opt.components)):
print(name)
if opt.component_owners:
# Looking up this info for rhbz 'Fedora' product is sloooow
# since there are so many components. So delay getting this
# info until as late as possible
bz.refresh_products(names=[opt.component_owners],
include_fields=include_fields + [
"components.default_assigned_to",
"components.default_qa_contact",
"components.name",
"components.description"])
component_details = bz.getcomponentsdetails(opt.component_owners)
for c in sorted(component_details):
print(to_encoding(u"%s: %s" %
(c, component_details[c]['initialowner'])))
if opt.versions:
for p in products:
if p['name'] != opt.versions:
continue
if "versions" in p:
for v in p['versions']:
print(to_encoding(v["name"]))
break
def _convert_to_outputformat(output):
fmt = ""
if output == "normal":
fmt = "%{__unicode__}"
elif output == "ids":
fmt = "%{id}"
elif output == 'full':
fmt += "%{__unicode__}\n"
fmt += "Component: %{component}\n"
fmt += "CC: %{cc}\n"
fmt += "Blocked: %{blocks}\n"
fmt += "Depends: %{depends_on}\n"
fmt += "%{comments}\n"
elif output == 'extra':
fmt += "%{__unicode__}\n"
fmt += " +Keywords: %{keywords}\n"
fmt += " +QA Whiteboard: %{qa_whiteboard}\n"
fmt += " +Status Whiteboard: %{status_whiteboard}\n"
fmt += " +Devel Whiteboard: %{devel_whiteboard}\n"
elif output == 'oneline':
fmt += "#%{bug_id} %{status} %{assigned_to} %{component}\t"
fmt += "[%{target_milestone}] %{flags} %{cve}"
else:
raise RuntimeError("Unknown output type '%s'" % output)
return fmt
def _format_output(bz, opt, buglist):
if opt.output == 'raw':
buglist = bz.getbugs([b.bug_id for b in buglist])
for b in buglist:
print("Bugzilla %s: " % b.bug_id)
for attrname in sorted(b.__dict__):
print(to_encoding(u"ATTRIBUTE[%s]: %s" %
(attrname, b.__dict__[attrname])))
print("\n\n")
return
def bug_field(matchobj):
# whiteboard and flag allow doing
# %{whiteboard:devel} and %{flag:needinfo}
# That's what 'rest' matches
(fieldname, rest) = matchobj.groups()
if fieldname == "whiteboard" and rest:
fieldname = rest + "_" + fieldname
if fieldname == "flag" and rest:
val = b.get_flag_status(rest)
elif fieldname == "flags" or fieldname == "flags_requestee":
tmpstr = []
for f in getattr(b, "flags", []):
requestee = f.get('requestee', "")
if fieldname == "flags":
requestee = ""
if fieldname == "flags_requestee":
if requestee == "":
continue
tmpstr.append("%s" % requestee)
else:
tmpstr.append("%s%s%s" %
(f['name'], f['status'], requestee))
val = ",".join(tmpstr)
elif fieldname == "cve":
cves = []
for key in getattr(b, "keywords", []):
# grab CVE from keywords and blockers
if key.find("Security") == -1:
continue
for bl in b.blocks:
cvebug = bz.getbug(bl)
for cb in cvebug.alias:
if cb.find("CVE") == -1:
continue
if cb.strip() not in cves:
cves.append(cb)
val = ",".join(cves)
elif fieldname == "comments":
val = ""
for c in getattr(b, "comments", []):
val += ("\n* %s - %s:\n%s\n" %
(c['time'], c['author'], c['text']))
elif fieldname == "__unicode__":
val = b.__unicode__()
else:
val = getattr(b, fieldname, "")
vallist = isinstance(val, list) and val or [val]
val = ','.join([to_encoding(v) for v in vallist])
return val
for b in buglist:
print(format_field_re.sub(bug_field, opt.outputformat))
def _parse_triset(vallist, checkplus=True, checkminus=True, checkequal=True,
splitcomma=False):
add_val = []
rm_val = []
set_val = None
def make_list(v):
if not v:
return []
if splitcomma:
return v.split(",")
return [v]
for val in isinstance(vallist, list) and vallist or [vallist]:
val = val or ""
if val.startswith("+") and checkplus:
add_val += make_list(val[1:])
elif val.startswith("-") and checkminus:
rm_val += make_list(val[1:])
elif val.startswith("=") and checkequal:
# Intentionally overwrite this
set_val = make_list(val[1:])
else:
add_val += make_list(val)
return add_val, rm_val, set_val
def _do_new(bz, opt, parser):
# Parse options that accept comma separated list
def parse_multi(val):
return _parse_triset(val, checkplus=False, checkminus=False,
checkequal=False, splitcomma=True)[0]
ret = bz.build_createbug(
blocks=parse_multi(opt.blocked) or None,
cc=parse_multi(opt.cc) or None,
component=opt.component or None,
depends_on=parse_multi(opt.dependson) or None,
description=opt.description or None,
groups=parse_multi(opt.groups) or None,
keywords=parse_multi(opt.keywords) or None,
op_sys=opt.os or None,
platform=opt.arch or None,
priority=opt.priority or None,
product=opt.product or None,
severity=opt.severity or None,
summary=opt.summary or None,
url=opt.url or None,
version=opt.version or None,
assigned_to=opt.assigned_to or None,
qa_contact=opt.qa_contact or None,
sub_component=opt.sub_component or None,
alias=opt.alias or None,
)
_merge_field_opts(ret, opt, parser)
if opt.test_return_result:
return ret
b = bz.createbug(ret)
b.refresh()
return [b]
def _do_modify(bz, parser, opt, args):
bugid_list = [bugid for a in args for bugid in a.split(',')]
add_wb, rm_wb, set_wb = _parse_triset(opt.whiteboard)
add_devwb, rm_devwb, set_devwb = _parse_triset(opt.devel_whiteboard)
add_intwb, rm_intwb, set_intwb = _parse_triset(opt.internal_whiteboard)
add_qawb, rm_qawb, set_qawb = _parse_triset(opt.qa_whiteboard)
add_blk, rm_blk, set_blk = _parse_triset(opt.blocked, splitcomma=True)
add_deps, rm_deps, set_deps = _parse_triset(opt.dependson, splitcomma=True)
add_key, rm_key, set_key = _parse_triset(opt.keywords)
add_cc, rm_cc, ignore = _parse_triset(opt.cc,
checkplus=False,
checkequal=False)
add_groups, rm_groups, ignore = _parse_triset(opt.groups,
checkequal=False,
splitcomma=True)
add_tags, rm_tags, ignore = _parse_triset(opt.tags, checkequal=False)
status = opt.status or None
if opt.dupeid is not None:
opt.close = "DUPLICATE"
if opt.close:
status = "CLOSED"
You can’t perform that action at this time.
