#
# Copyright (c) 2008 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

"""
Module for common utility functions.
"""

import os

def join(a, *b):
    """
    Version of os.path.join that doesn't reroot when it finds a leading /.
    """

    root = os.path.normpath(a)
    for path in b:
        root += os.sep + os.path.normpath(path)
    return root

@@ -629,16 +629,49 @@
 ort os%0A%0A
+from rpmvercmp import rpmvercmp%0A%0A
 def join
@@ -885,8 +885,930 @@
 rn root%0A
+%0Adef srpmToConaryVersion(srcPkg):%0A    %22%22%22%0A    Get the equvialent conary version from a srcPkg object.%0A    @param srcPkg: package object for a srpm%0A    @type srcPkg: repomd.packagexml._Package%0A    @return conary trailing version%0A    %22%22%22%0A%0A    version = srcPkg.version.replace('-', '_')%0A    release = srcPkg.release.replace('-', '_')%0A    cnyver = '_'.join(%5Bversion, release%5D)%0A    return cnyver%0A%0Adef packagevercmp(a, b):%0A    %22%22%22%0A    Compare two package objects.%0A    @param a: package object from repo metadata%0A    @type a: repomd.packagexml._Package%0A    @param b: package object from repo metadata%0A    @type b: repomd.packagexml._Package%0A    %22%22%22%0A%0A    epochcmp = rpmvercmp(a.epoch, b.epoch)%0A    if epochcmp != 0:%0A        return epochcmp%0A%0A    vercmp = rpmvercmp(a.version, b.version)%0A    if vercmp != 0:%0A        return vercmp%0A%0A    relcmp = rpmvercmp(a.release, b.release)%0A    if relcmp != 0:%0A        return relcmp%0A%0A    return 0%0A

convert srpmToConaryVersion to using package objects add function for comparing package objects