Package rosdeb :: Module repo
[frames] | no frames]

Source Code for Module rosdeb.repo

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2010, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  # 
 10  #  * Redistributions of source code must retain the above copyright 
 11  #    notice, this list of conditions and the following disclaimer. 
 12  #  * Redistributions in binary form must reproduce the above 
 13  #    copyright notice, this list of conditions and the following 
 14  #    disclaimer in the documentation and/or other materials provided 
 15  #    with the distribution. 
 16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 17  #    contributors may be used to endorse or promote products derived 
 18  #    from this software without specific prior written permission. 
 19  # 
 20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  # POSSIBILITY OF SUCH DAMAGE. 
 32  # 
 33  # Revision $Id: repo.py 16975 2012-09-03 05:02:44Z tfoote $ 
 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   
44 -class BadRepo(Exception): pass
45 46 _Packages_cache = {}
47 -def get_Packages(repo_url, os_platform, arch, cache=None):
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 # this is very bad. This script is assuming the layout of the 58 # repo has a subdirectory ubuntu. I can't parameterize it out 59 # without potentially breaking a lot. Using an if statement to get 60 # it to work. 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
74 -def parse_Packages(packagelist):
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
96 -def load_Packages(repo_url, os_platform, arch, cache=None):
97 """ 98 Download and parse debian Packages list into (package, version, depends) tuples 99 """ 100 return parse_Packages(get_Packages(repo_url, os_platform, arch, cache))
101
102 -def get_repo_version(repo_url, distro, os_platform, arch):
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 # There is probably something much simpler we could do, but this 127 # more robust to any bad state we may have caused to the shadow 128 # repo. 129 package_deps = load_Packages(repo_url, os_platform, arch) 130 done = False 131 queue = [deb_name] 132 depends = set() 133 # This is not particularly efficient, but it does not need to 134 # be. Basically, we find all the packages that depend on the 135 # package, then find all the packages that depends on those, 136 # etc... 137 while queue: 138 next = queue[0] 139 queue = queue[1:] 140 for package, _, deps, _ in package_deps: 141 #strip of version specifications from deps 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
148 -def get_stack_version(packageslist, distro_name, stack_name):
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