svk.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 svk. It is based on the svn implementation
  6. """
  7. # Copyright (C) 2006 Holger Hans Peter Freyther
  8. # Copyright (C) 2003, 2004 Chris Larson
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License version 2 as
  12. # published by the Free Software Foundation.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. # Based on functions from the base bb module, Copyright 2003 Holger Schurig
  24. import os, re
  25. import bb
  26. from bb import data
  27. from bb.fetch import Fetch
  28. from bb.fetch import FetchError
  29. from bb.fetch import MissingParameterError
  30. class Svk(Fetch):
  31. """Class to fetch a module or modules from svk repositories"""
  32. def supports(self, url, ud, d):
  33. """
  34. Check to see if a given url can be fetched with cvs.
  35. """
  36. return ud.type in ['svk']
  37. def localpath(self, url, ud, d):
  38. if not "module" in ud.parm:
  39. raise MissingParameterError("svk method needs a 'module' parameter")
  40. else:
  41. ud.module = ud.parm["module"]
  42. ud.revision = ""
  43. if 'rev' in ud.parm:
  44. ud.revision = ud.parm['rev']
  45. ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
  46. return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
  47. def forcefetch(self, url, ud, d):
  48. if (ud.date == "now"):
  49. return True
  50. return False
  51. def go(self, loc, ud, d):
  52. """Fetch urls"""
  53. if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile):
  54. return
  55. svkroot = ud.host + ud.path
  56. svkcmd = "svk co -r {%s} %s/%s" % (date, svkroot, ud.module)
  57. if ud.revision:
  58. svkcmd = "svk co -r %s/%s" % (ud.revision, svkroot, ud.module)
  59. # create temp directory
  60. localdata = data.createCopy(d)
  61. data.update_data(localdata)
  62. bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: creating temporary directory")
  63. bb.mkdirhier(data.expand('${WORKDIR}', localdata))
  64. data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvk.XXXXXX', localdata), localdata)
  65. tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
  66. tmpfile = tmppipe.readline().strip()
  67. if not tmpfile:
  68. bb.msg.error(bb.msg.domain.Fetcher, "Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
  69. raise FetchError(ud.module)
  70. # check out sources there
  71. os.chdir(tmpfile)
  72. bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
  73. bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svkcmd)
  74. myret = os.system(svkcmd)
  75. if myret != 0:
  76. try:
  77. os.rmdir(tmpfile)
  78. except OSError:
  79. pass
  80. raise FetchError(ud.module)
  81. os.chdir(os.path.join(tmpfile, os.path.dirname(ud.module)))
  82. # tar them up to a defined filename
  83. myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)))
  84. if myret != 0:
  85. try:
  86. os.unlink(ud.localpath)
  87. except OSError:
  88. pass
  89. raise FetchError(ud.module)
  90. # cleanup
  91. os.system('rm -rf %s' % tmpfile)