svn.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. """
  4. BitBake 'Fetch' implementations
  5. This implementation is for svn. It is based on the cvs implementation.
  6. """
  7. # Copyright (C) 2004 Marcin Juszkiewicz
  8. #
  9. # Classes for obtaining upstream sources for the
  10. # BitBake build tools.
  11. # Copyright (C) 2003, 2004 Chris Larson
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License version 2 as
  15. # published by the Free Software Foundation.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License along
  23. # with this program; if not, write to the Free Software Foundation, Inc.,
  24. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  25. #
  26. # Based on functions from the base bb module, Copyright 2003 Holger Schurig
  27. import os, re
  28. import sys
  29. import bb
  30. from bb import data
  31. from bb.fetch import Fetch
  32. from bb.fetch import FetchError
  33. from bb.fetch import MissingParameterError
  34. class Svn(Fetch):
  35. """Class to fetch a module or modules from svn repositories"""
  36. def supports(self, url, ud, d):
  37. """
  38. Check to see if a given url can be fetched with svn.
  39. """
  40. return ud.type in ['svn']
  41. def localpath(self, url, ud, d):
  42. if not "module" in ud.parm:
  43. raise MissingParameterError("svn method needs a 'module' parameter")
  44. else:
  45. ud.module = ud.parm["module"]
  46. ud.revision = ""
  47. if 'rev' in ud.parm:
  48. ud.revision = ud.parm['rev']
  49. if ud.revision:
  50. ud.date = ""
  51. ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
  52. return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
  53. def forcefetch(self, url, ud, d):
  54. if (ud.date == "now"):
  55. return True
  56. return False
  57. def go(self, loc, ud, d):
  58. """Fetch url"""
  59. # try to use the tarball stash
  60. if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile):
  61. bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % ud.localpath)
  62. return
  63. proto = "svn"
  64. if "proto" in ud.parm:
  65. proto = ud.parm["proto"]
  66. svn_rsh = None
  67. if proto == "svn+ssh" and "rsh" in ud.parm:
  68. svn_rsh = ud.parm["rsh"]
  69. svnroot = ud.host + ud.path
  70. # either use the revision, or SRCDATE in braces, or nothing for SRCDATE = "now"
  71. options = []
  72. if ud.revision:
  73. options.append("-r %s" % ud.revision)
  74. elif ud.date != "now":
  75. options.append("-r {%s}" % ud.date)
  76. localdata = data.createCopy(d)
  77. data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata)
  78. data.update_data(localdata)
  79. data.setVar('SVNROOT', "%s://%s/%s" % (proto, svnroot, ud.module), localdata)
  80. data.setVar('SVNCOOPTS', " ".join(options), localdata)
  81. data.setVar('SVNMODULE', ud.module, localdata)
  82. svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
  83. svnupcmd = data.getVar('UPDATECOMMAND', localdata, 1)
  84. if svn_rsh:
  85. svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
  86. svnupcmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svnupcmd)
  87. pkg = data.expand('${PN}', d)
  88. pkgdir = os.path.join(data.expand('${SVNDIR}', localdata), pkg)
  89. moddir = os.path.join(pkgdir, ud.module)
  90. bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + moddir + "'")
  91. if os.access(os.path.join(moddir, '.svn'), os.R_OK):
  92. bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
  93. # update sources there
  94. os.chdir(moddir)
  95. bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupcmd)
  96. myret = os.system(svnupcmd)
  97. else:
  98. bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
  99. # check out sources there
  100. bb.mkdirhier(pkgdir)
  101. os.chdir(pkgdir)
  102. bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svncmd)
  103. myret = os.system(svncmd)
  104. if myret != 0:
  105. raise FetchError(ud.module)
  106. os.chdir(pkgdir)
  107. # tar them up to a defined filename
  108. myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)))
  109. if myret != 0:
  110. try:
  111. os.unlink(ud.localpath)
  112. except OSError:
  113. pass
  114. raise FetchError(ud.module)