def have_deb(name, comparator=None, version=None): comparatorDict = {'<=':operator.le, '==':operator.eq, '>=':operator.ge, '!=':operator.ne} cmp = lambda x, y, z: z(StrictVersion(x),StrictVersion(y)) #print "have_deb: %s , %s, %s" % (name, comparator, version) devnull = open(os.devnull,"w") notfound = subprocess.call(["dpkg","-s",name],stdout=devnull,stderr=subprocess.STDOUT) devnull.close() if notfound: return False; a = shellexec(["dpkg","-s",name]); m = re.search(r'Version: (\d+:)?([0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+).*\n', a); # print "MATCH:" + "1" + str( m.group(1) ) + "2" + str( m.group(2) ) if(m): #print "Deb Version: " + m.group(2); if not comparator: return True try: if cmp(m.group(2), version, comparatorDict[comparator]): if comparator == '==': logger.info("have_deb: Satisfies requirement...installed version of %s (%s) is %s" % (name, m.group(2), version)) else: logger.info("have_deb: Satisfies requirement...installed version of %s (%s) is %s than %s" % (name, m.group(2), comparator, version)) return True else: if comparator == '==': logger.warning("have_deb: Does not satisfy requirement...installed version of %s (%s) is not %s" % (name, m.group(2), version)) else: logger.warning("have_deb: Does not satisfy requirement...installed version of %s (%s) is not %s than %s" % (name, m.group(2), comparator, version)) return False except ValueError, e: logger.error("have_deb: fatal error: %s" % (e)) globals.die("Please check the recipe for %s" % (name))
def have_rpm(name, comparator=None, version=None): comparatorDict = {'<=':operator.le, '==':operator.eq, '>=':operator.ge, '!=':operator.ne} cmp = lambda x, y, z: z(StrictVersion(x),StrictVersion(y)) #print "have_rpm: %s , %s, %s" % (name, comparator, version) a = shellexec(["rpm","-q",name]); if(re.search(r'is not installed', a)): return False; #m = re.search(r'-([\d\.]+)', a); m = re.search(r'-([0-9]+\.[0-9]+\.*[0-9]*|[0-9]+[a-z]+).*\n', a) if(m): #print "RPM Version: " + m.group(1); if not comparator: return True try: if cmp(m.group(1), version, comparatorDict[comparator]): if comparator == '==': logger.info("have_rpm: Satisfies requirement...installed version of %s (%s) is %s" % (name, m.group(1), version)) else: logger.info("have_rpm: Satisfies requirement...installed version of %s (%s) is %s than %s" % (name, m.group(1), comparator, version)) return True else: if comparator == '==': logger.warning("have_rpm: Does not satisfy requirement...installed version of %s (%s) is not %s" % (name, m.group(1), version)) else: logger.warning("have_rpm: Does not satisfy requirement...installed version of %s (%s) is not %s than %s" % (name, m.group(1), comparator, version)) return False except ValueError, e: logger.error("have_rpm: fatal error: %s" % (e)) globals.die("Please check the recipe for %s" % (name))
def rpm_exists(name, comparator=None, version=None): comparatorDict = {'<=':operator.le, '==':operator.eq, '>=':operator.ge, '!=':operator.ne} cmp = lambda x, y, z: z(StrictVersion(x),StrictVersion(y)) a = shellexec(["yum","info",name]) if len(a) == 0: logger.warning("rpm_exists: could not find a downloadable version of %s" % (name)) return False if re.search(r'No matching Packages to list', a): logger.warning("rpm_exists: could not find a downloadable version of %s" % (name)) return False m = re.search(r'Version *: (\d+:)?([0-9]+\.[0-9]+\.*[0-9]*|[0-9]+[a-z]+).*\n', a) if(m): if not comparator: logger.info("rpm_exists: Satisfies requirement...found downloadable version of %s" % (name)) return True try: if cmp(m.group(2), version, comparatorDict[comparator]): if comparator == '==': logger.info("rpm_exists: Satisfies requirement...downloadable version of %s (%s) is %s" % (name, m.group(2), version)) else: logger.info("rpm_exists: Satisfies requirement...downloadable version of %s (%s) is %s than %s" % (name, m.group(2), comparator, version)) return True else: if comparator == '==': logger.warning("rpm_exists: Does not satisfy requirement...downloadable version of %s (%s) is not %s" % (name, m.group(2), version)) else: logger.warning("rpm_exists: Does not satisfy requirement...downloadable version of %s (%s) is not %s than %s" % (name, m.group(2), comparator, version)) return False except ValueError, e: logger.error("rpm_exists: fatal error: %s" % (e)) globals.die("Please check the recipe for %s" % (name))
def deb_exists(name, comparator=None, version=None): comparatorDict = {"<=": operator.le, "==": operator.eq, ">=": operator.ge, "!=": operator.ne} cmp = lambda x, y, z: z(StrictVersion(x), StrictVersion(y)) a = shellexec(["apt-cache", "showpkg", name]) if len(a) == 0: logger.warning("deb_exists: could not find a downloadable version of %s" % (name)) return False if re.search(r"Unable to locate package", a): logger.warning("deb_exists: could not find a downloadable version of %s" % (name)) return False m = re.search(r"Versions: \n(\d+:)?([0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+).*\n", a) if m: if not comparator: logger.info("deb_exists: Satisfies requirement...found downloadable version of %s" % (name)) return True try: if cmp(m.group(2), version, comparatorDict[comparator]): if comparator == "==": logger.info( "deb_exists: Satisfies requirement...downloadable version of %s (%s) is %s" % (name, m.group(2), version) ) else: logger.info( "deb_exists: Satisfies requirement...downloadable version of %s (%s) is %s than %s" % (name, m.group(2), comparator, version) ) return True else: if comparator == "==": logger.warning( "deb_exists: Does not satisfy requirement...downloadable version of %s (%s) is not %s" % (name, m.group(2), version) ) else: logger.warning( "deb_exists: Does not satisfy requirement...downloadable version of %s (%s) is not %s than %s" % (name, m.group(2), comparator, version) ) return False except ValueError, e: logger.error("deb_exists: fatal error: %s" % (e)) globals.die("Please check the recipe for %s" % (name))
logger.info("deb_exists: Satisfies requirement...downloadable version of %s (%s) is %s" % (name, m.group(2), version)) else: logger.info("deb_exists: Satisfies requirement...downloadable version of %s (%s) is %s than %s" % (name, m.group(2), comparator, version)) return True else: if comparator == '==': logger.warning("deb_exists: Does not satisfy requirement...downloadable version of %s (%s) is not %s" % (name, m.group(2), version)) else: logger.warning("deb_exists: Does not satisfy requirement...downloadable version of %s (%s) is not %s than %s" % (name, m.group(2), comparator, version)) return False except ValueError, e: logger.error("deb_exists: fatal error: %s" % (e)) globals.die("Please check the recipe for %s" % (name)) else: return False print a; globals.die("This should be unreachable: in deb_exists()"); def rpm_exists(name, comparator=None, version=None): comparatorDict = {'<=':operator.le, '==':operator.eq, '>=':operator.ge, '!=':operator.ne} cmp = lambda x, y, z: z(StrictVersion(x),StrictVersion(y)) a = shellexec(["yum","info",name]) if len(a) == 0: logger.warning("rpm_exists: could not find a downloadable version of %s" % (name)) return False if re.search(r'No matching Packages to list', a): logger.warning("rpm_exists: could not find a downloadable version of %s" % (name)) return False m = re.search(r'Version *: (\d+:)?([0-9]+\.[0-9]+\.*[0-9]*|[0-9]+[a-z]+).*\n', a) if(m): if not comparator: