svk.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  25. import logging
  26. import bb
  27. from bb import data
  28. from bb.fetch2 import FetchMethod
  29. from bb.fetch2 import FetchError
  30. from bb.fetch2 import MissingParameterError
  31. from bb.fetch2 import logger
  32. from bb.fetch2 import runfetchcmd
  33. class Svk(FetchMethod):
  34. """Class to fetch a module or modules from svk repositories"""
  35. def supports(self, ud, d):
  36. """
  37. Check to see if a given url can be fetched with svk.
  38. """
  39. return ud.type in ['svk']
  40. def urldata_init(self, ud, d):
  41. if not "module" in ud.parm:
  42. raise MissingParameterError('module', ud.url)
  43. else:
  44. ud.module = ud.parm["module"]
  45. ud.revision = ud.parm.get('rev', "")
  46. ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
  47. def need_update(self, ud, d):
  48. if ud.date == "now":
  49. return True
  50. if not os.path.exists(ud.localpath):
  51. return True
  52. return False
  53. def download(self, ud, d):
  54. """Fetch urls"""
  55. svkroot = ud.host + ud.path
  56. svkcmd = "svk co -r {%s} %s/%s" % (ud.date, svkroot, ud.module)
  57. if ud.revision:
  58. svkcmd = "svk co -r %s %s/%s" % (ud.revision, svkroot, ud.module)
  59. # create temp directory
  60. localdata = data.createCopy(d)
  61. data.update_data(localdata)
  62. logger.debug(2, "Fetch: creating temporary directory")
  63. bb.utils.mkdirhier(data.expand('${WORKDIR}', localdata))
  64. data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvk.XXXXXX', localdata), localdata)
  65. tmpfile, errors = bb.process.run(data.getVar('MKTEMPDIRCMD', localdata, True) or "false")
  66. tmpfile = tmpfile.strip()
  67. if not tmpfile:
  68. logger.error()
  69. raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", ud.url)
  70. # check out sources there
  71. os.chdir(tmpfile)
  72. logger.info("Fetch " + ud.url)
  73. logger.debug(1, "Running %s", svkcmd)
  74. runfetchcmd(svkcmd, d, cleanup = [tmpfile])
  75. os.chdir(os.path.join(tmpfile, os.path.dirname(ud.module)))
  76. # tar them up to a defined filename
  77. runfetchcmd("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)), d, cleanup = [ud.localpath])
  78. # cleanup
  79. bb.utils.prunedir(tmpfile)