GithubHelp home page GithubHelp logo

ihiji / version_utils Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 8.0 55 KB

Version parsing and comparison utilities in pure python

Home Page: https://pypi.python.org/pypi/version_utils

License: GNU General Public License v3.0

Python 100.00%

version_utils's People

Contributors

alxgu avatar furlongm avatar mplanchard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

version_utils's Issues

feature request: replacement for labelCompare

I've been trying version_utils to see if I can use it as a replacement for labelCompare from rpm-python (which is not available on pypi). There seems to be some differences in the output:

Compare version_utils output:

apparmor-abstractions-2.10.1-5.1-noarch -> apparmor-abstractions-2.10-3.2-noarch (Bugfix)
apparmor-docs-2.10.1-5.1-noarch -> apparmor-docs-2.10-3.2-noarch (Bugfix)
apparmor-parser-2.10.1-5.1-x86_64 -> apparmor-parser-2.10-3.2-x86_64 (Bugfix)
apparmor-profiles-2.10.1-5.1-noarch -> apparmor-profiles-2.10-3.2-noarch (Bugfix)
apparmor-utils-2.10.1-5.1-noarch -> apparmor-utils-2.10-3.2-noarch (Bugfix)
bpython-0.12-14.7-noarch -> bpython-0.14.2-26.3-noarch (Bugfix)
deltarpm-3.6.1-7.1-x86_64 -> deltarpm-3.6-5.1-x86_64 (Bugfix)
libapparmor1-2.10.1-5.1-x86_64 -> libapparmor1-2.10-3.2-x86_64 (Bugfix)
libical1-1.0.1-11.1-x86_64 -> libical1-1.0-9.7-x86_64 (Bugfix)
perl-apparmor-2.10.1-5.1-x86_64 -> perl-apparmor-2.10-3.2-x86_64 (Bugfix)
python3-apparmor-2.10.1-5.1-x86_64 -> python3-apparmor-2.10-3.2-x86_64 (Bugfix)
yast2-users-3.1.41.3-10.1-x86_64 -> yast2-users-3.1.41-4.1-x86_64 (Bugfix)

vs labelCompare output:

bpython-0.12-14.7-noarch -> bpython-0.14.2-26.3-noarch (Bugfix)

The labelCompare output is correct as far as the system is concerned.

Shouldn't both of the following functions return the same value?

>>> compare_packages('apparmor-abstractions-2.10.1-5.1-noarch', 'apparmor-abstractions-2.10-3.2-noarch')
1
>>> compare_versions('2.10.1-5.1', '2.10-3.2')
-1

Also related, would a drop-in replacement for labelCompare be a possibility?

rpm.compare_versions inaccurate

version: 0.3.0

Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> from version_utils import rpm
>>> rpm.compare_versions('2.0.14.1-1.29.amzn1', '2.0.14-1.25.amzn1')
-1
>>>

it's obviously the 2.0.14.1-1.29.amzn1 is new version

Index out of range

I'm getting an error on this test

from version_utils import rpm
def test_compare_evr_trailing_chars():
    """
    Test a fix I applied to the evr function.
    """
    evr_a = [u'0', u'2.02.98', u'9.el6_4.2']
    evr_b = [u'0', u'2.02.98', u'9.el6.']
    assert rpm.compare_evrs(evr_a, evr_b) == rpm.a_newer
        while len(chars_a) != 0 and len(chars_b) != 0:
            logger.debug('starting loop comparing %s '
                         'to %s', chars_a, chars_b)
            _check_leading(chars_a, chars_b)
            if chars_a[0] == '~' and chars_b[0] == '~':
                map(lambda x: x.pop(0), (chars_a, chars_b))
            elif chars_a[0] == '~':
                return b_newer
>           elif chars_b[0] == '~':
E           IndexError: list index out of range

../../../../.virtualenvs/ciam/lib/python2.7/site-packages/version_utils/rpm.py:173: IndexError

I think the problem is in compare_versions on line #168. _check_leading modifies a list in place, making the list empty.

I think a fix might be to add another length check at line 169, right after the call to _check_leading.

could not parse package string

Getting the following error:

version_utils.errors.RpmError: Could not parse package string: aaa_base-13.2+git20140911.61c1681-10.1

For reference, python-rpm parses this as ('', '13.2+git20140911.61c1681', '10.1')

Should allow a package name as well as a version

If the version name ends in .rpm, that portion of the name should be stripped and ignored. Similarly in the future for .deb, etc.

This would allow you to take the normal name of a package file and input it without stripping it.

Right now, it returns "rpm" as the architecture if one fails to strip off the .rpm from the package name.

version_utils: incorrect handling of epoch in _rpm_re regex

The _rpm_re regular expression is used to split RPM nvr or nevr to name, epoch, version and release. However, the regex is incorrect and likely to treat part of the version number as epoch number, as it only handles : as optional, rather than whole (\d*):.

>>> from version_utils import rpm
>>> pkg = rpm.package('firefox-45.0-4.fc22.x86_64')
>>> print pkg.epoch, pkg.version
4 5.0

while the expected output is:

0 45.0

I think the relevant part of the regex should be (?:(\d*):)?. Non-capturing group is used to avoid further changes to parse_package(). However, the following still needs fixing:

epoch = default_epoch if epoch == '' else epoch

to check if epoch is None.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.