summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xclient/bin/kernel_config.py4
-rwxr-xr-xclient/common_lib/kernel_versions.py113
-rwxr-xr-xtko/compose_query.cgi2
-rwxr-xr-xtko/frontend.py7
-rwxr-xr-xtko/machine_aggr.cgi2
-rwxr-xr-xtko/machine_test_attribute_graph.cgi2
6 files changed, 121 insertions, 9 deletions
diff --git a/client/bin/kernel_config.py b/client/bin/kernel_config.py
index 2ceaad76..58ab3a32 100755
--- a/client/bin/kernel_config.py
+++ b/client/bin/kernel_config.py
@@ -2,8 +2,8 @@
# the repo.
import shutil, os
-from autotest_lib.client.bin import utils, kernel_versions
-from autotest_lib.client.common_lib import error
+from autotest_lib.client.bin import utils
+from autotest_lib.client.common_lib import error, kernel_versions
def apply_overrides(orig_file, changes_file, output_file):
override = dict()
diff --git a/client/common_lib/kernel_versions.py b/client/common_lib/kernel_versions.py
new file mode 100755
index 00000000..1b796c14
--- /dev/null
+++ b/client/common_lib/kernel_versions.py
@@ -0,0 +1,113 @@
+#
+# kernel_versions.py -- linux kernel version comparisons
+#
+__author__ = """Copyright Andy Whitcroft 2007"""
+
+import sys,re
+
+#
+# Sort key for ordering versions chronologically. The key ordering
+# problem is between that introduced by -rcN. These come _before_
+# their accompanying version.
+#
+# 2.6.0 -> 2.6.1-rc1 -> 2.6.1
+#
+# In order to sort them we convert all non-rc releases to a pseudo
+# -rc99 release. We also convert all numbers to two digits. The
+# result is then sortable textually.
+#
+# 02.06.00-rc99 -> 02.06.01-rc01 -> 02.06.01-rc99
+#
+encode_sep = re.compile(r'(\D+)')
+
+def version_encode(version):
+ bits = encode_sep.split(version)
+ n = 9
+ if len(bits[0]) == 0:
+ n += 2
+ if len(bits) == n or (len(bits) > n and bits[n] != '_rc'):
+ # Insert missing _rc99 after 2 . 6 . 18 -smp- 220 . 0
+ bits.insert(n, '_rc')
+ bits.insert(n+1, '99')
+ n = 5
+ if len(bits[0]) == 0:
+ n += 2
+ if len(bits) <= n or bits[n] != '-rc':
+ bits.insert(n, '-rc')
+ bits.insert(n+1, '99')
+ for n in range(0, len(bits), 2):
+ if len(bits[n]) == 1:
+ bits[n] = '0' + bits[n]
+
+ return ''.join(bits)
+
+
+def version_limit(version, n):
+ bits = encode_sep.split(version)
+ return ''.join(bits[0:n])
+
+
+def version_len(version):
+ return len(encode_sep.split(version))
+
+#
+# Given a list of versions find the nearest version which is deemed
+# less than or equal to the target. Versions are in linux order
+# as follows:
+#
+# 2.6.0 -> 2.6.1 -> 2.6.2-rc1 -> 2.6.2-rc2 -> 2.6.2 -> 2.6.3-rc1
+# | |\
+# | | 2.6.2-rc1-mm1 -> 2.6.2-rc1-mm2
+# | \
+# | 2.6.2-rc1-ac1 -> 2.6.2-rc1-ac2
+# \
+# 2.6.1-mm1 -> 2.6.1-mm2
+#
+# Note that a 2.6.1-mm1 is not a predecessor of 2.6.2-rc1-mm1.
+#
+def version_choose_config(version, candidates):
+ # Check if we have an exact match ... if so magic
+ if version in candidates:
+ return version
+
+ # Sort the search key into the list ordered by 'age'
+ deco = [ (version_encode(v), i, v) for i, v in
+ enumerate(candidates + [ version ]) ]
+ deco.sort()
+ versions = [ v for _, _, v in deco ]
+
+ # Everything sorted below us is of interst.
+ for n in range(len(versions) - 1, -1, -1):
+ if versions[n] == version:
+ break
+ n -= 1
+
+ # Try ever shorter 'prefixes' 2.6.20-rc3-mm, 2.6.20-rc, 2.6. etc
+ # to match against the ordered list newest to oldest.
+ length = version_len(version) - 1
+ version = version_limit(version, length)
+ while length > 1:
+ for o in range(n, -1, -1):
+ if version_len(versions[o]) == (length + 1) and \
+ version_limit(versions[o], length) == version:
+ return versions[o]
+ length -= 2
+ version = version_limit(version, length)
+
+ return None
+
+
+def is_released_kernel(version):
+ # True if version name suggests a released kernel,
+ # not some release candidate or experimental kernel name
+ # e.g. 2.6.18-smp-200.0 includes no other text, underscores, etc
+ version = version.strip('01234567890.-')
+ return version in ['', 'smp', 'smpx', 'pae']
+
+
+def is_release_candidate(version):
+ # True if version names a released kernel or release candidate,
+ # not some experimental name containing arbitrary text
+ # e.g. 2.6.18-smp-220.0_rc3 but not 2.6.18_patched
+ version = re.sub(r'[_-]rc\d+', '', version)
+ return is_released_kernel(version)
diff --git a/tko/compose_query.cgi b/tko/compose_query.cgi
index 0184c43b..b8bb301d 100755
--- a/tko/compose_query.cgi
+++ b/tko/compose_query.cgi
@@ -14,7 +14,7 @@ total_wall_time_start = time.time()
import common
from autotest_lib.tko import display, frontend, db, query_lib
-from autotest_lib.client.bin import kernel_versions
+from autotest_lib.client.common_lib import kernel_versions
html_header = """\
<form action="/tko/compose_query.cgi" method="get">
diff --git a/tko/frontend.py b/tko/frontend.py
index 70ee2fc7..d9aff027 100755
--- a/tko/frontend.py
+++ b/tko/frontend.py
@@ -1,13 +1,12 @@
#!/usr/bin/python
import os, re, db, sys, datetime
+import common
+from autotest_lib.client.common_lib import kernel_versions
+
MAX_RECORDS = 50000L
MAX_CELLS = 500000L
tko = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
-client_bin = os.path.abspath(os.path.join(tko, '../client/bin'))
-sys.path.insert(0, client_bin)
-import kernel_versions
-
root_url_file = os.path.join(tko, '.root_url')
if os.path.exists(root_url_file):
html_root = open(root_url_file, 'r').readline().rstrip()
diff --git a/tko/machine_aggr.cgi b/tko/machine_aggr.cgi
index 4d3b97bb..b45dfd1f 100755
--- a/tko/machine_aggr.cgi
+++ b/tko/machine_aggr.cgi
@@ -8,7 +8,7 @@ Popen = subprocess.Popen
import common
from autotest_lib.tko import db, display, frontend, plotgraph
-from autotest_lib.client.bin import kernel_versions
+from autotest_lib.client.common_lib import kernel_versions
released_kernel = re.compile('2\.\d\.\d+(-smp-)[0-9]{3}\.[0-9]$')
rc_kernel = re.compile('2\.\d\.\d+(-smp-)[0-9]{3}\.[0-9]_rc[0-9]$')
diff --git a/tko/machine_test_attribute_graph.cgi b/tko/machine_test_attribute_graph.cgi
index e9b39fe0..1f5b8b3a 100755
--- a/tko/machine_test_attribute_graph.cgi
+++ b/tko/machine_test_attribute_graph.cgi
@@ -8,7 +8,7 @@ Popen = subprocess.Popen
import common
from autotest_lib.tko import db, display, frontend, plotgraph
-from autotest_lib.client.bin import kernel_versions
+from autotest_lib.client.common_lib import kernel_versions
db = db.db()