diff options
author | Mihai Ibanescu <misa@redhat.com> | 2006-05-04 18:55:31 -0400 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2006-05-04 18:55:31 -0400 |
commit | 48cf03916eb198e1b5a11c3e110c4d32787789fc (patch) | |
tree | 76288e07f2365910eba6d5b9be990dd845aaa22c | |
parent | bd4e362ebf0f5759263ce86531fbb01dd2fec1e4 (diff) | |
download | third_party-cobbler-48cf03916eb198e1b5a11c3e110c4d32787789fc.tar.gz third_party-cobbler-48cf03916eb198e1b5a11c3e110c4d32787789fc.tar.xz third_party-cobbler-48cf03916eb198e1b5a11c3e110c4d32787789fc.zip |
Comparison function is simpler, and no need to sort when we need max
reduce is a nice way to extract the max of a sequence.
-rw-r--r-- | cobbler/util.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/cobbler/util.py b/cobbler/util.py index cdf7bbe..ae7dde7 100644 --- a/cobbler/util.py +++ b/cobbler/util.py @@ -83,25 +83,25 @@ class BootUtil: """ files = self.find_matching_files(directory, regex) get_numbers = re.compile(r'(\d+).(\d+).(\d+)') - def sort(a,b): + def max2(a, b): + """Returns the larger of the two values""" av = get_numbers.search(os.path.basename(a)).groups() bv = get_numbers.search(os.path.basename(b)).groups() - if av[0]<bv[0]: return -1 - elif av[0]>bv[0]: return 1 - elif av[1]<bv[1]: return -1 - elif av[1]>bv[1]: return 1 - elif av[2]<bv[2]: return -1 - elif av[2]>bv[2]: return 1 - return 0 + + ret = cmp(av[0], bv[0]) or cmp(av[1], bv[1]) or cmp(av[2], bv[2]) + if ret < 0: + return b + return a + if len(files) > 0: - return sorted(files, sort)[-1] - else: - # couldn't find a highest numbered file, but maybe there - # is just a 'vmlinuz' or an 'initrd.img' in this directory? - last_chance = os.path.join(directory,unversioned) - if os.path.exists(last_chance): - return last_chance - return None + return reduce(max2, files) + + # couldn't find a highest numbered file, but maybe there + # is just a 'vmlinuz' or an 'initrd.img' in this directory? + last_chance = os.path.join(directory,unversioned) + if os.path.exists(last_chance): + return last_chance + return None def find_kernel(self,path): |