cvs.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. Classes for obtaining upstream sources for the
  6. BitBake build tools.
  7. """
  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. #
  25. import os
  26. import logging
  27. import bb
  28. from bb import data
  29. from bb.fetch2 import Fetch, FetchError, MissingParameterError, logger
  30. class Cvs(Fetch):
  31. """
  32. Class to fetch a module or modules from cvs repositories
  33. """
  34. def supports(self, url, ud, d):
  35. """
  36. Check to see if a given url can be fetched with cvs.
  37. """
  38. return ud.type in ['cvs']
  39. def localpath(self, url, ud, d):
  40. if not "module" in ud.parm:
  41. raise MissingParameterError("cvs method needs a 'module' parameter")
  42. ud.module = ud.parm["module"]
  43. ud.tag = ud.parm.get('tag', "")
  44. # Override the default date in certain cases
  45. if 'date' in ud.parm:
  46. ud.date = ud.parm['date']
  47. elif ud.tag:
  48. ud.date = ""
  49. norecurse = ''
  50. if 'norecurse' in ud.parm:
  51. norecurse = '_norecurse'
  52. fullpath = ''
  53. if 'fullpath' in ud.parm:
  54. fullpath = '_fullpath'
  55. ud.localfile = data.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath), d)
  56. return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
  57. def forcefetch(self, url, ud, d):
  58. if (ud.date == "now"):
  59. return True
  60. return False
  61. def go(self, loc, ud, d):
  62. method = ud.parm.get('method', 'pserver')
  63. localdir = ud.parm.get('localdir', ud.module)
  64. cvs_port = ud.parm.get('port', '')
  65. cvs_rsh = None
  66. if method == "ext":
  67. if "rsh" in ud.parm:
  68. cvs_rsh = ud.parm["rsh"]
  69. if method == "dir":
  70. cvsroot = ud.path
  71. else:
  72. cvsroot = ":" + method
  73. cvsproxyhost = data.getVar('CVS_PROXY_HOST', d, True)
  74. if cvsproxyhost:
  75. cvsroot += ";proxy=" + cvsproxyhost
  76. cvsproxyport = data.getVar('CVS_PROXY_PORT', d, True)
  77. if cvsproxyport:
  78. cvsroot += ";proxyport=" + cvsproxyport
  79. cvsroot += ":" + ud.user
  80. if ud.pswd:
  81. cvsroot += ":" + ud.pswd
  82. cvsroot += "@" + ud.host + ":" + cvs_port + ud.path
  83. options = []
  84. if 'norecurse' in ud.parm:
  85. options.append("-l")
  86. if ud.date:
  87. # treat YYYYMMDDHHMM specially for CVS
  88. if len(ud.date) == 12:
  89. options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12]))
  90. else:
  91. options.append("-D \"%s UTC\"" % ud.date)
  92. if ud.tag:
  93. options.append("-r %s" % ud.tag)
  94. localdata = data.createCopy(d)
  95. data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata)
  96. data.update_data(localdata)
  97. data.setVar('CVSROOT', cvsroot, localdata)
  98. data.setVar('CVSCOOPTS', " ".join(options), localdata)
  99. data.setVar('CVSMODULE', ud.module, localdata)
  100. cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
  101. cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
  102. if cvs_rsh:
  103. cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
  104. cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
  105. # create module directory
  106. logger.debug(2, "Fetch: checking for module directory")
  107. pkg = data.expand('${PN}', d)
  108. pkgdir = os.path.join(data.expand('${CVSDIR}', localdata), pkg)
  109. moddir = os.path.join(pkgdir, localdir)
  110. if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
  111. logger.info("Update " + loc)
  112. # update sources there
  113. os.chdir(moddir)
  114. myret = os.system(cvsupdatecmd)
  115. else:
  116. logger.info("Fetch " + loc)
  117. # check out sources there
  118. bb.mkdirhier(pkgdir)
  119. os.chdir(pkgdir)
  120. logger.debug(1, "Running %s", cvscmd)
  121. myret = os.system(cvscmd)
  122. if myret != 0 or not os.access(moddir, os.R_OK):
  123. try:
  124. os.rmdir(moddir)
  125. except OSError:
  126. pass
  127. raise FetchError(ud.module)
  128. scmdata = ud.parm.get("scmdata", "")
  129. if scmdata == "keep":
  130. tar_flags = ""
  131. else:
  132. tar_flags = "--exclude 'CVS'"
  133. # tar them up to a defined filename
  134. if 'fullpath' in ud.parm:
  135. os.chdir(pkgdir)
  136. myret = os.system("tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir))
  137. else:
  138. os.chdir(moddir)
  139. os.chdir('..')
  140. myret = os.system("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir)))
  141. if myret != 0:
  142. try:
  143. os.unlink(ud.localpath)
  144. except OSError:
  145. pass
  146. raise FetchError(ud.module)