• attachment:unwrap_externals.py of Papers

Attachment 'unwrap_externals.py'

Download

   1 #!/usr/bin/env python
   2 
   3 import sys
   4 import subprocess
   5 
   6 NAME = 'unwrap_externals.py'
   7 USAGE = 'USAGE: %s [uri]'%NAME
   8 
   9 def unwrap_external(uri):
  10   cmd = ['svn', 'propget', 'svn:externals', uri]
  11   output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
  12   ret = []
  13   for l in output.split('\n'):
  14     if len(l) > 0:
  15       ls = l.split()
  16       r = None
  17       if len(ls) == 2:
  18         n, u = ls
  19       else:
  20         n, r, u = ls
  21         # r should be of the form -r123; extract the number
  22         if r[0:2] == '-r':
  23           r = r[2:]
  24       # Recurse
  25       sub_ret = unwrap_external(u)
  26       if sub_ret == []:
  27         ret.append([n,r,u])
  28       else:
  29         ret.extend(sub_ret)
  30   return ret
  31 
  32 def get_svn_revision_from_uri(uri):
  33   cmd = ['svn', 'info', uri]
  34   output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
  35   for l in output.split('\n'):
  36     if l.startswith('Revision'):
  37       rev = l.split()[1]
  38       return rev
  39   return None
  40 
  41 def write_rosconfig_file(entries):
  42   for n, r, u in entries:
  43     if r:
  44       rev = r
  45     else:
  46       rev = get_svn_revision_from_uri(u)
  47     print '- svn:'
  48     # Use the @ syntax, for archival purposes
  49     print '    uri: %s@%s'%(u, rev)
  50     print '    local-name: %s'%(n)
  51 
  52 if __name__ == '__main__':
  53   if len(sys.argv) != 2:
  54     print USAGE
  55     sys.exit(1)
  56 
  57   uri = sys.argv[1]
  58   entries = unwrap_external(uri)
  59   write_rosconfig_file(entries)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-09-27 20:55:43, 1.4 KB) [[attachment:unwrap_externals.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.