Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] How to Compare Rpm Versions in Python?

#1
How to Compare Rpm Versions in Python?

Problem Formulation: Compare RPM Versions in Python

  • Given two lists of strings that are the RPM versions currently installed on your computer and the versions in a repository or another environment.
  • How to compare those lists to find the RPMs that are out of date?

Example: Our goal is to determine a list of packages that have a different newer version.

Input:
rpm_1 = ["my_package-3.2.2.rpm", "your_package-3.1.1.rpm", "their_package-3.1.1.rpm", "her_package-3.1.1.rpm", "his_package-3.1.1.rpm", "its_package-3.1.1.rpm"] rpm_2 = ["my_package-9.2.2.rpm", "your_package-3.1.1.rpm", "her_package-3.1.1.rpm", "their_package-9.1.1.rpm"] Output:
Stale package my_package3.2.2.rpm has new version: 9.2.2
Stale package their_package3.1.1.rpm has new version: 9.1.1

Background: RPM is an acronym for RedHat Package Manager and it is a free open-source package management system for Linux to install packages with the file suffix .rpm. An RPM package contains an arbitrary number of files to be extracted into the Linux operating system. It’s used for many modern Linux distributions such as Fedora, CentOS, OpenSUSE, and Oracle Linux.

Solution: We solve the problem with a simple dictionary versions that tracks the versions of each of the old packages from rpm_1 and compares them with the versions in the newer list rpm_2.

# RPM names assuming '-' indicates start of version number
rpm_1 = ["my_package-3.2.2.rpm", "your_package-3.1.1.rpm", "their_package-3.1.1.rpm", "her_package-3.1.1.rpm", "his_package-3.1.1.rpm", "its_package-3.1.1.rpm"]
rpm_2 = ["my_package-9.2.2.rpm", "your_package-3.1.1.rpm", "her_package-3.1.1.rpm", "their_package-9.1.1.rpm"] def compare(rpm_1, rpm_2): versions = dict() for s in rpm_1: name, version = s.split('-') version = version[:-4] versions[name] = version for s in rpm_2: name, version = s.split('-') version = version[:-4] if name in versions and version != versions[name]: print('Stale package', name + versions[name] + '.rpm', 'has new version: ', version) compare(rpm_1, rpm_2)

The output is the list of packages that differ in the version name in comparison to at least one old package name:

Stale package my_package3.2.2.rpm has new version: 9.2.2
Stale package their_package3.1.1.rpm has new version: 9.1.1

The post How to Compare Rpm Versions in Python? first appeared on Finxter.



https://www.sickgaming.net/blog/2021/02/...in-python/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tut] How To Run Multiple Python Versions On Windows? xSicKxBot 0 31 03-08-2021, 03:30 PM
Last Post: xSicKxBot
  [Tut] Python help() xSicKxBot 0 65 01-22-2021, 01:02 AM
Last Post: xSicKxBot
  [Tut] Python complex() — A Useless Python Feature? xSicKxBot 0 73 12-19-2020, 02:05 AM
Last Post: xSicKxBot
  [Tut] Python next() xSicKxBot 0 69 11-22-2020, 08:17 AM
Last Post: xSicKxBot
  [Tut] Hello World! A Python One-Liner to Get Started with Python Quickly xSicKxBot 0 117 09-07-2020, 06:10 PM
Last Post: xSicKxBot
  [Tut] The Most Pythonic Way to Compare Two Lists in Python xSicKxBot 0 141 06-28-2020, 04:18 PM
Last Post: xSicKxBot
  [Tut] Python Join List of Bytes (and What’s a Python Byte Anyway?) xSicKxBot 0 186 06-10-2020, 05:38 AM
Last Post: xSicKxBot
  [Tut] Python Re Dot xSicKxBot 0 317 01-28-2020, 08:01 AM
Last Post: xSicKxBot

Forum Jump:

[-]
Active Threads
PluralSight Courses All Free During Apri...
Last Post: xSicKxBot
Today 05:10 PM
» Replies: 0
» Views: 2
AppleInsider - Flash deal: 50% off H&R B...
Last Post: xSicKxBot
Today 05:10 PM
» Replies: 0
» Views: 1
News - See More Of New Zombie Game The D...
Last Post: xSicKxBot
Today 05:09 PM
» Replies: 0
» Views: 1
ISO: Staff Members for Website, Discord,...
Last Post: Ronalddiz
Today 04:20 PM
» Replies: 4
» Views: 8419
Official Sick Gaming Social Links: Twitt...
Last Post: Marcusjut
Today 09:56 AM
» Replies: 5
» Views: 9793
(Indie Deal) FREE ToW3: Korea, Sold Out,...
Last Post: xSicKxBot
Today 07:05 AM
» Replies: 0
» Views: 6
News - Unrailed! Is The Next Switch Limi...
Last Post: xSicKxBot
Today 07:05 AM
» Replies: 0
» Views: 8
News - The Darkside Detective: A Fumble ...
Last Post: xSicKxBot
Today 07:05 AM
» Replies: 0
» Views: 7
News - The Hunter Dev On Using Motion Ca...
Last Post: xSicKxBot
Today 07:05 AM
» Replies: 0
» Views: 11
Sick Gaming Welcomes All Gamers
Last Post: Rayfordres
Today 06:14 AM
» Replies: 8
» Views: 15824

[-]
Twitter

[-]
Sponsored
Get the Deal of the Week at RefurBees.com

Copyright © SickGaming.net 2012-2020