forked from rpm-software-management/yum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yumcommands.py
5025 lines (4178 loc) · 188 KB
/
yumcommands.py
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 -t
# 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 Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Copyright 2006 Duke University
# Copyright 2013 Red Hat
# Written by Seth Vidal
"""
Classes for subcommands of the yum command line interface.
"""
import os
import sys
import cli
import rpm
from yum import logginglevels
from yum import _, P_
from yum import misc
import yum.Errors
import operator
import locale
import fnmatch
import time
from yum.i18n import utf8_width, utf8_width_fill, to_unicode, exception2msg
import tempfile
import shutil
import distutils.spawn
import glob
import errno
import yum.config
from yum import updateinfo
from yum.packages import parsePackages
from yum.packages import YumLocalPackage # cashe and fs diff
from yum.fssnapshots import LibLVMError, lvmerr2str
def _err_mini_usage(base, basecmd):
if basecmd not in base.yum_cli_commands:
base.usage()
return
cmd = base.yum_cli_commands[basecmd]
txt = base.yum_cli_commands["help"]._makeOutput(cmd)
base.logger.critical(_(' Mini usage:\n'))
base.logger.critical(txt)
def checkRootUID(base):
"""Verify that the program is being run by the root user.
:param base: a :class:`yum.Yumbase` object.
:raises: :class:`cli.CliError`
"""
if base.conf.uid != 0:
base.logger.critical(_('You need to be root to perform this command.'))
raise cli.CliError
def checkGPGKey(base):
"""Verify that there are gpg keys for the enabled repositories in the
rpm database.
:param base: a :class:`yum.Yumbase` object.
:raises: :class:`cli.CliError`
"""
if base._override_sigchecks:
return
if not base.gpgKeyCheck():
for repo in base.repos.listEnabled():
if (repo.gpgcheck or repo.repo_gpgcheck) and not repo.gpgkey:
msg = _("""
You have enabled checking of packages via GPG keys. This is a good thing.
However, you do not have any GPG public keys installed. You need to download
the keys for packages you wish to install and install them.
You can do that by running the command:
rpm --import public.gpg.key
Alternatively you can specify the url to the key you would like to use
for a repository in the 'gpgkey' option in a repository section and yum
will install it for you.
For more information contact your distribution or package provider.
""")
base.logger.critical(msg)
base.logger.critical(_("Problem repository: %s"), repo)
raise cli.CliError
def checkPackageArg(base, basecmd, extcmds):
"""Verify that *extcmds* contains the name of at least one package for
*basecmd* to act on.
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
:raises: :class:`cli.CliError`
"""
if len(extcmds) == 0:
base.logger.critical(
_('Error: Need to pass a list of pkgs to %s') % basecmd)
_err_mini_usage(base, basecmd)
raise cli.CliError
def checkSwapPackageArg(base, basecmd, extcmds):
"""Verify that *extcmds* contains the name of at least two packages for
*basecmd* to act on.
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
:raises: :class:`cli.CliError`
"""
min_args = 2
if '--' in extcmds:
min_args = 3
if len(extcmds) < min_args:
base.logger.critical(
_('Error: Need at least two packages to %s') % basecmd)
_err_mini_usage(base, basecmd)
raise cli.CliError
def checkRepoPackageArg(base, basecmd, extcmds):
"""Verify that *extcmds* contains the name of at least one package for
*basecmd* to act on.
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
:raises: :class:`cli.CliError`
"""
repos = base.repos.findRepos(extcmds[0], name_match=True, ignore_case=True)
if len(repos) > 1:
repos = [r for r in repos if r.isEnabled()]
if not repos:
base.logger.critical(
_('Error: Need to pass a single valid repoid. to %s') % basecmd)
_err_mini_usage(base, basecmd)
raise cli.CliError
if len(repos) > 1:
repos = ", ".join([r.ui_id for r in repos])
base.logger.critical(
_('Error: Need to pass only a single valid repoid. to %s, passed: %s') % (basecmd, repos))
_err_mini_usage(base, basecmd)
raise cli.CliError
if not repos[0].isEnabled():
# Might as well just fix this...
base.repos.enableRepo(repos[0].id)
base.verbose_logger.info(
_('Repo %s has been automatically enabled.') % repos[0].ui_id)
return repos[0].id
def checkItemArg(base, basecmd, extcmds):
"""Verify that *extcmds* contains the name of at least one item for
*basecmd* to act on. Generally, the items are command-line
arguments that are not the name of a package, such as a file name
passed to provides.
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
:raises: :class:`cli.CliError`
"""
if len(extcmds) == 0:
base.logger.critical(_('Error: Need an item to match'))
_err_mini_usage(base, basecmd)
raise cli.CliError
def checkGroupArg(base, basecmd, extcmds):
"""Verify that *extcmds* contains the name of at least one group for
*basecmd* to act on.
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
:raises: :class:`cli.CliError`
"""
if len(extcmds) == 0:
base.logger.critical(_('Error: Need a group or list of groups'))
_err_mini_usage(base, basecmd)
raise cli.CliError
def checkCleanArg(base, basecmd, extcmds):
"""Verify that *extcmds* contains at least one argument, and that all
arguments in *extcmds* are valid options for clean.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
:raises: :class:`cli.CliError`
"""
VALID_ARGS = ('headers', 'packages', 'metadata', 'dbcache', 'plugins',
'expire-cache', 'rpmdb', 'all')
if len(extcmds) == 0:
base.logger.critical(_('Error: clean requires an option: %s') % (
", ".join(VALID_ARGS)))
raise cli.CliError
for cmd in extcmds:
if cmd not in VALID_ARGS:
base.logger.critical(_('Error: invalid clean argument: %r') % cmd)
_err_mini_usage(base, basecmd)
raise cli.CliError
def checkShellArg(base, basecmd, extcmds):
"""Verify that the arguments given to 'yum shell' are valid. yum
shell can be given either no argument, or exactly one argument,
which is the name of a file.
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
:raises: :class:`cli.CliError`
"""
if len(extcmds) == 0:
base.verbose_logger.debug(_("No argument to shell"))
elif len(extcmds) == 1:
base.verbose_logger.debug(_("Filename passed to shell: %s"),
extcmds[0])
if not os.path.isfile(extcmds[0]):
base.logger.critical(
_("File %s given as argument to shell does not exist."),
extcmds[0])
base.usage()
raise cli.CliError
else:
base.logger.critical(
_("Error: more than one file given as argument to shell."))
base.usage()
raise cli.CliError
def checkEnabledRepo(base, possible_local_files=[]):
"""Verify that there is at least one enabled repo.
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
:raises: :class:`cli.CliError`:
"""
if base.repos.listEnabled():
return
for lfile in possible_local_files:
if lfile.endswith(".rpm") and (yum.misc.re_remote_url(lfile) or
os.path.exists(lfile)):
return
# runs prereposetup (which "most" plugins currently use to add repos.)
base.pkgSack
if base.repos.listEnabled():
return
msg = _('There are no enabled repos.\n'
' Run "yum repolist all" to see the repos you have.\n'
' To enable Red Hat Subscription Management repositories:\n'
' subscription-manager repos --enable <repo>\n'
' To enable custom repositories:\n'
' yum-config-manager --enable <repo>')
base.logger.critical(msg)
raise cli.CliError
class YumCommand:
"""An abstract base class that defines the methods needed by the cli
to execute a specific command. Subclasses must override at least
:func:`getUsage` and :func:`getSummary`.
"""
def __init__(self):
self.done_command_once = False
self.hidden = False
def doneCommand(self, base, msg, *args):
""" Output *msg* the first time that this method is called, and do
nothing on subsequent calls. This is to prevent duplicate
messages from being printed for the same command.
:param base: a :class:`yum.Yumbase` object
:param msg: the message to be output
:param *args: additional arguments associated with the message
"""
if not self.done_command_once:
base.verbose_logger.info(logginglevels.INFO_2, msg, *args)
self.done_command_once = True
def getNames(self):
"""Return a list of strings that are the names of the command.
The command can be called from the command line by using any
of these names.
:return: a list containing the names of the command
"""
return []
def getUsage(self):
"""Return a usage string for the command, including arguments.
:return: a usage string for the command
"""
raise NotImplementedError
def getSummary(self):
"""Return a one line summary of what the command does.
:return: a one line summary of what the command does
"""
raise NotImplementedError
def doCheck(self, base, basecmd, extcmds):
"""Verify that various conditions are met so that the command
can run.
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being checked for
:param extcmds: a list of arguments passed to *basecmd*
"""
pass
def doCommand(self, base, basecmd, extcmds):
"""Execute the command
:param base: a :class:`yum.Yumbase` object.
:param basecmd: the name of the command being executed
:param extcmds: a list of arguments passed to *basecmd*
:return: (exit_code, [ errors ])
exit_code is::
0 = we're done, exit
1 = we've errored, exit with error string
2 = we've got work yet to do, onto the next stage
"""
return 0, [_('Nothing to do')]
def needTs(self, base, basecmd, extcmds):
"""Return whether a transaction set must be set up before the
command can run
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: a list of arguments passed to *basecmd*
:return: True if a transaction set is needed, False otherwise
"""
return True
# Some of this is subjective, esp. between past/present, but roughly use:
#
# write = I'm using package data to alter the rpmdb in anyway.
# read-only:future = I'm providing data that is likely to result in a
# future write, so we might as well do it now.
# Eg. yum check-update && yum update -q -y
# read-only:present = I'm providing data about the present state of
# packages in the repo.
# Eg. yum list yum
# read-only:past = I'm providing context data about past writes, or just
# anything that is available is good enough for me
# (speed is much better than quality).
# Eg. yum history info
# Eg. TAB completion
#
# ...default is write, which does the same thing we always did (obey
# metadata_expire and live with it).
def cacheRequirement(self, base, basecmd, extcmds):
"""Return the cache requirements for the remote repos.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: a list of arguments passed to *basecmd*
:return: Type of requirement: read-only:past, read-only:present, read-only:future, write
"""
return 'write'
class InstallCommand(YumCommand):
"""A class containing methods needed by the cli to execute the
install command.
"""
def getNames(self):
"""Return a list containing the names of this command. This
command can be called from the command line by using any of
these names.
:return: a list containing the names of this command
"""
return ['install', 'install-n', 'install-na', 'install-nevra']
def getUsage(self):
"""Return a usage string for this command.
:return: a usage string for this command
"""
return _("PACKAGE...")
def getSummary(self):
"""Return a one line summary of this command.
:return: a one line summary of this command
"""
return _("Install a package or packages on your system")
def doCheck(self, base, basecmd, extcmds):
"""Verify that conditions are met so that this command can run.
These include that the program is being run by the root user,
that there are enabled repositories with gpg keys, and that
this command is called with appropriate arguments.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
"""
checkRootUID(base)
checkGPGKey(base)
checkPackageArg(base, basecmd, extcmds)
checkEnabledRepo(base, extcmds)
def doCommand(self, base, basecmd, extcmds):
"""Execute this command.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
:return: (exit_code, [ errors ])
exit_code is::
0 = we're done, exit
1 = we've errored, exit with error string
2 = we've got work yet to do, onto the next stage
"""
self.doneCommand(base, _("Setting up Install Process"))
return base.installPkgs(extcmds, basecmd=basecmd)
class UpdateCommand(YumCommand):
"""A class containing methods needed by the cli to execute the
update command.
"""
def getNames(self):
"""Return a list containing the names of this command. This
command can by called from the command line by using any of
these names.
:return: a list containing the names of this command
"""
return ['update', 'update-to']
def getUsage(self):
"""Return a usage string for this command.
:return: a usage string for this command
"""
return _("[PACKAGE...]")
def getSummary(self):
"""Return a one line summary of this command.
:return: a one line summary of this command
"""
return _("Update a package or packages on your system")
def doCheck(self, base, basecmd, extcmds):
"""Verify that conditions are met so that this command can run.
These include that there are enabled repositories with gpg
keys, and that this command is being run by the root user.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
"""
checkRootUID(base)
checkGPGKey(base)
checkEnabledRepo(base, extcmds)
def doCommand(self, base, basecmd, extcmds):
"""Execute this command.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
:return: (exit_code, [ errors ])
exit_code is::
0 = we're done, exit
1 = we've errored, exit with error string
2 = we've got work yet to do, onto the next stage
"""
self.doneCommand(base, _("Setting up Update Process"))
ret = base.updatePkgs(extcmds, update_to=(basecmd == 'update-to'))
updateinfo.remove_txmbrs(base)
return ret
class DistroSyncCommand(YumCommand):
"""A class containing methods needed by the cli to execute the
distro-synch command.
"""
def getNames(self):
"""Return a list containing the names of this command. This
command can be called from the command line by using any of these names.
:return: a list containing the names of this command
"""
return ['distribution-synchronization', 'distro-sync', 'distupgrade']
def getUsage(self):
"""Return a usage string for this command.
:return: a usage string for this command
"""
return _("[PACKAGE...]")
def getSummary(self):
"""Return a one line summary of this command.
:return: a one line summary of this command
"""
return _("Synchronize installed packages to the latest available versions")
def doCheck(self, base, basecmd, extcmds):
"""Verify that conditions are met so that this command can run.
These include that the program is being run by the root user,
and that there are enabled repositories with gpg keys.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
"""
checkRootUID(base)
checkGPGKey(base)
checkEnabledRepo(base, extcmds)
def doCommand(self, base, basecmd, extcmds):
"""Execute this command.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
:return: (exit_code, [ errors ])
exit_code is::
0 = we're done, exit
1 = we've errored, exit with error string
2 = we've got work yet to do, onto the next stage
"""
self.doneCommand(base, _("Setting up Distribution Synchronization Process"))
base.conf.obsoletes = 1
ret = base.distroSyncPkgs(extcmds)
updateinfo.remove_txmbrs(base)
return ret
def _add_pkg_simple_list_lens(data, pkg, indent=''):
""" Get the length of each pkg's column. Add that to data.
This "knows" about simpleList and printVer. """
na = len(pkg.name) + 1 + len(pkg.arch) + len(indent)
ver = len(pkg.version) + 1 + len(pkg.release)
rid = len(pkg.ui_from_repo)
if pkg.epoch != '0':
ver += len(pkg.epoch) + 1
for (d, v) in (('na', na), ('ver', ver), ('rid', rid)):
data[d].setdefault(v, 0)
data[d][v] += 1
def _list_cmd_calc_columns(base, ypl):
""" Work out the dynamic size of the columns to pass to fmtColumns. """
data = {'na' : {}, 'ver' : {}, 'rid' : {}}
for lst in (ypl.installed, ypl.available, ypl.extras,
ypl.updates, ypl.recent):
for pkg in lst:
_add_pkg_simple_list_lens(data, pkg)
if len(ypl.obsoletes) > 0:
for (npkg, opkg) in ypl.obsoletesTuples:
_add_pkg_simple_list_lens(data, npkg)
_add_pkg_simple_list_lens(data, opkg, indent=" " * 4)
data = [data['na'], data['ver'], data['rid']]
columns = base.calcColumns(data, remainder_column=1)
return (-columns[0], -columns[1], -columns[2])
def _cmdline_exclude(pkgs, cmdline_excludes):
""" Do an extra exclude for installed packages that match the cmd line. """
if not cmdline_excludes:
return pkgs
e,m,u = parsePackages(pkgs, cmdline_excludes)
excluded = set(e + m)
return [po for po in pkgs if po not in excluded]
class InfoCommand(YumCommand):
"""A class containing methods needed by the cli to execute the
info command.
"""
def getNames(self):
"""Return a list containing the names of this command. This
command can be called from the command line by using any of these names.
:return: a list containing the names of this command
"""
return ['info']
def getUsage(self):
"""Return a usage string for this command.
:return: a usage string for this command
"""
return "[PACKAGE|all|available|installed|updates|distro-extras|extras|obsoletes|recent]"
def getSummary(self):
"""Return a one line summary of this command.
:return: a one line summary of this command
"""
return _("Display details about a package or group of packages")
def doCommand(self, base, basecmd, extcmds, repoid=None):
"""Execute this command.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
:return: (exit_code, [ errors ])
exit_code is::
0 = we're done, exit
1 = we've errored, exit with error string
2 = we've got work yet to do, onto the next stage
"""
if extcmds and extcmds[0] in ('updates', 'obsoletes'):
updateinfo.exclude_updates(base)
else:
updateinfo.exclude_all(base)
if True: # Try, YumBase...
highlight = base.term.MODE['bold']
# If we are doing: "yum info installed blah" don't do the highlight
# because the usability of not accessing the repos. is still higher
# than providing colour for a single line. Usable updatesd/etc. FTW.
if basecmd == 'info' and extcmds and extcmds[0] == 'installed':
highlight = False
ypl = base.returnPkgLists(extcmds, installed_available=highlight,
repoid=repoid)
update_pkgs = {}
inst_pkgs = {}
local_pkgs = {}
columns = None
if basecmd == 'list':
# Dynamically size the columns
columns = _list_cmd_calc_columns(base, ypl)
if highlight and ypl.installed:
# If we have installed and available lists, then do the
# highlighting for the installed packages so you can see what's
# available to update, an extra, or newer than what we have.
for pkg in (ypl.hidden_available +
ypl.reinstall_available +
ypl.old_available):
key = (pkg.name, pkg.arch)
if key not in update_pkgs or pkg.verGT(update_pkgs[key]):
update_pkgs[key] = pkg
if highlight and ypl.available:
# If we have installed and available lists, then do the
# highlighting for the available packages so you can see what's
# available to install vs. update vs. old.
for pkg in ypl.hidden_installed:
key = (pkg.name, pkg.arch)
if key not in inst_pkgs or pkg.verGT(inst_pkgs[key]):
inst_pkgs[key] = pkg
if highlight and ypl.updates:
# Do the local/remote split we get in "yum updates"
for po in sorted(ypl.updates):
if po.repo.id != 'installed' and po.verifyLocalPkg():
local_pkgs[(po.name, po.arch)] = po
# Output the packages:
kern = base.conf.color_list_installed_running_kernel
clio = base.conf.color_list_installed_older
clin = base.conf.color_list_installed_newer
clir = base.conf.color_list_installed_reinstall
clie = base.conf.color_list_installed_extra
if base.conf.query_install_excludes:
ypl.installed = _cmdline_exclude(ypl.installed,
base.cmdline_excludes)
rip = base.listPkgs(ypl.installed, _('Installed Packages'), basecmd,
highlight_na=update_pkgs, columns=columns,
highlight_modes={'>' : clio, '<' : clin,
'kern' : kern,
'=' : clir, 'not in' : clie})
kern = base.conf.color_list_available_running_kernel
clau = base.conf.color_list_available_upgrade
clad = base.conf.color_list_available_downgrade
clar = base.conf.color_list_available_reinstall
clai = base.conf.color_list_available_install
rap = base.listPkgs(ypl.available, _('Available Packages'), basecmd,
highlight_na=inst_pkgs, columns=columns,
highlight_modes={'<' : clau, '>' : clad,
'kern' : kern,
'=' : clar, 'not in' : clai})
rep = base.listPkgs(ypl.extras, _('Extra Packages'), basecmd,
columns=columns)
cul = base.conf.color_update_local
cur = base.conf.color_update_remote
rup = base.listPkgs(ypl.updates, _('Updated Packages'), basecmd,
highlight_na=local_pkgs, columns=columns,
highlight_modes={'=' : cul, 'not in' : cur})
# XXX put this into the ListCommand at some point
if len(ypl.obsoletes) > 0 and basecmd == 'list':
# if we've looked up obsolete lists and it's a list request
rop = [0, '']
print _('Obsoleting Packages')
# The tuple is (newPkg, oldPkg) ... so sort by new
for obtup in sorted(ypl.obsoletesTuples,
key=operator.itemgetter(0)):
base.updatesObsoletesList(obtup, 'obsoletes',
columns=columns, repoid=repoid)
else:
rop = base.listPkgs(ypl.obsoletes, _('Obsoleting Packages'),
basecmd, columns=columns)
rrap = base.listPkgs(ypl.recent, _('Recently Added Packages'),
basecmd, columns=columns)
# extcmds is pop(0)'d if they pass a "special" param like "updates"
# in returnPkgLists(). This allows us to always return "ok" for
# things like "yum list updates".
if len(extcmds) and \
rrap[0] and rop[0] and rup[0] and rep[0] and rap[0] and rip[0]:
return 1, [_('No matching Packages to list')]
return 0, []
def needTs(self, base, basecmd, extcmds):
"""Return whether a transaction set must be set up before this
command can run.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: a list of arguments passed to *basecmd*
:return: True if a transaction set is needed, False otherwise
"""
if len(extcmds) and extcmds[0] == 'installed':
return False
return True
def cacheRequirement(self, base, basecmd, extcmds):
"""Return the cache requirements for the remote repos.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: a list of arguments passed to *basecmd*
:return: Type of requirement: read-only:past, read-only:present, read-only:future, write
"""
if len(extcmds) and extcmds[0] in ('updates', 'obsoletes'):
return 'read-only:future'
if len(extcmds) and extcmds[0] in ('installed', 'distro-extras', 'extras', 'recent'):
return 'read-only:past'
# available/all
return 'read-only:present'
class ListCommand(InfoCommand):
"""A class containing methods needed by the cli to execute the
list command.
"""
def getNames(self):
"""Return a list containing the names of this command. This
command can be called from the command line by using any of these names.
:return: a list containing the names of this command
"""
return ['list']
def getSummary(self):
"""Return a one line summary of this command.
:return: a one line summary of this command
"""
return _("List a package or groups of packages")
class EraseCommand(YumCommand):
"""A class containing methods needed by the cli to execute the
erase command.
"""
def getNames(self):
"""Return a list containing the names of this command. This
command can be called from the command line by using any of these names.
:return: a list containing the names of this command
"""
return ['erase', 'remove',
'erase-n', 'erase-na', 'erase-nevra',
'remove-n', 'remove-na', 'remove-nevra']
def getUsage(self):
"""Return a usage string for this command.
:return: a usage string for this command
"""
return "PACKAGE..."
def getSummary(self):
"""Return a one line summary of this command.
:return: a one line summary of this command
"""
return _("Remove a package or packages from your system")
def doCheck(self, base, basecmd, extcmds):
"""Verify that conditions are met so that this command can
run. These include that the program is being run by the root
user, and that this command is called with appropriate
arguments.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
"""
checkRootUID(base)
if basecmd == 'autoremove':
return
checkPackageArg(base, basecmd, extcmds)
def doCommand(self, base, basecmd, extcmds):
"""Execute this command.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
:return: (exit_code, [ errors ])
exit_code is::
0 = we're done, exit
1 = we've errored, exit with error string
2 = we've got work yet to do, onto the next stage
"""
pos = False
if basecmd.startswith('autoremove'):
# We have to alter this, as it's used in resolving stage. Which
# sucks. Just be careful in "yum shell".
base.conf.clean_requirements_on_remove = True
basecmd = basecmd[len('auto'):] # pretend it's just remove...
if not extcmds:
pos = True
extcmds = []
for pkg in sorted(base.rpmdb.returnLeafNodes()):
if 'reason' not in pkg.yumdb_info:
continue
if pkg.yumdb_info.reason != 'dep':
continue
extcmds.append(pkg)
self.doneCommand(base, _("Setting up Remove Process"))
ret = base.erasePkgs(extcmds, pos=pos, basecmd=basecmd)
return ret
def needTs(self, base, basecmd, extcmds):
"""Return whether a transaction set must be set up before this
command can run.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: a list of arguments passed to *basecmd*
:return: True if a transaction set is needed, False otherwise
"""
return False
def needTsRemove(self, base, basecmd, extcmds):
"""Return whether a transaction set for removal only must be
set up before this command can run.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: a list of arguments passed to *basecmd*
:return: True if a remove-only transaction set is needed, False otherwise
"""
return True
class AutoremoveCommand(EraseCommand):
"""A class containing methods needed by the cli to execute the
autremove command.
"""
def getNames(self):
"""Return a list containing the names of this command. This
command can be called from the command line by using any of these names.
:return: a list containing the names of this command
"""
return [ 'autoremove', 'autoremove-n', 'autoremove-na', 'autoremove-nevra']
def getSummary(self):
"""Return a one line summary of this command.
:return: a one line summary of this command
"""
return _("Remove leaf packages")
class GroupsCommand(YumCommand):
""" Single sub-command interface for most groups interaction. """
direct_commands = {'grouplist' : 'list',
'groupinstall' : 'install',
'groupupdate' : 'update',
'groupremove' : 'remove',
'grouperase' : 'remove',
'groupinfo' : 'info'}
def getNames(self):
"""Return a list containing the names of this command. This
command can be called from the command line by using any of these names.
:return: a list containing the names of this command
"""
return ['groups', 'group'] + self.direct_commands.keys()
def getUsage(self):
"""Return a usage string for this command.
:return: a usage string for this command
"""
return "[list|info|summary|install|upgrade|remove|mark] [GROUP]"
def getSummary(self):
"""Return a one line summary of this command.
:return: a one line summary of this command
"""
return _("Display, or use, the groups information")
def _grp_setup_doCommand(self, base):
self.doneCommand(base, _("Setting up Group Process"))
base.doRepoSetup(dosack=0)
try:
base.doGroupSetup()
except yum.Errors.GroupsError:
return 1, [_('No Groups on which to run command')]
except yum.Errors.YumBaseError, e:
raise
def _grp_cmd(self, basecmd, extcmds):
if basecmd in self.direct_commands:
cmd = self.direct_commands[basecmd]
elif extcmds:
cmd = extcmds[0]
extcmds = extcmds[1:]
else:
cmd = 'summary'
if cmd in ('mark', 'unmark') and extcmds:
cmd = "%s-%s" % (cmd, extcmds[0])
extcmds = extcmds[1:]
remap = {'update' : 'upgrade',
'erase' : 'remove',
'mark-erase' : 'mark-remove',
}
cmd = remap.get(cmd, cmd)
return cmd, extcmds
def doCheck(self, base, basecmd, extcmds):
"""Verify that conditions are met so that this command can run.
The exact conditions checked will vary depending on the
subcommand that is being called.
:param base: a :class:`yum.Yumbase` object
:param basecmd: the name of the command
:param extcmds: the command line arguments passed to *basecmd*
"""
cmd, extcmds = self._grp_cmd(basecmd, extcmds)