compat: fix ckmake to skip same base kernels
authorLuis R. Rodriguez <mcgrof@do-not-panic.com>
Fri, 15 Mar 2013 02:05:47 +0000 (19:05 -0700)
committerLuis R. Rodriguez <mcgrof@do-not-panic.com>
Fri, 15 Mar 2013 02:07:46 +0000 (19:07 -0700)
The ckmake script was allowing testing of compilation
of kernels even if the base kernels were the same. This
fixes it to skip them, trimming down test kernel compilation
down and not caring what old kernels you keep on your
system. This also now prints the RC release correctly.

The get_rel_spec() routine is based on the rel-html
get_rel_spec() routine and rel-html is AGPL but since
I wrote it I relicense a modified version of that
routine here to GPLv2.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
bin/ckmake

index 3d30bee84914ba4bd40026fed015699d081b92c3..cd9741aed9a3c9b772485a6cfeb4c5d3305952a5 100755 (executable)
@@ -185,6 +185,62 @@ def sig_handler(signal, frame):
        clean()
        sys.exit(-2)
 
+def get_rel_spec(rel):
+       if ("rc" in rel):
+               m = re.match(r"v*(?P<VERSION>\d+)\.+" \
+                            "(?P<PATCHLEVEL>\d+)[.]+" \
+                            "(?P<SUBLEVEL>\d+)[-]+" \
+                            "\d+rc(?P<EXTRAVERSION>\d+)\-*",
+                            rel)
+       else:
+               m = re.match(r"v*(?P<VERSION>\d+)\.+" \
+                            "(?P<PATCHLEVEL>\d+)[.]+" \
+                            "(?P<SUBLEVEL>\d+)[-]+" \
+                            "(?P<EXTRAVERSION>\d+)\-*",
+                              rel)
+        if (not m):
+                return m
+        rel_specs = m.groupdict()
+        return rel_specs
+
+def krel_same_base(new_rel, rel):
+       if (int(new_rel['ver']) != int(rel['ver'])):
+               return False
+       if (int(new_rel['pat']) != int(rel['pat'])):
+               return False
+       if (int(new_rel['ver']) == 3):
+               return True
+       if (int(new_rel['ver']) != 2):
+               return False
+       if (int(new_rel['sub']) == int(rel['sub'])):
+               return True
+       return False
+
+def krel_base_update(new_rel, rel):
+       if (not krel_same_base(new_rel, rel)):
+               return False
+       if (int(new_rel['sub']) > int(rel['sub'])):
+               return True
+       if (int(new_rel['sub']) < int(rel['sub'])):
+               return False
+
+       # Too lazy to deal with 2.x kernels,
+       if (not new_rel['is_rc']):
+               return False
+
+       if (int(new_rel['ext']) <= int(rel['ext'])):
+               return False
+       return True
+
+def krel_base_smaller(new_rel, rel):
+       if (not krel_same_base(new_rel, rel)):
+               return False
+       if (int(new_rel['sub']) > int(rel['sub'])):
+               return False
+       if (int(new_rel['sub']) < int(rel['sub'])):
+               return True
+       return False
+
 class kernel_set():
        def __init__(self, stdscr):
                self.queue = Queue()
@@ -221,38 +277,47 @@ class kernel_set():
                self.lock.acquire()
                self.stdscr.refresh()
                self.lock.release()
+       def evaluate_new_rel(self, new_rel):
+               for rel in self.releases:
+                       if (krel_base_update(new_rel, rel)):
+                               new_rel['idx'] = rel['idx']
+                               self.releases.remove(rel)
+                               break
+                       if (krel_base_smaller(new_rel, rel)):
+                               return
+               self.releases.insert(new_rel['idx'], new_rel)
        def parse_releases(self):
                for dirname, dirnames, filenames in os.walk(modules):
                        dirnames.sort()
                        for subdirname in dirnames:
-                               m = re.match(r"v*(?P<VERSION>\w+.)" \
-                                            "(?P<PATCHLEVEL>\w+.*)" \
-                                            "(?P<SUBLEVEL>\w*)" \
-                                            "(?P<EXTRAVERSION>[.-]\w*)" \
-                                            "(?P<RELMOD>[-]\w*).*", \
-                                            subdirname)
-                               if not m:
+                               specifics = get_rel_spec(subdirname)
+                               if (not specifics):
                                        continue
+                               rc = False
 
-                               specifics = m.groupdict()
-
-                               ver = specifics['VERSION'] + \
-                                     specifics['PATCHLEVEL'] + \
-                                     specifics['SUBLEVEL']
+                               ver = specifics['VERSION'] + '.' + \
+                                     specifics['PATCHLEVEL']
 
-                               for rel in self.releases:
-                                       if (rel['version'] == ver):
-                                               continue
+                               if ("rc" in subdirname):
+                                       rc = True
+                                       ver = ver + '-rc' + specifics['EXTRAVERSION']
+                               else:
+                                       ver = ver + '.' + specifics['SUBLEVEL']
 
                                rel = dict(idx=len(self.releases),
                                           name=subdirname,
                                           full_path=dirname + '/' +
-                                                    subdirname,
+                                                        subdirname,
                                           version=ver,
+                                          is_rc = rc,
+                                          ver=specifics['VERSION'],
+                                          pat=specifics['PATCHLEVEL'],
+                                          sub=specifics['SUBLEVEL'],
+                                          ext=specifics['EXTRAVERSION'],
                                           processed=False,
                                           log='',
                                           status=1234)
-                               self.releases.insert(rel['idx'], rel)
+                               self.evaluate_new_rel(rel)
                self.refresh()
        def setup_screen(self):
                for i in range(0, len(self.releases)):