1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 """
36 Utilities for reading state from a debian repo
37 """
38
39 import urllib2
40 import re
41
42 from .core import debianize_name
43
45
46 _Packages_cache = {}
48 """
49 Retrieve the package list from the shadow repo. This routine
50 utilizes a cache and should not be invoked in long-running
51 processes.
52 @raise BadRepo: if repo does not exist
53 """
54 if cache is None:
55 cache = _Packages_cache
56
57
58
59
60
61 if 'packages.ros.org/ros' in repo_url or 'shadow' in repo_url:
62 packages_url = repo_url + '/ubuntu/dists/%(os_platform)s/main/binary-%(arch)s/Packages'%locals()
63 else:
64 packages_url = repo_url + '/dists/%(os_platform)s/main/binary-%(arch)s/Packages'%locals()
65 if packages_url in cache:
66 return cache[packages_url]
67 else:
68 try:
69 cache[packages_url] = retval = urllib2.urlopen(packages_url).read()
70 except urllib2.HTTPError:
71 raise BadRepo("[%s]: %s"%(repo_url, packages_url))
72 return retval
73
75 """
76 Parse debian Packages list into (package, version, depends) tuples
77 @return: parsed tuples or None if packagelist is None
78 """
79 package_deps = []
80 package = deps = version = distro = None
81 for l in packagelist.split('\n'):
82 if l.startswith('Package: '):
83 package = l[len('Package: '):]
84 elif l.startswith('Version: '):
85 version = l[len('Version: '):]
86 elif l.startswith('Depends: '):
87 deps = l[len('Depends: '):].split(',')
88 deps = [d.strip() for d in deps]
89 elif l.lower().startswith('wg-rosdistro: '):
90 distro = l[len('wg-rosdistro: '):]
91 if package != None and version != None and deps != None and distro != None:
92 package_deps.append((package, version, deps, distro))
93 package = version = deps = distro = None
94 return package_deps
95
101
103 """
104 Return the greatest build-stamp for any deb in the repository
105 """
106 packagelist = load_Packages(repo_url, os_platform, arch)
107 return max(['0'] + [x[1][x[1].find('-')+1:x[1].find('~')] for x in packagelist if x[3] == distro.release_name])
108
109 -def deb_in_repo(repo_url, deb_name, deb_version, os_platform, arch, use_regex=True, cache=None):
110 """
111 @param cache: dictionary to store Packages list for caching
112 """
113 packagelist = get_Packages(repo_url, os_platform, arch, cache)
114 if not use_regex:
115 s = 'Package: %s\nVersion: %s'%(deb_name, deb_version)
116 return s in packagelist
117 else:
118 M = re.search('^Package: %s\nVersion: %s$'%(deb_name, deb_version), packagelist, re.MULTILINE)
119 return M is not None
120
121 -def get_depends(repo_url, deb_name, os_platform, arch):
122 """
123 Get all debian package dependencies by scraping the Packages
124 list. We mainly use this for invalidation logic.
125 """
126
127
128
129 package_deps = load_Packages(repo_url, os_platform, arch)
130 done = False
131 queue = [deb_name]
132 depends = set()
133
134
135
136
137 while queue:
138 next = queue[0]
139 queue = queue[1:]
140 for package, _, deps, _ in package_deps:
141
142 deps = [d.split()[0] for d in deps]
143 if package not in depends and next in deps:
144 queue.append(package)
145 depends.add(package)
146 return list(depends)
147
149 """
150 Get the ROS version number of the stack in the repository
151 """
152 deb_name = "ros-%s-%s"%(distro_name, debianize_name(stack_name))
153 match = [vm for sm, vm, _, _ in packageslist if sm == deb_name]
154 if match:
155 return match[0].split('-')[0]
156 else:
157 return None
158