Verify Method for RPM Module - Release 0.9

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

 



I create a new method for the rpm module.

*With glob integration

The method for the rpm module is done, thanks for the suggestions given
during all of the work.

The code is available at: http://func.pastebin.com/f75c77458 and I also
am sending the diff and git file in annex.




Michael DeHaan wrote:
Seth Vidal wrote:


On Thu, 2 Apr 2009, Milton Paiva Neto wrote:

In a conjunct effort me and Varinder Singh merged the RPM Module with the Yum Module and we create a module called Packages.


The module is available at:
http://func.pastebin.com/f215bec3b
http://matrix.senecac.on.ca/~mpaivaneto/packages.py


Don't call it packages.

unless the plan is to merge in deb package and other support as well.

-sv

_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list


Further -- joining the install and remove code with the yum code won't work on RHEL 4 installations, since it would require yum to be installed.

We also can't be changing API signatures for modules like this midstream, so this introduces duplication.

If you want to create a higher level packages module (that uses the rpm and yum module code), this is reasonable... but as Seth says, it should also support (at minimum) Debian and be an abstract
concept. It should also reuse the code from the other two modules.

That's a great idea, I want to upstream this method to the rpm module
than I can begin to work in create the higher level "Packages module".
In the time I was thinking in merge the rpm module with the yum module
I didn't think that other people could have been using scripts who uses
code from these modules as they are right now. Keeping the rpm and the
yum module and creating a super module that call these modules is
probably the best way to go, thanks again for the comments.


PackageKit sort of comes up as a logical abstraction layer, but I think that's a bad idea seeing that's not available for EL 4, and enterprise-ness is the primary install base.

--Michael


--
--------
Milton Paiva Neto
milton.paiva@xxxxxxxxx
mpaivaneto@xxxxxxxxxxxxxxxxxxx
http://miltonpaiva.wordpress.com/


# Copyright 2007, Red Hat, Inc
# Michael DeHaan <mdehaan@xxxxxxxxxx>
# Copyright 2009
# Milton Paiva Neto <milton.paiva@xxxxxxxxx>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.

import func_module

class RpmModule(func_module.FuncModule):

    version = "0.0.1"
    api_version = "0.0.1"
    description = "RPM related commands."

    def inventory(self, flatten=True):
        """
        Returns information on all installed packages.
        By default, 'flatten' is passed in as True, which makes printouts very
        clean in diffs for use by func-inventory.  If you are writting another
        software application, using flatten=False will prevent the need to 
        parse the returns.
        """
        # I have not been able to get flatten=False to work if there 
        # is more than 491 entries in the dict -- ashcrow
        import rpm
        ts = rpm.TransactionSet()
        mi = ts.dbMatch()
        results = []
        for hdr in mi:
            name = hdr['name']
            epoch = (hdr['epoch'] or 0)
            version = hdr['version']
            release = hdr['release']
            arch = hdr['arch']
            if flatten:
                results.append("%s %s %s %s %s" % (name, epoch, version, 
                                                   release, arch))
            else:
                results.append([name, epoch, version, release, arch])
        return results

    def verify(self, pattern='', flatten=True):
        """
        Returns information on the verified package(s).
        """        
        import rpm
        import yum
        from re import split
        ts = rpm.TransactionSet()
        mi = (ts.dbMatch() if pattern == '' else self.glob(pattern))
        results = []
        for hdr in mi:
            name = hdr['name'] if pattern == '' else split("\s",hdr)[0]
            if flatten:                
                yb = yum.YumBase()
                pkgs = yb.rpmdb.searchNevra(name)
                for pkg in pkgs:
                    errors = pkg.verify()
                    for fn in errors.keys():
                        for prob in errors[fn]:
                            results.append('%s %s %s' % (name, fn, prob.message))
            else:
                results.append("%s-%s-%s.%s" % (name, version, release, arch))
        return results

    def glob(self, pattern, flatten=True):
        """
        Return a list of installed packages that match a pattern
        """
        import rpm
        ts = rpm.TransactionSet()
        mi = ts.dbMatch()
        results = []
        if not mi:
            return
        mi.pattern('name', rpm.RPMMIRE_GLOB, pattern)
        for hdr in mi:
            name = hdr['name']
            epoch = (hdr['epoch'] or 0)
            version = hdr['version']
            release = hdr['release']
            # gpg-pubkeys have no arch
            arch = (hdr['arch'] or "")

            if flatten:
                results.append("%s %s %s %s %s" % (name, epoch, version,
                                                       release, arch))
            else:
                results.append([name, epoch, version, release, arch])
        return results

    def register_method_args(self):
        """
        Implementing the method argument getter
        """
        return {
                'inventory':{
                    'args':{
                        'flatten':{
                            'type':'boolean',
                            'optional':True,
                            'default':True,
                            'description':"Print clean in difss"
                            }
                        },
                    'description':"Returns information on all installed packages"
                    },
                'verify':{
                    'args':{
                        'flatten':{
                            'type':'boolean',
                            'optional':True,
                            'default':True,
                            'description':"Print clean in difss"
                            }
                        },
                    'description':"Returns information on the verified package(s)"
                    },
                'glob':{
                    'args':{
                        'pattern':{
                            'type':'string',
                            'optional':False,
                            'description':"The glob packet pattern"
                            },
                        'flatten':{
                            'type':'boolean',
                            'optional':True,
                            'default':True,
                            'description':"Print clean in difss"
                                }
                        },
                    'description':"Return a list of installed packages that match a pattern"
                    }
                }
3,4d2
< # Copyright 2009
< # Milton Paiva Neto <milton.paiva@xxxxxxxxx>
31c29
<         import rpm
---
> 	import rpm
48,71d45
<     def verify(self, pattern='', flatten=True):
<         """
<         Returns information on the verified package(s).
<         """        
<         import rpm
<         import yum
<         from re import split
<         ts = rpm.TransactionSet()
<         mi = (ts.dbMatch() if pattern == '' else self.glob(pattern))
<         results = []
<         for hdr in mi:
<             name = hdr['name'] if pattern == '' else split("\s",hdr)[0]
<             if flatten:                
<                 yb = yum.YumBase()
<                 pkgs = yb.rpmdb.searchNevra(name)
<                 for pkg in pkgs:
<                     errors = pkg.verify()
<                     for fn in errors.keys():
<                         for prob in errors[fn]:
<                             results.append('%s %s %s' % (name, fn, prob.message))
<             else:
<                 results.append("%s-%s-%s.%s" % (name, version, release, arch))
<         return results
< 
76c50
<         import rpm
---
> 	import rpm
101a76
> 
114,124d88
<                 'verify':{
<                     'args':{
<                         'flatten':{
<                             'type':'boolean',
<                             'optional':True,
<                             'default':True,
<                             'description':"Print clean in difss"
<                             }
<                         },
<                     'description':"Returns information on the verified package(s)"
<                     },
141c105
<                 }
\ No newline at end of file
---
>                 }

diff --git a/usr/lib/python2.5/site-packages/func/minion/modules/rpms.py b/func/func/minion/modules/rpms.py
index 3ed0290..746b9b8 100644
--- a/usr/lib/python2.5/site-packages/func/minion/modules/rpms.py
+++ b/func/func/minion/modules/rpms.py
@@ -1,7 +1,5 @@
 # Copyright 2007, Red Hat, Inc
 # Michael DeHaan <mdehaan@xxxxxxxxxx>
-# Copyright 2009
-# Milton Paiva Neto <milton.paiva@xxxxxxxxx>
 #
 # This software may be freely redistributed under the terms of the GNU
 # general public license.
@@ -28,7 +26,7 @@ class RpmModule(func_module.FuncModule):
         """
         # I have not been able to get flatten=False to work if there 
         # is more than 491 entries in the dict -- ashcrow
-        import rpm
+	import rpm
         ts = rpm.TransactionSet()
         mi = ts.dbMatch()
         results = []
@@ -45,35 +43,11 @@ class RpmModule(func_module.FuncModule):
                 results.append([name, epoch, version, release, arch])
         return results
 
-    def verify(self, pattern='', flatten=True):
-        """
-        Returns information on the verified package(s).
-        """        
-        import rpm
-        import yum
-        from re import split
-        ts = rpm.TransactionSet()
-        mi = (ts.dbMatch() if pattern == '' else self.glob(pattern))
-        results = []
-        for hdr in mi:
-            name = hdr['name'] if pattern == '' else split("\s",hdr)[0]
-            if flatten:                
-                yb = yum.YumBase()
-                pkgs = yb.rpmdb.searchNevra(name)
-                for pkg in pkgs:
-                    errors = pkg.verify()
-                    for fn in errors.keys():
-                        for prob in errors[fn]:
-                            results.append('%s %s %s' % (name, fn, prob.message))
-            else:
-                results.append("%s-%s-%s.%s" % (name, version, release, arch))
-        return results
-
     def glob(self, pattern, flatten=True):
         """
         Return a list of installed packages that match a pattern
         """
-        import rpm
+	import rpm
         ts = rpm.TransactionSet()
         mi = ts.dbMatch()
         results = []
@@ -99,6 +73,7 @@ class RpmModule(func_module.FuncModule):
         """
         Implementing the method argument getter
         """
+
         return {
                 'inventory':{
                     'args':{
@@ -111,17 +86,6 @@ class RpmModule(func_module.FuncModule):
                         },
                     'description':"Returns information on all installed packages"
                     },
-                'verify':{
-                    'args':{
-                        'flatten':{
-                            'type':'boolean',
-                            'optional':True,
-                            'default':True,
-                            'description':"Print clean in difss"
-                            }
-                        },
-                    'description':"Returns information on the verified package(s)"
-                    },
                 'glob':{
                     'args':{
                         'pattern':{
@@ -138,4 +102,4 @@ class RpmModule(func_module.FuncModule):
                         },
                     'description':"Return a list of installed packages that match a pattern"
                     }
-                }
\ No newline at end of file
+                }

_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list

[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux