Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 53 additions & 50 deletions ketchup
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
#
# ketchup-1.1-beta2
# http://github.com/psomas/ketchup
# http://github.com/psomas/ketchup
# git://github.com/psomas/ketchup.git
#
# Orignial code by:
Expand All @@ -12,7 +12,7 @@
#
# Now maintained by:
# Stratos Psomadakis <psomas@cslab.ece.ntua.gr>
#
#
# Contributors:
# Baruch Even <baruch@debian.org>
# Pavel Machek <pavel@ucw.cz>
Expand Down Expand Up @@ -124,34 +124,37 @@ compress_types = {".bz2" : "bzcat", ".gz" : "gzcat", ".xz" : "xzcat", "" : "cat"

def tree(ver):
# every version must start with x.y, exit otherwise
t = re.match(r'((\d+)\.\d+)', ver)
t = re.match(r'((\d+)\.(\d+|x))', ver)
if t == None:
error("Invalid tree version!")
sys.exit(-1)

# linux versions >=3.0 use only the first digit to define the 'tree'
ret = int(t.group(2))
ret = int(t.group(2))
if ret >= 3:
return ret

# 2.x linux trees
# 2.x linux trees
return float(t.group(1))

def rev(ver):
p = pre(ver)

# 3.x trees
if tree(ver) >= 3:
r = re.match(r'\d+\.(\d+)', ver)
r = re.match(r'\d+\.(\d+|x)', ver)
# 2.x trees
else:
r = re.match(r'\d+\.\d+\.(\d+)', ver)

# if there's no match, the version is invalid
try: r = int(r.group(1))
except:
error("Invalid tree version!")
sys.exit(-1)
if r.group(1) == 'x':
return r.group(1)
else:
try: r = int(r.group(1))
except:
error("Invalid tree version!")
sys.exit(-1)

#for -rc versions return the previous stable version
if p: r = r - 1
Expand All @@ -160,7 +163,7 @@ def rev(ver):
if t == 2:
t = 2.6
r = last_minor(t)

return r

def pre(ver):
Expand All @@ -179,9 +182,9 @@ def post(ver):
if tree(ver) >= 3:
p = re.match(r'\d+\.\d+\.(\d+)', ver)
# 2.x trees
else:
else:
p = re.match(r'\d+\.\d+\.\d+\.(\d+)', ver)

try: return p.group(1)
except: return None

Expand All @@ -192,7 +195,7 @@ def prenum(ver):
# 2.x trees
else:
p = re.match(r'\d+\.\d+\.\d+(\.\d+)?-rc(\d+)', ver)

try: return p.group(2)
except: return None

Expand Down Expand Up @@ -232,7 +235,7 @@ def forkname(ver):
else:
f = re.match(r'\d+\.\d+\.\d+(\.\d+)?(-(rc|pre)\d+)?(-([a-zA-Z]+)(-)?(\d+)?)?',
ver)

try: return f.group(5)
except: return None

Expand Down Expand Up @@ -270,7 +273,7 @@ def get_ver(makefile):
for l in m.readlines():
for p in parts:
try: part[p] = re.match(r'%s\s*=\s*(\S+)' % p, l).group(1)
except:
except:
# get any other extra versions defined in the makefile (except
# kernel version)
v = re.match(r'(\S+VERSION)\s*=\s*(\S+)', l)
Expand All @@ -279,15 +282,15 @@ def get_ver(makefile):
extra[v.group(1)] = v.group(2)
except:
pass

if part['VERSION'] >= '3'and part['SUBLEVEL'] == '0':
version = "%s.%s" % tuple([part[p] for p in parts[:2]])
else:
version = "%s.%s.%s" % tuple([part[p] for p in parts[:3]])

for v in extra.keys():
version += extra.get(v, "")

version += get_localversion()

return version
Expand Down Expand Up @@ -358,7 +361,7 @@ def latest_dir_lt(url, pat):
'kernel_url': kernel_url,
'revbase' : revbase(lv)
}

url = url % s
for l in urllib.urlopen(url).readlines():
m = re.search('"%s"' % pat, l)
Expand All @@ -373,7 +376,7 @@ def latest_dir_lt(url, pat):
def find_www(url, pat, grp):
"""Parse the page the url is pointing to and fetch the matched items"""
p = []

for l in urllib.urlopen(url).readlines():
m = re.search('"%s"' % pat, l)
if m: p.append(m.group(grp))
Expand All @@ -387,16 +390,16 @@ def latest_dir(url, pat):
'kernel_url': kernel_url,
'full_tree': latest_major()
}

p = find_www(url % s, pat, 1)
if not p: return None

p.sort(compare_ver)
return p[-1]

def find_majors():
return find_www(kernel_url, '.*v(\d+\.\d+).*', 1)
def find_majors():
return find_www(kernel_url, '.*v(\d+\.(\d+|x)).*', 1)

def latest_major():
global lmajor
if lmajor == None:
Expand All @@ -415,7 +418,7 @@ def last_minor(t):
if maj not in minors:
url = kernel_url + ("/v%s" % maj)

p = map(int, find_www(url, ".*linux-%s\.(\d+)\.tar\.bz2" % t, 1))
p = map(int, find_www(url, ".*linux-%s\.(\d+)\.tar\.(bz2|xz|gz)" % t, 1))
p.sort()

if p:
Expand Down Expand Up @@ -457,7 +460,7 @@ def find_info(ver):
if ver != v[0](os.path.dirname(v[1])):
error("%s can only be applied to specific kernel versions" % s)
sys.exit(-1)

return version_info[s]

def full_tree(ver):
Expand All @@ -470,7 +473,7 @@ def full_tree(ver):
error("Invalid tree version!")
return t.group(0)


def version_urls(ver):
""" Return the URL for the patch associated with the specified version """
i = find_info(ver)[1]
Expand All @@ -479,7 +482,7 @@ def version_urls(ver):

v = {
'full': ver,
'tree': tree(ver) + .0,
'tree': str(tree(ver)) + ".x",
'base': base(ver),
'prebase': prebase(ver),
'fork': fork(ver),
Expand All @@ -491,15 +494,15 @@ def version_urls(ver):
l = []
for e in i:
l.append(e % v)

return l

def patch_path(ver):
patch_name = os.path.basename(version_urls(ver)[0])
if re.search(r'\d+\.\d+', patch_name) == None:
suf = re.search(r'\.tar\.(gz|(bz(\d+)?))', patch_name).group(0)
patch_name = re.sub(r'(\.tar\.(gz|(bz(\d+)?)))', "-%s%s" % (ver, suf), patch_name)

return os.path.join(archive, patch_name)

def download(url, f):
Expand Down Expand Up @@ -656,7 +659,7 @@ def apply_quilt(ver, reverse = 0):
os.chdir(old)
os.system("rm -rf patches")
sys.exit(-1)

os.system("mv broken-out/*.patch ./")

os.chdir(old)
Expand Down Expand Up @@ -736,14 +739,14 @@ def untar(tarfile):
def install_nearest(ver):
t = tree(ver)
if t == 2.4:
tarballs = glob.glob(archive + "/linux-%s.*.tar.bz2" % t)
else:
tarballs = glob.glob(archive + "/linux-2.6.*.tar.bz2")
tarballs += glob.glob(archive + "/linux-[3-9].*.tar.bz2")
tarballs = glob.glob(archive + "/linux-%s.*.tar.(bz2|xz)" % t)
else:
tarballs = glob.glob(archive + "/linux-2.6.*.tar.(bz2|xz)")
tarballs += glob.glob(archive + "/linux-[3-9].*.tar.(bz2|xz)")

list = []
for f in tarballs:
m = re.match(r'.*/linux-(.*).tar.bz2$', f)
m = re.match(r'.*/linux-(.*).tar.(bz2|xz)$', f)
v = m.group(1)
dt = tree(v) - tree(ver)
# if we're 2 'major' trees apart, just get the full tarball
Expand All @@ -766,7 +769,7 @@ def install_nearest(ver):
t += .0

if not list or (options["full-tarball"] and list[0][0]):
f = "linux-%s.tar.bz2" % ver
f = "linux-%s.tar.xz" % ver
url = "%s/v%s/%s" % (kernel_url, t, f)
url_longterm = "%s/v%s/longterm/v%s/%s" % (kernel_url, t, revbase(ver), f)
f = archive + "/" + f
Expand All @@ -793,7 +796,7 @@ def find_ver(ver):
if ver in version_info.keys():
v = version_info[ver]

d = v[1]
d = v[1]
if type(d) is not type([]):
d = [ d ]

Expand Down Expand Up @@ -826,12 +829,12 @@ def transform(a, b):

if post(a) and (post(a) != post(b) or rev(a) != rev(b)):
apply_patch(prebase(a), 1)

ra, rb = rev(a), rev(b)
ta, tb = tree(a), tree(b)
if tree(revbase(b)) != tb:
tb = tree(revbase(b))

if ta == tb and ra > rb:
for r in range(ra, rb, -1):
apply_patch("%s.%s" % (ta, r), -1)
Expand All @@ -846,7 +849,7 @@ def transform(a, b):

if t >= 3:
t += .0

for r in range(last_minor(t), rb, -1):
apply_patch("%s.%s" % (tb, r), -1)
if tb > ta:
Expand Down Expand Up @@ -895,18 +898,18 @@ version_info = {
r'patch-(.*?).bz2',
1, "2.4 kernel series"),
'linux-next': (latest_dir,
"%(kernel_url)s" + "/v2.6/next" + "/patch-v%(prebase)s%(fork)s.bz2",
r'patch-v(.*?).bz2',
"%(kernel_url)s" + "/v2.6/next" + "/patch-v%(prebase)s%(fork)s.xz",
r'patch-v(.*?).xz',
1, "linux-next tree"),
'linux-rc': (latest_dir,
[ "%(kernel_url)s" + "/v%(tree)s" + "/testing/patch-%(prebase)s.bz2",
"%(kernel_url)s" + "/v%(tree)s" + "/testing/v%(full_tree)s/patch-%(prebase)s.bz2"],
r'patch-(.*?).bz2',
[ "%(kernel_url)s" + "/v%(tree)s" + "/testing/patch-%(prebase)s.xz",
"%(kernel_url)s" + "/v%(tree)s" + "/testing/v%(full_tree)s/patch-%(prebase)s.xz"],
r'patch-(.*?).xz',
1, "current stable kernel series prereleases"),
'linux-lt': (latest_dir_lt,
["%(kernel_url)s" + "/v%(tree)s/longterm/v%(revbase)s/patch-%(prebase)s.bz2",
"%(kernel_url)s" + "/v%(tree)s" + "/patch-%(prebase)s.bz2"],
r'patch-(.*?).bz2',
["%(kernel_url)s" + "/v%(tree)s/longterm/v%(revbase)s/patch-%(prebase)s.xz",
"%(kernel_url)s" + "/v%(tree)s" + "/patch-%(prebase)s.xz"],
r'patch-(.*?).xz',
1, "longterm kernel series - update (only) to newer longterm stable releases"),
'linux': (latest_dir,
["%(kernel_url)s" + "/v%(tree)s" + "/patch-%(prebase)s.xz",
Expand Down