[python-uk] Welcome to the "python-uk" mailing list

Alistair Broomhead alistair.broomhead at gmail.com
Sat Jul 28 07:27:53 EDT 2018


So I'd still agree with the advice to post this on StackOverflow, as it's a
better format for a mailing list for this sort of question, but you're
almost there, I advise you look at dict.items, also your rpm list code
might be a little cleaner if you looked at named groups for re, and
considered turning those loops into functions.

There's plenty more I could suggest, but as suggested earlier this isn't
the best forum for this sort of help, I'd point to either the
aforementioned StackOverflow, or looking at IRC channels on freenode.

On Sat, 28 Jul 2018, 11:48 Asad, <asad.hasan2004 at gmail.com> wrote:

> Hi All ,
>
>          I got few steps ahead :  How to I iterate from keys of one
> dictionary to another and just compare the version ?
>
> import is
> import re
> from distutils.version import StrictVersion
> import operator
>
> lines=[]
> new_dict={}
> old_dict={}
>
>
> fo = open("rpmlist1.txt", "r")
> for line in fo:
>     line=line.strip()
>     lines.append(line)
>
> #print lines
>
> get_rpm_parts = re.compile(r"""
>       ^ (.*)        # name
>       - (.*)        # version
>       - ([0-9]+)    # build
>       [.] ([^.]+)   # os
>       [.] ([^.]+) $ # architecture
> """, re.X)
>
> for s in lines:
>     match = re.search(get_rpm_parts, s)
>     if match :
>  #       print "name: %s ver: %s arch: %s" % (match1.group ( 1 ), match1.group ( 2 ), match1.group ( 5 ))
>         new_dict[match.group(1)] = {"name": s, "version": match.group ( 2 ), "build": match.group ( 3 ),"os": match.group ( 4 ), "arch": match.group ( 5 )}
>         #else:
>      #   print "no match1",s
>
> print new_dict
>
>
>
> list1 = [
>         "binutils-2.23.52.0.1-12.el7.x86_64",
>         "compat-libcap1-1.10-3.el7.x86_64",
>         "compat-libstdc++-33-3.2.3-71.el7.i686",
>         "compat-libstdc++-33-3.2.3-71.el7.x86_64",
>         "gcc-4.8.2-3.el7.x86_64",
>         "gcc-c++-4.8.2-3.el7.x86_64",
>         "glibc-2.17-36.el7.i686",
>         "glibc-2.17-36.el7.x86_64",
>         "glibc-devel-2.17-36.el7.i686",
>         "glibc-devel-2.17-36.el7.x86_64",
>         "ksh",
>         "libaio-0.3.109-9.el7.i686",
>         "libaio-0.3.109-9.el7.x86_64",
>         "libaio-devel-0.3.109-9.el7.i686",
>         "libaio-devel-0.3.109-9.el7.x86_64",
>         "libgcc-4.8.2-3.el7.i686",
>         "libgcc-4.8.2-3.el7.x86_64",
>         "libstdc++-4.8.2-3.el7.i686",
>         "libstdc++-4.8.2-3.el7.x86_64",
>         "libstdc++-devel-4.8.2-3.el7.i686",
>         "libstdc++-devel-4.8.2-3.el7.x86_64",
>         "libXi-1.7.2-1.el7.i686",
>         "libXi-1.7.2-1.el7.x86_64",
>         "libXtst-1.2.2-1.el7.i686",
>         "libXtst-1.2.2-1.el7.x86_64",
>         "make-3.82-19.el7.x86_64",
>         "sysstat-10.1.5-1.el7.x86_64",
> ]
>
> for i in list1:
>     match1 = re.search(get_rpm_parts, i)
>     if match1:
>         #print "name: %s ver: %s arch: %s" % (match1.group ( 1 ), match1.group ( 2 ), match1.group ( 5 ))
>         old_dict[match1.group ( 1 )] = {"name": i, "version": match1.group ( 2 ), "build": match1.group ( 3 ),"os": match1.group ( 4 ), "arch": match1.group ( 5 )}
>     # else:
>     #   print "no match1",s
>
> print old_dict
>
> ----Please let me know from here how to proceed further   ***************
>
> On Sat, Jul 28, 2018 at 1:20 PM Nathan Jeffrey <nathan.jeffrey at gmail.com>
> wrote:
>
>> If I were going to do that, I would make those lists into sets, and then
>> you could use set arithmetic to calculate the intersections.
>>
>> Have a look on Stack Overflow. This is fairly bread-and-butter stuff, and
>> I am sure there is a better answer there than I could concoct here 😁
>>
>> Good luck!
>>
>> - N
>>
>> On Sat, 28 Jul 2018, 08:42 Asad, <asad.hasan2004 at gmail.com> wrote:
>>
>>> Hi All ,
>>>
>>>            I am new to python just completed 4 lecture on python, I am
>>> looking for a pyhton script of module which check the versions of the rpm
>>> in linux .
>>>
>>>           I have a situation in which I have two list list1 and list2 :
>>>
>>> list1 is prerequisites rpm for application
>>>
>>> and list2 is the list of rpm's in the system
>>>
>>> list1 = [
>>>         "binutils-2.23.52.0.1-12.el7.x86_64",
>>>         "compat-libcap1-1.10-3.el7.x86_64",
>>>         "compat-libstdc++-33-3.2.3-71.el7.i686",
>>>         "compat-libstdc++-33-3.2.3-71.el7.x86_64",
>>>         "gcc-4.8.2-3.el7.x86_64",
>>>         "gcc-c++-4.8.2-3.el7.x86_64",
>>>         "glibc-2.17-36.el7.i686",
>>>         "glibc-2.17-36.el7.x86_64",
>>>         "glibc-devel-2.17-36.el7.i686",
>>>         "glibc-devel-2.17-36.el7.x86_64",
>>>         "ksh",
>>>         "libaio-0.3.109-9.el7.i686",
>>>         "libaio-0.3.109-9.el7.x86_64",
>>>         "libaio-devel-0.3.109-9.el7.i686",
>>>         "libaio-devel-0.3.109-9.el7.x86_64",
>>>         "libgcc-4.8.2-3.el7.i686",
>>>         "libgcc-4.8.2-3.el7.x86_64",
>>>         "libstdc++-4.8.2-3.el7.i686",
>>>         "libstdc++-4.8.2-3.el7.x86_64",
>>>         "libstdc++-devel-4.8.2-3.el7.i686",
>>>         "libstdc++-devel-4.8.2-3.el7.x86_64",
>>>         "libXi-1.7.2-1.el7.i686",
>>>         "libXi-1.7.2-1.el7.x86_64",
>>>         "libXtst-1.2.2-1.el7.i686",
>>>         "libXtst-1.2.2-1.el7.x86_64",
>>>         "make-3.82-19.el7.x86_64",
>>>         "sysstat-10.1.5-1.el7.x86_64",
>>> ]
>>>
>>> lsit2 = ['acl-2.2.51-12.el7.x86_64', 'adcli-0.8.1-3.el7.x86_64',
>>> 'audit-2.7.6-3.el7.x86_64', 'audit-libs-2.7.6-3.el7.i686',
>>> 'audit-libs-2.7.6-3.el7.x86_64', 'audit-libs-python-2.7.6-3.el7.x86_64',
>>> 'authconfig-6.2.8-30.el7.x86_64', 'autofs-5.0.7-70.0.1.el7_4.1.x86_64',
>>> 'autogen-libopts-5.18-5.el7.x86_64', 'avahi-autoipd-0.6.31-17.el7.x86_64',
>>> 'avahi-libs-0.6.31-17.el7.x86_64', 'bash-4.2.46-29.el7_4.x86_64',
>>> 'bc-1.06.95-13.el7.x86_64', 'bind-libs-9.9.4-51.el7_4.2.x86_64',
>>> 'bind-libs-lite-9.9.4-51.el7_4.2.x86_64',
>>> 'bind-license-9.9.4-51.el7_4.2.noarch',
>>> 'bind-utils-9.9.4-51.el7_4.2.x86_64',
>>> 'binutils-2.25.1-32.base.el7_4.2.x86_64', 'biosdevname-0.7.2-2.el7.x86_64',
>>> 'btrfs-progs-4.9.1-1.0.2.el7.x86_64', 'bzip2-1.0.6-13.el7.x86_64',
>>> 'bzip2-libs-1.0.6-13.el7.i686', 'bzip2-libs-1.0.6-13.el7.x86_64',
>>> 'ca-certificates-2017.2.14-71.el7.noarch', 'c-ares-1.10.0-3.el7.x86_64',
>>> 'checkpolicy-2.5-4.el7.x86_64', 'chkconfig-1.7.4-1.el7.x86_64',
>>> 'compat-libcap1-1.10-7.el7.x86_64',
>>> 'compat-libstdc++-33-3.2.3-72.el7.i686',
>>> 'compat-libstdc++-33-3.2.3-72.el7.x86_64',
>>> 'coreutils-8.22-18.0.1.el7.x86_64', 'cpio-2.11-25.el7_4.x86_64',
>>> 'cpp-4.8.5-16.0.3.el7_4.2.x86_64', 'cracklib-2.9.0-11.el7.i686',
>>> 'cracklib-2.9.0-11.el7.x86_64', 'cracklib-dicts-2.9.0-11.el7.x86_64',
>>> 'cronie-1.4.11-17.el7.x86_64', 'cronie-anacron-1.4.11-17.el7.x86_64']
>>>
>>> I would like to do a rpm version check between the two list  (list1 and
>>> list2)
>>>
>>> so it only prints the rpm from list1 which are not installed and version
>>> available in list2 is higher or lower .
>>>
>>>  Thanks in advance ,
>>>
>>>
>>> On Sat, Jul 28, 2018 at 1:31 AM <python-uk-request at python.org> wrote:
>>>
>>>> Welcome to the python-uk at python.org mailing list! Welcome to the
>>>> python-uk mailing list.
>>>>
>>>> This list is to help UK Python users to form a community, arrange
>>>> events, advertise help or jobs wanted or sought and generally chat.
>>>>
>>>>
>>>> To post to this list, send your message to:
>>>>
>>>>   python-uk at python.org
>>>>
>>>> General information about the mailing list is at:
>>>>
>>>>   https://mail.python.org/mailman/listinfo/python-uk
>>>>
>>>> If you ever want to unsubscribe or change your options (eg, switch to
>>>> or from digest mode, change your password, etc.), visit your
>>>> subscription page at:
>>>>
>>>>
>>>> https://mail.python.org/mailman/options/python-uk/asad.hasan2004%40gmail.com
>>>>
>>>>
>>>> You can also make such adjustments via email by sending a message to:
>>>>
>>>>   python-uk-request at python.org
>>>>
>>>> with the word `help' in the subject or body (don't include the
>>>> quotes), and you will get back a message with instructions.
>>>>
>>>> You must know your password to change your options (including changing
>>>> the password, itself) or to unsubscribe without confirmation.  It is:
>>>>
>>>>   Welc0me at 1
>>>>
>>>> Normally, Mailman will remind you of your python.org mailing list
>>>> passwords once every month, although you can disable this if you
>>>> prefer.  This reminder will also include instructions on how to
>>>> unsubscribe or change your account options.  There is also a button on
>>>> your options page that will email your current password to you.
>>>>
>>>
>>>
>>> --
>>> Asad Hasan
>>> +91 9582111698
>>> _______________________________________________
>>> python-uk mailing list
>>> python-uk at python.org
>>> https://mail.python.org/mailman/listinfo/python-uk
>>>
>> _______________________________________________
>> python-uk mailing list
>> python-uk at python.org
>> https://mail.python.org/mailman/listinfo/python-uk
>>
>
>
> --
> Asad Hasan
> +91 9582111698
> _______________________________________________
> python-uk mailing list
> python-uk at python.org
> https://mail.python.org/mailman/listinfo/python-uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-uk/attachments/20180728/bfc7f2d4/attachment-0001.html>


More information about the python-uk mailing list