Re: back ported dnf pretransaction for fedora 25

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

 



Hi,

I think you might have the wrong mailing list for this topic - this is a
list for 389 Directory Server, not dnf. However, your work does look
very interesting, and I hope that it gets accepted :) 

On Mon, 2017-06-26 at 14:24 +0000, andreas@xxxxxxxxxxxxx wrote:
> Hello Everyone,
> 
> I back ported the function pretransaction into dnf plugin from fedora 25, because
> I’ don’t wanna break the current system.
> 
> Source can be found at:
> 
> https://copr.fedorainfracloud.org/coprs/andybe/BtrfsF25/
> 
> dnf-1.1.10-7.fc25.src.rpm
> dnf-plugins-extras-0.0.12-5.fc25.src.rpm
> 
> 0001-dnf-plugin-add-pretransaction.patch 
> 
> diff --git a/dnf/base.py b/dnf/base.py
> index eade03d..46e1e40 100644
> --- a/dnf/base.py
> +++ b/dnf/base.py
> @@ -603,6 +603,8 @@ class Base(object):
>                  for display_ in cb.displays:
>                      display_.output = False
>  
> +            self._plugins.run_pre_transaction()
> +
>              logger.info(_('Running transaction'))
>              self._run_transaction(cb=cb)
>          timer()
> diff --git a/dnf/plugin.py b/dnf/plugin.py
> index c611cc3..0978db8 100644
> --- a/dnf/plugin.py
> +++ b/dnf/plugin.py
> @@ -67,6 +67,9 @@ class Plugin(object):
>      def sack(self):
>          # :api
>          pass
> +    def pre_transaction(self):
> +        # :api
> +        pass
>  
>      def transaction(self):
>          # :api
> @@ -106,6 +109,7 @@ class Plugins(object):
>  
>      run_sack = _caller('sack')
>      run_resolved = _caller('resolved')
> +    run_pre_transaction = _caller('pre_transaction')
>      run_transaction = _caller('transaction')
>  
>      def unload(self):
> diff --git a/doc/api_plugins.rst b/doc/api_plugins.rst
> index e2e15ba..8845a3c 100644
> --- a/doc/api_plugins.rst
> +++ b/doc/api_plugins.rst
> @@ -55,6 +55,10 @@ When DNF CLI runs it loads the plugins found in the paths during the CLI's initi
>  
>      Plugin can override this. This hook is called immediately after :attr:`.Base.sack` is initialized with data from all the enabled repos.
>  
> +  .. method:: pre_transaction
> +
> +    Plugin can override this. This hook is called just before transaction execution. This means after a successful transaction test. RPMDB is locked during that time.
> +
>    .. method:: transaction
>  
>      Plugin can override this. This hook is called immediately after a successful transaction.
> diff --git a/doc/api_vs_yum.rst b/doc/api_vs_yum.rst
> index 65b6a35..7c421e6 100644
> --- a/doc/api_vs_yum.rst
> +++ b/doc/api_vs_yum.rst
> @@ -37,7 +37,7 @@ Hook Number  Yum hook           DNF hook
>  ``6``        ``prereposetup``          
>  ``7``        ``postreposetup``  ``sack``
>  ``8``        ``exclude``        ``resolved``
> -``9``        ``preresolve``              
> +``9``        ``preresolve``     ``pre_transaction       
>  ``10``       ``postresolve``    ``resolved but no re-resolve``
>  ``11``       ``pretrans``              
>  ``12``       ``postrans``       ``transaction``
>  
> 
> 
> 
> 
> dnf-plugins-extras-0.0.12
> 
> snapper_prepost.patch
> 
> diff --git a/plugins/snapper.py b/plugins/snapper.py
> index d0443b0..877be38 100644
> --- a/plugins/snapper.py
> +++ b/plugins/snapper.py
> @@ -1,6 +1,7 @@
>  # creates snapshots via 'snapper'.
>  #
>  # Copyright (C) 2014 Igor Gnatenko
> +# Copyright (C) 2017 Andreas Benzler
>  #
>  # This copyrighted material is made available to anyone wishing to use,
>  # modify, copy, or redistribute it subject to the terms and conditions of
> @@ -31,17 +32,11 @@ class Snapper(dnf.Plugin):
>      def __init__(self, base, cli):
>          self.base = base
>          self.description = " ".join(sys.argv)
> +        self.snapper = None
> +        self.pre_id = None
>  
> -    def transaction(self):
> -        if not len(self.base.transaction):
> -            return
> -
> -        if dnfpluginsextras.is_erasing(self.base.transaction,
> -                                       "snapper"):
> -            return
>          try:
> -            bus = SystemBus()
> -            snapper = Interface(bus.get_object('org.opensuse.Snapper',
> +            self.snapper = Interface(SystemBus().get_object('org.opensuse.Snapper',
>                                                 '/org/opensuse/Snapper'),
>                                  dbus_interface='org.opensuse.Snapper')
>          except DBusException as e:
> @@ -49,15 +44,37 @@ class Snapper(dnf.Plugin):
>                  "snapper: " + _("connect to snapperd failed: %s"), e
>              )
>              return
> +
> +    def pre_transaction(self):
> +        if not len(self.base.transaction):
> +            return
> +
>          try:
> +            logger.debug("snapper:" + _("creating snapshot") + " (pre)"
> +            )
> +            self.pre_id = self.snapper.CreatePreSnapshot('root', self.description, 'number', {})
>              logger.debug(
> -                "snapper: " + _("creating snapshot")
> +                "snapper: " + _("created snapshot %d"), self.pre_id
> +            )
> +
> +        except DBusException as e:
> +            logger.critical(
> +                "snapper: " + _("creating snapshot failed: %s"), e
> +            )
> +
> +    def transaction(self):
> +        if not len(self.base.transaction):
> +            return
> +
> +
> +        try:
> +            logger.debug("snapper:" + _("creating snapshot") + " (post)"
>              )
> -            snap = snapper.CreateSingleSnapshot("root", self.description,
> -                                                "number", {})
> +            post_id = self.snapper.CreatePostSnapshot('root',  str(self.pre_id) ,'', 'number',{})
>              logger.debug(
> -                "snapper: " + _("created snapshot %d"), snap
> +                "snapper: " + _("created snapshot %d"), post_id
>              )
> +
>          except DBusException as e:
>              logger.critical(
>                  "snapper: " + _("creating snapshot failed: %s"), e
> _______________________________________________
> 389-devel mailing list -- 389-devel@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to 389-devel-leave@xxxxxxxxxxxxxxxxxxxxxxx

-- 
Sincerely,

William Brown
Software Engineer
Red Hat, Australia/Brisbane

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
389-devel mailing list -- 389-devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to 389-devel-leave@xxxxxxxxxxxxxxxxxxxxxxx

[Index of Archives]     [Fedora Directory Announce]     [Fedora Users]     [Older Fedora Users Mail]     [Fedora Advisory Board]     [Fedora Security]     [Fedora Devel Java]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Mentors]     [Fedora Package Review]     [Fedora Art]     [Fedora Music]     [Fedora Packaging]     [CentOS]     [Fedora SELinux]     [Big List of Linux Books]     [KDE Users]     [Fedora Art]     [Fedora Docs]

  Powered by Linux