cvs.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 urldata_init(self, 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. def localpath(self, url, ud, d):
  57. return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
  58. def forcefetch(self, url, ud, d):
  59. if (ud.date == "now"):
  60. return True
  61. return False
  62. def download(self, loc, ud, d):
  63. method = ud.parm.get('method', 'pserver')
  64. localdir = ud.parm.get('localdir', ud.module)
  65. cvs_port = ud.parm.get('port', '')
  66. cvs_rsh = None
  67. if method == "ext":
  68. if "rsh" in ud.parm:
  69. cvs_rsh = ud.parm["rsh"]
  70. if method == "dir":
  71. cvsroot = ud.path
  72. else:
  73. cvsroot = ":" + method
  74. cvsproxyhost = data.getVar('CVS_PROXY_HOST', d, True)
  75. if cvsproxyhost:
  76. cvsroot += ";proxy=" + cvsproxyhost
  77. cvsproxyport = data.getVar('CVS_PROXY_PORT', d, True)
  78. if cvsproxyport:
  79. cvsroot += ";proxyport=" + cvsproxyport
  80. cvsroot += ":" + ud.user
  81. if ud.pswd:
  82. cvsroot += ":" + ud.pswd
  83. cvsroot += "@" + ud.host + ":" + cvs_port + ud.path
  84. options = []
  85. if 'norecurse' in ud.parm:
  86. options.append("-l")
  87. if ud.date:
  88. # treat YYYYMMDDHHMM specially for CVS
  89. if len(ud.date) == 12:
  90. options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12]))
  91. else:
  92. options.append("-D \"%s UTC\"" % ud.date)
  93. if ud.tag:
  94. options.append("-r %s" % ud.tag)
  95. localdata = data.createCopy(d)
  96. data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata)
  97. data.update_data(localdata)
  98. data.setVar('CVSROOT', cvsroot, localdata)
  99. data.setVar('CVSCOOPTS', " ".join(options), localdata)
  100. data.setVar('CVSMODULE', ud.module, localdata)
  101. cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
  102. cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
  103. if cvs_rsh:
  104. cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
  105. cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
  106. # create module directory
  107. logger.debug(2, "Fetch: checking for module directory")
  108. pkg = data.expand('${PN}', d)
  109. pkgdir = os.path.join(data.expand('${CVSDIR}', localdata), pkg)
  110. moddir = os.path.join(pkgdir, localdir)
  111. if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
  112. logger.info("Update " + loc)
  113. bb.fetch2.check_network_access(d, cvsupdatecmd)
  114. # update sources there
  115. os.chdir(moddir)
  116. myret = os.system(cvsupdatecmd)
  117. else:
  118. logger.info("Fetch " + loc)
  119. # check out sources there
  120. bb.mkdirhier(pkgdir)
  121. os.chdir(pkgdir)
  122. logger.debug(1, "Running %s", cvscmd)
  123. bb.fetch2.check_network_access(d, cvscmd)
  124. myret = os.system(cvscmd)
  125. if myret != 0 or not os.access(moddir, os.R_OK):
  126. try:
  127. os.rmdir(moddir)
  128. except OSError:
  129. pass
  130. raise FetchError(ud.module)
  131. scmdata = ud.parm.get("scmdata", "")
  132. if scmdata == "keep":
  133. tar_flags = ""
  134. else:
  135. tar_flags = "--exclude 'CVS'"
  136. # tar them up to a defined filename
  137. if 'fullpath' in ud.parm:
  138. os.chdir(pkgdir)
  139. myret = os.system("tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir))
  140. else:
  141. os.chdir(moddir)
  142. os.chdir('..')
  143. myret = os.system("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir)))
  144. if myret != 0:
  145. try:
  146. os.unlink(ud.localpath)
  147. except OSError:
  148. pass
  149. raise FetchError(ud.module)