コード例 #1
0
ファイル: download.py プロジェクト: wgwoods/dnf-plugins-core
    def configure(self, args):
        # setup sack and populate it with enabled repos
        demands = self.cli.demands
        demands.sack_activation = True
        demands.available_repos = True

        # Setup ArgumentParser to handle util
        # You must only add options not used by dnf already
        self.parser = dnfpluginscore.ArgumentParser(self.aliases[0])
        self.parser.add_argument('packages',
                                 nargs='+',
                                 help=_('packages to download'))
        self.parser.add_argument("--source",
                                 action='store_true',
                                 help=_('download the src.rpm instead'))
        self.parser.add_argument(
            '--destdir', help=_('download path, default is current dir'))
        self.parser.add_argument(
            '--resolve',
            action='store_true',
            help=_('resolve and download needed dependencies'))

        # parse the options/args
        # list available options/args on errors & exit
        self.opts = self.parser.parse_args(args)

        # show util help & exit
        if self.opts.help_cmd:
            print(self.parser.format_help())
            return

        if self.opts.source:
            dnfpluginscore.lib.enable_source_repos(self.base.repos)
コード例 #2
0
def parse_args(args):
    parser = dnfpluginscore.ArgumentParser(NeedsRestartingCommand.aliases[0])
    parser.add_argument('-u',
                        '--useronly',
                        action='store_true',
                        help=_("only consider this user's processes"))
    return parser.parse_args(args)
コード例 #3
0
def parse_arguments(args):
    def macro_def(arg):
        arglist = arg.split(None, 1) if arg else []
        if len(arglist) < 2:
            msg = _("'%s' is not of the format 'MACRO EXPR'") % arg
            raise dnfpluginscore.argparse.ArgumentTypeError(msg)
        return arglist

    parser = dnfpluginscore.ArgumentParser(BuildDepCommand.aliases[0])
    parser.add_argument('packages',
                        nargs='+',
                        metavar='package',
                        help=_('packages with builddeps to install'))
    parser.add_argument('-D',
                        '--define',
                        action='append',
                        default=[],
                        metavar="'MACRO EXPR'",
                        type=macro_def,
                        help=_('define a macro for spec file parsing'))
    ptype = parser.add_mutually_exclusive_group()
    ptype.add_argument('--spec',
                       action='store_true',
                       help=_('treat commandline arguments as spec files'))
    ptype.add_argument('--srpm',
                       action='store_true',
                       help=_('treat commandline arguments as source rpm'))

    return parser.parse_args(args), parser
コード例 #4
0
ファイル: py3query.py プロジェクト: mldulaney/portingdb
def parse_arguments(args):
    parser = dnfpluginscore.ArgumentParser(Py3QueryCommand.aliases[0])

    parser.add_argument('--output', '-o', metavar='FILE', action='store',
                        help=_('write output to the given file'))

    return parser.parse_args(args), parser
コード例 #5
0
    def configure(self, args):
        # setup sack and populate it with enabled repos
        demands = self.cli.demands
        demands.available_repos = True

        self.parser = dnfpluginscore.ArgumentParser(self.aliases[0])
        self.parser.add_argument(
            'repo', nargs='*',
            help=_('repo to modify'))
        self.parser.add_argument(
            '--save', default=False, action='store_true',
            help=_('save the current options (useful with --setopt)'))
        self.parser.add_argument(
            '--set-enabled', default=False, action='store_true',
            help=_('enable the specified repos (automatically saves)'))
        self.parser.add_argument(
            '--set-disabled', default=False, action='store_true',
            help=_('disable the specified repos (automatically saves)'))
        self.parser.add_argument(
            '--add-repo', default=[], action='append', metavar='URL',
            help=_('add (and enable) the repo from the specified file or url'))
        self.parser.add_argument(
            '--dump', default=False, action='store_true',
            help=_('print current configuration values to stdout'))

        self.opts = self.parser.parse_args(args)

        if self.opts.help_cmd:
            print(self.parser.format_help())
            return

        if (self.opts.save or self.opts.set_enabled or
                self.opts.set_disabled or self.opts.add_repo):
            demands.root_user = True
コード例 #6
0
 def test_argparse(self):
     """Test the ArgumentParser."""
     parser = dnfpluginscore.ArgumentParser('test')
     parser.add_argument('cmd', nargs=1)
     parser.add_argument('parms', nargs='*')
     self.assertEqual(parser.prog, 'dnf test')
     # test --help-cmd is added
     self.assertIn('--help-cmd', parser._option_string_actions)
     # test unknown option
     with mock.patch('argparse.ArgumentParser.print_help', lambda x: x):
         self.assertRaises(dnf.exceptions.Error, parser.parse_args,
                           ['--dummy'])
     # test --help-cmd is working
     opts = parser.parse_args(['subcmd', '--help-cmd'])
     self.assertTrue(opts.help_cmd)
     # test args
     opts = parser.parse_args(['subcmd', 'parm1', 'parm2'])
     self.assertEqual(opts.cmd, ['subcmd'])
     self.assertEqual(opts.parms, ['parm1', 'parm2'])
コード例 #7
0
def _parse_args(args):
    alias = RepoSyncCommand.aliases[0]
    parser = dnfpluginscore.ArgumentParser(alias)
    parser.add_argument(
        '-p',
        '--download-path',
        default='./',
        help=_('where to store downloaded repositories '),
    )
    parser.add_argument(
        '--repo',
        action='append',
        help=_('repository to download'),
    )
    # make --repoid hidden compatibility alias for --repo
    parser.add_argument('--repoid',
                        action='append',
                        dest='repo',
                        help=argparse.SUPPRESS)
    return parser.parse_args(args)
コード例 #8
0
def parse_arguments(args):
    parser = dnfpluginscore.ArgumentParser(Py3QueryCommand.aliases[0])

    parser.add_argument('--output',
                        '-o',
                        metavar='FILE',
                        action='store',
                        help=_('write output to the given file'))

    parser.add_argument('--no-bz',
                        dest='fetch_bugzilla',
                        action='store_false',
                        default=True,
                        help=_("Don't get Bugzilla links"))

    parser.add_argument('--qrepo',
                        dest='py3query_repo',
                        default='rawhide',
                        help=_("Repo to use for the query"))

    return parser.parse_args(args), parser
コード例 #9
0
def parse_arguments(args):
    # Setup ArgumentParser to handle util
    parser = dnfpluginscore.ArgumentParser(RepoQueryCommand.aliases[0])
    parser.add_argument('key', nargs='*', help=_('the key to search for'))
    parser.add_argument('--repo',
                        metavar='REPO',
                        action='append',
                        help=_('show only results from this REPO'))
    # make --repoid hidden compatibility alias for --repo
    parser.add_argument('--repoid',
                        dest='repo',
                        action='append',
                        help=argparse.SUPPRESS)
    parser.add_argument('--arch',
                        metavar='ARCH',
                        help=_('show only results from this ARCH'))
    parser.add_argument('-f',
                        '--file',
                        metavar='FILE',
                        help=_('show only results that owns FILE'))
    parser.add_argument('--whatprovides',
                        metavar='REQ',
                        help=_('show only results there provides REQ'))
    parser.add_argument('--whatrequires',
                        metavar='REQ',
                        help=_('show only results there require REQ'))
    parser.add_argument('--whatrecommends',
                        metavar='REQ',
                        help=_('show only results that recommend REQ'))
    parser.add_argument('--whatenhances',
                        metavar='REQ',
                        help=_('show only results that enhance REQ'))
    parser.add_argument('--whatsuggests',
                        metavar='REQ',
                        help=_('show only results that suggest REQ'))
    parser.add_argument('--whatsupplements',
                        metavar='REQ',
                        help=_('show only results that supplement REQ'))
    parser.add_argument(
        "--alldeps",
        action="store_true",
        help="shows results that requires package provides and files")
    parser.add_argument('--querytags',
                        action='store_true',
                        help=_('show available tags to use with '
                               '--queryformat'))
    parser.add_argument(
        '--resolve',
        action='store_true',
        help=_('resolve capabilities to originating package(s)'))
    parser.add_argument("--tree",
                        action="store_true",
                        help=_('show recursive tree for package(s)'))
    parser.add_argument('--srpm',
                        action='store_true',
                        help=_('operate on corresponding source RPM'))

    outform = parser.add_mutually_exclusive_group()
    outform.add_argument('-i',
                         "--info",
                         dest='queryinfo',
                         default=False,
                         action='store_true',
                         help=_('show detailed information about the package'))
    outform.add_argument('-l',
                         "--list",
                         dest='queryfilelist',
                         default=False,
                         action='store_true',
                         help=_('show list of files in the package'))
    outform.add_argument('-s',
                         "--source",
                         dest='querysourcerpm',
                         default=False,
                         action='store_true',
                         help=_('show package source RPM name'))
    outform.add_argument('--qf',
                         "--queryformat",
                         dest='queryformat',
                         default=QFORMAT_DEFAULT,
                         help=_('format for displaying found packages'))
    outform.add_argument("--latest-limit",
                         dest='latest_limit',
                         type=int,
                         help=_('show N latest packages for a given name.arch'
                                ' (or latest but N if N is negative)'))

    pkgfilter = parser.add_mutually_exclusive_group()
    pkgfilter.add_argument(
        "--duplicated",
        dest='pkgfilter',
        const='duplicated',
        action='store_const',
        help=_('limit the query to installed duplicated packages'))
    pkgfilter.add_argument(
        "--installonly",
        dest='pkgfilter',
        const='installonly',
        action='store_const',
        help=_('limit the query to installed installonly packages'))
    pkgfilter.add_argument(
        "--unsatisfied",
        dest='pkgfilter',
        const='unsatisfied',
        action='store_const',
        help=
        _('limit the query to installed packages with unsatisfied dependencies'
          ))

    package_atribute = parser.add_mutually_exclusive_group()
    help_msgs = {
        'conflicts':
        _('Display capabilities that the package conflicts with.'),
        'enhances': _('Display capabilities that the package can enhance.'),
        'obsoletes': _('Display capabilities that the package obsoletes.'),
        'provides': _('Display capabilities provided by the package.'),
        'recommends': _('Display capabilities that the package recommends.'),
        'requires': _('Display capabilities that the package depends on.'),
        'suggests': _('Display capabilities that the package suggests.'),
        'supplements':
        _('Display capabilities that the package can supplement.')
    }
    for arg in ('conflicts', 'enhances', 'obsoletes', 'provides', 'recommends',
                'requires', 'suggests', 'supplements'):
        name = '--%s' % arg
        package_atribute.add_argument(name,
                                      dest='packageatr',
                                      action='store_const',
                                      const=arg,
                                      help=help_msgs[arg])

    help_list = {
        'available':
        _('Display only available packages.'),
        'installed':
        _('Display only installed packages.'),
        'extras':
        _('Display only packages that are not present in any of available repositories.'
          ),
        'upgrades':
        _('Display only packages that provide an upgrade for some already installed package.'
          ),
        'autoremove':
        _('Display only packages that can be autoremoved.'),
        'recent':
        _('Display only recently edited packages')
    }
    list_group = parser.add_mutually_exclusive_group()
    for list_arg in ('available', 'installed', 'extras', 'upgrades',
                     'autoremove', 'recent'):
        switch = '--%s' % list_arg
        list_group.add_argument(switch,
                                dest='list',
                                action='store_const',
                                const=list_arg,
                                help=help_list[list_arg])

    return parser.parse_args(args), parser