Re: Tips to add optional arguments on dnf using plugin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Fellipe,

if layer in your case means a particular set of repositories, then
Nicolas advice with using distinct prefixes for repositories in each
layer and then passing --repoid=<prefix>-* to the dnf is probably most
straightforward solution.

If you really need a custom plugin, then there is a problem that
values parsed from command line options are stored only in command
classes. So if you need to use it in the plugin, you must parse
arguments and store values yourself. This example works for me:

class Ghost(dnf.Plugin):
    name = 'ghost'

    def __init__(self, base, cli):
        super(Ghost, self).__init__(base, cli)
        cli.optparser.add_argument('--set-layer')
        self.myopts, _unused_args = cli.optparser.parse_known_args(sys.argv[1:])

    def config(self):
        print("Plugin config() set-layer =", self.myopts.set_layer)

Then when I call any dnf command, I can see output from the plugin
with correct value of set-layer option:

$ dnf search --set-layer=helloworld HHH
Plugin config() set-layer = helloworld
Last metadata expiration check: 3:22:10 ago on Út 23. července 2019,
12:20:31 CEST.
No matches found.

Regards,

Marek
--
Marek Blaha <mblaha@xxxxxxxxxx>

Red Hat Czech s.r.o.
Software Engineer

On Tue, Jul 23, 2019 at 2:19 PM Fellipe Henrique <fellipeh@xxxxxxxxx> wrote:
>
> Hi Marek,
>
> Thanks again for your reply..
>
> I already tried to use __init__ method...  arguments was added without error ( I can get any message when add on optparser), but, dnf still say:  unrecognized arguments
>
> I believe it's because plugin is loaded after args was passed inside dnf, so, dnf not recognize the new argument.. only approach I can get global args, is add inside def _main_parser(self):  on option_parser.py  on dnf package.. but, I avoid to change anything from mainstream..
>
> Cheers,
>
> T.·.F.·.A.·.     S+F
> Fellipe Henrique P. Soares
>
> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
> Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh
> Blog: http:www.fellipeh.eti.br
> GitHub: https://github.com/fellipeh
> Twitter: @fh_bash
>
>
> On Tue, Jul 23, 2019 at 9:10 AM Marek Blaha <mblaha@xxxxxxxxxx> wrote:
>>
>> Hi,
>>
>> there is no supported way how to change global arguments in DNF.
>> However, you can try in __init__ method of your plugin do something
>> like this:
>>
>> class MyPlugin(dnf.Plugin):
>>     def __init__(self, base, cli):
>>         super(MyPlugin, self).__init__(base, cli)
>>         cli.optparser.add_argument('--set-layer')
>>
>> --
>> Marek Blaha <mblaha@xxxxxxxxxx>
>>
>> Red Hat Czech s.r.o.
>> Software Engineer
>> On Tue, Jul 23, 2019 at 12:02 PM Fellipe Henrique <fellipeh@xxxxxxxxx> wrote:
>> >
>> > Hi Marek,
>> >
>> > First, Thanks very much for you reply...
>> >
>> > I need to add a "global" argument so I can change the layer of a repository... For example:
>> >
>> > $ dnf repolist --set-layer=mylayer
>> > $ dnf install -y any_repo --set-layer=mylayer
>> >
>> > So on my plug-in I can change layer in repository to do anything, for that running process, to a different layer. (For example)..
>> >
>> > That's the reason I need a "global" argument, not a command, so I can use these arg on any dnf command, like "-v" argument..
>> >
>> > I saw your email related to reposync, but reposync use a command, so I need to add a command "reposync" and its arguments... As I explain above, I need a global argument to work with all dnf commands...
>> >
>> > That's my real problem, I do not know if dnf plug-in give me access to do that...
>> >
>> > On yum, I made these using init_hook() def, and setting the args.. But dnf doesn't no have init_hook anymore....
>> >
>> > Again, thanks for your time and help, any tips will be welcome..
>> >
>> > Cheers!
>> >
>> > Fellipe H.
>> >
>> > Em ter, 23 de jul de 2019 às 03:37, Marek Blaha <mblaha@xxxxxxxxxx> escreveu:
>> >>
>> >> Each DNF command could have static method set_argparser (here is the
>> >> example from reposync plugin:
>> >> https://github.com/rpm-software-management/dnf-plugins-core/blob/master/plugins/reposync.py#L60)
>> >> which can be used for adding command specific arguments. However there
>> >> is no such method for adding global arguments.
>> >> May I ask you to elaborate your use case in more details? What are you
>> >> trying to achieve?
>> >>
>> >> Regards,
>> >>
>> >> Marek
>> >>
>> >> --
>> >> Marek Blaha <mblaha@xxxxxxxxxx>
>> >>
>> >> Red Hat Czech s.r.o.
>> >> Software Engineer
>> >>
>> >> On Mon, Jul 22, 2019 at 7:59 PM Fellipe Henrique <fellipeh@xxxxxxxxx> wrote:
>> >> >
>> >> > Hello,
>> >> >
>> >> > First of all, thanks for accept me on these mail list.. my first mail it's about a issue I facing here on my job...
>> >> >
>> >> > I need to add some optional arguments on dnf,  not a command, just a "global" args.. eg:  $ dnf repolist --my_arg=abcd
>> >> >
>> >> > How can I do these? Can I use plugin with these approach?
>> >> >
>> >> > I already try to override OptionParser from cli inside Plugin class, no success... I try just parse cli args, but dnf still says my argument if not recognized..
>> >> >
>> >> > Anyone, have any tips how to do that?
>> >> >
>> >> > Best regards,
>> >> >
>> >> > T.·.F.·.A.·.     S+F
>> >> > Fellipe Henrique P. Soares
>> >> >
>> >> > e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
>> >> > Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh
>> >> > Blog: http:www.fellipeh.eti.br
>> >> > GitHub: https://github.com/fellipeh
>> >> > Twitter: @fh_bash
>> >> > _______________________________________________
>> >> > devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
>> >> > To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
>> >> > Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
>> >> > List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
>> >> > List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
>> >> _______________________________________________
>> >> devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
>> >> To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
>> >> Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
>> >> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
>> >> List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
>> >
>> > --
>> > Sent from my iPhone
>> > _______________________________________________
>> > devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
>> > To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
>> > Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
>> > List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
>> > List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
>> _______________________________________________
>> devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
>> To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
>> Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
>> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
>> List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
>
> _______________________________________________
> devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
> Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Users]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]

  Powered by Linux