2 # -*- coding: utf-8 -*-
4 # Copyright (C) 2015 - Michael Jeanson <mjeanson@efficios.com>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 """ This script is used to """
23 from distutils
.version
import Version
28 class KernelVersion(Version
):
29 """ Kernel version class """
31 re26
= re
.compile(r
'^(2\.\d+) \. (\d+) (\. (\d+))? (\-rc(\d+))?$',
33 re30
= re
.compile(r
'^(\d+) \. (\d+) (\. (\d+))? (\-rc(\d+))?$', re
.VERBOSE
)
36 def __init__(self
, vstring
=None):
43 def parse(self
, vstring
):
44 """ Parse version string """
46 self
._vstring
= vstring
48 if self
._vstring
.startswith("2"):
49 match
= self
.re26
.match(self
._vstring
)
51 match
= self
.re30
.match(self
._vstring
)
54 raise ValueError("invalid version number '%s'" % self
._vstring
)
56 (major
, minor
, patch
, rc_num
) = match
.group(1, 2, 4, 6)
58 major
= int(float(major
) * 10)
61 self
._version
= tuple(map(int, [major
, minor
, patch
]))
63 self
._version
= tuple(map(int, [major
, minor
])) + (0,)
66 self
._rc
= int(rc_num
)
72 """ Is this version an RC """
73 return self
._rc
is not None
81 return "KernelVersion ('%s')" % str(self
)
84 def _cmp(self
, other
):
85 if isinstance(other
, str):
86 other
= KernelVersion(other
)
88 if self
._version
!= other
._version
:
89 # numeric versions don't match
90 # prerelease stuff doesn't matter
91 if self
._version
< other
._version
:
97 # case 1: neither has rc; they're equal
98 # case 2: self has rc, other doesn't; other is greater
99 # case 3: self doesn't have rc, other does: self is greater
100 # case 4: both have rc: must compare them!
102 if (not self
._rc
and not other
._rc
):
104 elif (self
._rc
and not other
._rc
):
106 elif (not self
._rc
and other
._rc
):
108 elif (self
._rc
and other
._rc
):
109 if self
._rc
== other
._rc
:
111 elif self
._rc
< other
._rc
:
116 assert False, "never get here"
121 KERNCUTOFF
= KernelVersion("2.6.36")
123 LINUX_GIT
= "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
124 LINUX_PATH
= "/home/mjeanson/tmp/toto/"
134 # Open or create the local repository
135 if os
.path
.isdir(LINUX_PATH
):
136 linux_repo
= Repo(LINUX_PATH
)
138 linux_repo
= Repo
.clone_from(LINUX_GIT
, LINUX_PATH
)
141 linux_repo
.remote().pull()
143 # First get all valid versions
144 for tag
in linux_repo
.tags
:
146 version
= KernelVersion(tag
.name
.lstrip('v'))
148 # Add only those who are superior to the cutoff version
149 if version
>= KERNCUTOFF
:
150 versions
.append(version
)
155 # Sort the list by version order
158 # Keep only one rc if it's the latest version
160 for version
in reversed(versions
):
161 if version
.isrc() and not last
:
162 versions
.remove(version
)
165 #for version in versions:
171 for version
in versions
:
172 yversions
.append(version
.__str
__())
174 print(yaml
.dump(yversions
, default_flow_style
=False))
179 if __name__
== "__main__":
This page took 0.032818 seconds and 5 git commands to generate.