Package portage :: Module versions
[hide private]

Module versions

source code

Classes [hide private]
  _pkg_str
This class represents a cpv.
Functions [hide private]
 
_get_slot_re(eapi_attrs) source code
 
_get_pv_re(eapi_attrs) source code
 
ververify(myver, silent=1) source code
 
vercmp(ver1, ver2, silent=1)
Compare two versions Example usage: >>> from portage.versions import vercmp >>> vercmp('1.0-r1','1.2-r3') negative number >>> vercmp('1.3','1.2-r3') positive number >>> vercmp('1.0_p3','1.0_p3') 0
source code
None or integer
pkgcmp(pkg1, pkg2)
Compare 2 package versions created in pkgsplit format.
source code
 
_pkgsplit(mypkg, eapi=None)
@param mypkg: pv @return: 1.
source code
 
catpkgsplit(mydata, silent=1, eapi=None)
Takes a Category/Package-Version-Rev and returns a list of each.
source code
 
pkgsplit(mypkg, silent=1, eapi=None)
@param mypkg: either a pv or cpv @return: 1.
source code
 
cpv_getkey(mycpv, eapi=None)
Calls catpkgsplit on a cpv and returns only the cp.
source code
 
cpv_getversion(mycpv, eapi=None)
Returns the v (including revision) from an cpv.
source code
key object for sorting
cpv_sort_key(eapi=None)
Create an object for sorting cpvs, to be used as the 'key' parameter in places like list.sort() or sorted().
source code
 
catsplit(mydep) source code
 
best(mymatches, eapi=None)
Accepts None arguments; assumes matches are valid.
source code
Variables [hide private]
  _unknown_repo = u'__unknown__'
  _slot = u'([\w+][\w+.-]*)'
  _cat = u'[\w+][\w+.-]*'
  _pkg = {u'dots_allowed_in_PN': u'[\w+][\w+.-]*?', u'dots_disal...
  _v = u'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)...
  _rev = u'\d+'
  _vr = u'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc...
  _cp = {u'dots_allowed_in_PN': u'([\w+][\w+.-]*/[\w+][\w+.-]*?(...
  _cpv = {u'dots_allowed_in_PN': u'(([\w+][\w+.-]*/[\w+][\w+.-]*...
  _pv = {u'dots_allowed_in_PN': u'(?P<pn>[\w+][\w+.-]*?(?P<pn_in...
  ver_regexp = re.compile(r'^(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(...
  suffix_regexp = re.compile(r'^(alpha|beta|rc|pre|p)(\d*)$')
  suffix_value = {u'alpha': -4, u'beta': -3, u'p': 0, u'pre': -2...
  endversion_keys = [u'pre', u'p', u'alpha', u'beta', u'rc']
  _slot_re_cache = {}
  _pv_re_cache = {True: re.compile(r'(?ux)^(?P<pn>[\w\+][\w\+\.-...
  _cat_re = re.compile(r'(?u)^[\w\+][\w\+\.-]*$')
  _missing_cat = u'null'
  __package__ = 'portage'

Imports: re, sys, warnings, _unicode, portage, _unicode_decode, _get_eapi_attrs, InvalidData, _, _gen_valid_repo, cmp_sort_key


Function Details [hide private]

vercmp(ver1, ver2, silent=1)

source code 

Compare two versions
Example usage:
        >>> from portage.versions import vercmp
        >>> vercmp('1.0-r1','1.2-r3')
        negative number
        >>> vercmp('1.3','1.2-r3')
        positive number
        >>> vercmp('1.0_p3','1.0_p3')
        0

@param pkg1: version to compare with (see ver_regexp in portage.versions.py)
@type pkg1: string (example: "2.1.2-r3")
@param pkg2: version to compare againts (see ver_regexp in portage.versions.py)
@type pkg2: string (example: "2.1.2_rc5")
@rtype: None or float
@return:
1. positive if ver1 is greater than ver2
2. negative if ver1 is less than ver2 
3. 0 if ver1 equals ver2
4. None if ver1 or ver2 are invalid (see ver_regexp in portage.versions.py)

pkgcmp(pkg1, pkg2)

source code 

Compare 2 package versions created in pkgsplit format.

Example usage:

>>> from portage.versions import *
>>> pkgcmp(pkgsplit('test-1.0-r1'),pkgsplit('test-1.2-r3'))
-1
>>> pkgcmp(pkgsplit('test-1.3'),pkgsplit('test-1.2-r3'))
1
Parameters:
  • pkg1 (list (example: ['test', '1.0', 'r1'])) - package to compare with
  • pkg2 (list (example: ['test', '1.0', 'r1'])) - package to compare againts
Returns: None or integer
  1. None if package names are not the same
  2. 1 if pkg1 is greater than pkg2
  3. -1 if pkg1 is less than pkg2
  4. 0 if pkg1 equals pkg2

_pkgsplit(mypkg, eapi=None)

source code 

@param mypkg: pv
@return:
1. None if input is invalid.
2. (pn, ver, rev) if input is pv

catpkgsplit(mydata, silent=1, eapi=None)

source code 

Takes a Category/Package-Version-Rev and returns a list of each.

@param mydata: Data to split
@type mydata: string 
@param silent: suppress error messages
@type silent: Boolean (integer)
@rype: list
@return:
1.  If each exists, it returns [cat, pkgname, version, rev]
2.  If cat is not specificed in mydata, cat will be "null"
3.  if rev does not exist it will be '-r0'

pkgsplit(mypkg, silent=1, eapi=None)

source code 

@param mypkg: either a pv or cpv
@return:
1. None if input is invalid.
2. (pn, ver, rev) if input is pv
3. (cp, ver, rev) if input is a cpv

cpv_sort_key(eapi=None)

source code 

Create an object for sorting cpvs, to be used as the 'key' parameter in places like list.sort() or sorted(). This calls catpkgsplit() once for each cpv and caches the result. If a given cpv is invalid or two cpvs have different category/package names, then plain string (> and <) comparison is used.

Returns: key object for sorting
object for use as the 'key' parameter in places like list.sort() or sorted()

Variables Details [hide private]

_pkg

Value:
{u'dots_allowed_in_PN': u'[\w+][\w+.-]*?',
 u'dots_disallowed_in_PN': u'[\w+][\w+-]*?'}

_v

Value:
u'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)'

_vr

Value:
u'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+\
))?'

_cp

Value:
{u'dots_allowed_in_PN': u'([\w+][\w+.-]*/[\w+][\w+.-]*?(-(cvs\.)?(\d+)\
((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)',
 u'dots_disallowed_in_PN': u'([\w+][\w+.-]*/[\w+][\w+-]*?(-(cvs\.)?(\d\
+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)'}

_cpv

Value:
{u'dots_allowed_in_PN': u'(([\w+][\w+.-]*/[\w+][\w+.-]*?(-(cvs\.)?(\d+\
)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)-(cvs\.)\
?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)',
 u'dots_disallowed_in_PN': u'(([\w+][\w+.-]*/[\w+][\w+-]*?(-(cvs\.)?(\\
d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)-(cvs\\
.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)'}

_pv

Value:
{u'dots_allowed_in_PN': u'(?P<pn>[\w+][\w+.-]*?(?P<pn_inval>-(cvs\.)?(\
\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)-(?P<\
ver>(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*))(-r(\
?P<rev>\d+))?',
 u'dots_disallowed_in_PN': u'(?P<pn>[\w+][\w+-]*?(?P<pn_inval>-(cvs\.)\
?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)-(?\
P<ver>(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*))(-\
r(?P<rev>\d+))?'}

ver_regexp

Value:
re.compile(r'^(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\
d*)*)(-r(\d+))?$')

suffix_value

Value:
{u'alpha': -4, u'beta': -3, u'p': 0, u'pre': -2, u'rc': -1}

_pv_re_cache

Value:
{True: re.compile(r'(?ux)^(?P<pn>[\w\+][\w\+\.-]*?(?P<pn_inval>-(cvs\.\
)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)-(\
?P<ver>(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*))(\
-r(?P<rev>\d+))?$')}