8 import elementtree
.ElementTree
as ET
10 import xml
.etree
.ElementTree
as ET
12 from version
import Version
14 from PPARequest
import PPARequest
19 LOCAL_GIT_REPOS_PATH
= os
.path
.join(config
.check_versions_dir
, 'git')
21 class Component(object):
23 def __init__(self
, name
):
26 self
.upstream
= self
._get
_upstream
_version
()
27 self
.ubuntu
= self
._get
_ubuntu
_versions
()
28 self
.debian
= self
._get
_debian
_versions
()
29 self
.jhbuild
= self
._get
_jhbuild
_versions
()
31 if Component
.ppa_enabled():
32 self
.ppa
= self
._get
_ppa
_versions
()
36 def _get_upstream_version(self
):
39 def _get_jhbuild_versions(self
):
40 module_set
= JhbuildModulesetCache
.get_module_set()
41 for child
in module_set
.getchildren():
42 if child
.attrib
.get('id') != self
.name
:
44 if child
.attrib
.get('version'):
45 return {'trunk': Version(child
.attrib
.get('version'))}
46 return {'trunk': Version(child
.find('branch').attrib
.get('version'))}
49 def _get_ubuntu_versions(self
):
50 return self
._rmadison
('ubuntu')
52 def _get_debian_versions(self
):
53 return self
._rmadison
('debian')
55 def _rmadison(self
, distro
):
57 (s
, o
) = commands
.getstatusoutput('rmadison -u %s %s' % (distro
, self
.name
))
59 for l
in o
.split('\n'):
61 pkg
, ver
, distro
, archi
= l
.split('|')
66 distro
= distro
.strip()
67 distro
= distro
.split('/')[0]
69 versions
[distro
] = Version(ver
, debian
=True)
73 def _get_ppa_versions(self
):
74 return PPARequest().query(self
.name
)
81 return 'CHECK_VERSION_LAUNCHPAD' in os
.environ
and PPARequest
is not None
83 class HttpComponent(Component
):
84 def __init__(self
, name
, repo
):
87 Component
.__init
__(self
, name
)
89 def _get_upstream_version(self
):
90 # FIXME: there is probably a better regexp
91 reg_exp
= re
.compile('%s-.*(?=.tar.gz">)' % self
.name
)
92 listing
= urllib2
.urlopen(self
.repo
)
95 for release
in reg_exp
.findall(listing
.read()):
96 version
= re
.split('%s-' % self
.name
, release
)[1]
97 versions
.append(Version(version
))
101 class GitComponent(Component
):
102 def __init__(self
, name
, remote_repo
):
103 self
.remote_repo
= remote_repo
104 self
.local_repo_path
= os
.path
.join(LOCAL_GIT_REPOS_PATH
, name
)
106 if os
.path
.exists(self
.local_repo_path
):
108 os
.chdir(self
.local_repo_path
)
109 commands
.getstatusoutput('git pull')
110 self
.local_repo
= git
.Repo(self
.local_repo_path
)
112 self
.local_repo
= self
._clone
_repo
()
114 Component
.__init
__(self
, name
)
116 def _clone_repo(self
):
117 if not os
.path
.exists(LOCAL_GIT_REPOS_PATH
):
118 print "create", LOCAL_GIT_REPOS_PATH
119 os
.makedirs(LOCAL_GIT_REPOS_PATH
)
121 print "clone", self
.remote_repo
122 cmd
= 'git clone %s %s' % (self
.remote_repo
, self
.local_repo_path
)
123 status
, out
= commands
.getstatusoutput(cmd
)
125 return git
.Repo(self
.local_repo_path
)
127 def _get_upstream_version(self
):
130 for tag
in self
.local_repo
.tags
:
132 version
= tag
.name
.rsplit('-', 1)[1]
134 # assume '_' is used to separate version (as Empathy does)
135 # FIXME: this is horrible
136 version
= tag
.name
.split('_', 1)[1]
137 version
= version
.replace('_', '.')
139 versions
.append(Version(version
))
143 class TelepathyComponent(HttpComponent
):
144 def __init__(self
, name
):
145 repo
= 'http://telepathy.freedesktop.org/releases/%s' % name
147 HttpComponent
.__init
__(self
, name
, repo
)
149 class FarsightComponent(HttpComponent
):
150 def __init__(self
, name
):
151 repo
= 'http://farsight.freedesktop.org/releases/%s' % name
153 HttpComponent
.__init
__(self
, name
, repo
)
155 class NiceComponent(HttpComponent
):
156 def __init__(self
, name
):
157 repo
= 'http://nice.freedesktop.org/releases/'
159 HttpComponent
.__init
__(self
, name
, repo
)
162 class JhbuildModulesetCache
:
164 def get_module_set(cls
):
166 return cls
.module_set
167 external_deps
= urllib2
.urlopen('http://svn.gnome.org/svn/jhbuild/trunk/modulesets/gnome-external-deps-2.26.modules').read()
168 module_set
= ET
.fromstring(external_deps
)
169 cls
.module_set
= module_set
171 get_module_set
= classmethod(get_module_set
)
173 if __name__
== '__main__':
175 print comp
, comp
.upstream
, comp
.ubuntu
, comp
.debian
, comp
.ppa
, comp
.jhbuild
177 display(TelepathyComponent('telepathy-gabble'))
178 display(FarsightComponent('farsight2'))
179 display(NiceComponent('libnice'))
180 display(GitComponent('telepathy-sofiasip', 'git://git.collabora.co.uk/git/telepathy-sofiasip.git'))
181 display(GitComponent('empathy', 'git://git.collabora.co.uk/git/empathy.git'))