[Tutor] How to Compare rpm version using Python Script

Asad asad.hasan2004 at gmail.com
Mon Dec 2 08:55:29 EST 2019


Hi All ,

          I am trying to use Json to serialize the data .I wrote a small
code :

run the command : rpm -qa --queryformat "%{NAME} %{VERSION} %{RELEASE}
%{ARCH}\n" > /tmp/rpm.output

It gives a list of rpm separated by space . How can I convert to json so
that I can then make it a python dictionary object dictOne ?

dictTwo is a required list of rpm's which is to be checked  .


for rpmOne in dictOne:
    for rpmTwo in dictTwo:
        if rpmOne["name"] == rpmTwo["name"]:
           if rpmOne["arch"] == "x86_64" :
            if rpmOne["version"] >= rpmTwo["version"] :
               #print rpm["name"],rpm["arch"],rpm["version"], "Installed"
               Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]])
            else :
              #print rpm["name"],rpm["arch"],rpm["version"] , "Version is
less than required"
              Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]])
           elif rpm["arch"] == "i686" :
            if rpm["version"] >= rpmTwo["version"] :
               #print rpm["name"],rpm["arch"],rpm["version"], "Installed"
              Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]])
            else :
              #print rpm["name"],rpm["arch"],rpm["version"] , "Version is
less than required"
              Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]])
   else:
       continue
else :

       NotInstalledrpm.append([rpm["name"],rpm["arch"],rpm["version"]])

for install in Installedrpm :
    print install[0],install[1],install[2]

for noninstall in NotInstalledrpm:
    print noninstall


Please advice if there could be simpler or smarter way to achieve this .


On Sat, Nov 30, 2019 at 1:30 PM David L Neil via Tutor <tutor at python.org>
wrote:

> On 30/11/19 3:07 PM, David wrote:
> > On Sat, 30 Nov 2019 at 12:01, Alan Gauld via Tutor <tutor at python.org>
> wrote:
> >
> >> I used to work beside a data processing team who spent their lives
> >> creating reports from old COBOL based systems. They used to write
> >> their processed (ie pre-report) data extracts into CSV format files
> >> but instead of commas they used the cedilla character(ç), as it
> >> was hardly ever found in real world data (at least not in our area,
> >> maybe in Romance based language areas that might not hold good).
> >> But the point was to use a character that you will not actually
> >> find in the text as a separator.
> >
> > Years ago I noticed that ASCII contains several control characters that
> > are specifically intended as data separators:
> > https://en.wikipedia.org/wiki/Control_character#Data_structuring
> >
> > I sometimes use them in my shell scripting where appropriate, due to
> > the limited data structures available there, but I've never seen them
> used
> > or advocated anywhere else.
> >
> > Are there reasons why they are not used more widely by programmers
> > to solve simple textual data separation problems?
> >
> > I assume that they would still work with utf8, although I've not tested
> > that.
>
> Many of the "control characters" had specific purposes, perhaps in
> certain situations or in relation to particular devices, eg xOA is still
> used as printer/screen/etc LineFeed to this day. So, need to be careful
> in case the output is ever printed (for example).
>
> In ASCII there were official "separator" characters (x1C-1F), to which
> users could assign their own particular meaning, even though they were
> assigned names, eg "Record Separator".
>
> These (latter) have carried-through to UTF-8, eg "INFORMATION SEPARATOR
> ONE" through "...FOUR", and seem quite appropriate to the OP's application.
>
> --
> Regards =dn
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Asad Hasan
+91 9582111698


More information about the Tutor mailing list