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. # SPDX-License-Identifier: GPL-2.0-only
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License version 2 as
  14. # published by the Free Software Foundation.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License along
  22. # with this program; if not, write to the Free Software Foundation, Inc.,
  23. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. #
  25. #Based on functions from the base bb module, Copyright 2003 Holger Schurig
  26. #
  27. import os
  28. import logging
  29. import bb
  30. from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger
  31. from bb.fetch2 import runfetchcmd
  32. class Cvs(FetchMethod):
  33. """
  34. Class to fetch a module or modules from cvs repositories
  35. """
  36. def supports(self, ud, d):
  37. """
  38. Check to see if a given url can be fetched with cvs.
  39. """
  40. return ud.type in ['cvs']
  41. def urldata_init(self, ud, d):
  42. if not "module" in ud.parm:
  43. raise MissingParameterError("module", ud.url)
  44. ud.module = ud.parm["module"]
  45. ud.tag = ud.parm.get('tag', "")
  46. # Override the default date in certain cases
  47. if 'date' in ud.parm:
  48. ud.date = ud.parm['date']
  49. elif ud.tag:
  50. ud.date = ""
  51. norecurse = ''
  52. if 'norecurse' in ud.parm:
  53. norecurse = '_norecurse'
  54. fullpath = ''
  55. if 'fullpath' in ud.parm:
  56. fullpath = '_fullpath'
  57. ud.localfile = d.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath))
  58. def need_update(self, ud, d):
  59. if (ud.date == "now"):
  60. return True
  61. if not os.path.exists(ud.localpath):
  62. return True
  63. return False
  64. def download(self, ud, d):
  65. method = ud.parm.get('method', 'pserver')
  66. localdir = ud.parm.get('localdir', ud.module)
  67. cvs_port = ud.parm.get('port', '')
  68. cvs_rsh = None
  69. if method == "ext":
  70. if "rsh" in ud.parm:
  71. cvs_rsh = ud.parm["rsh"]
  72. if method == "dir":
  73. cvsroot = ud.path
  74. else:
  75. cvsroot = ":" + method
  76. cvsproxyhost = d.getVar('CVS_PROXY_HOST')
  77. if cvsproxyhost:
  78. cvsroot += ";proxy=" + cvsproxyhost
  79. cvsproxyport = d.getVar('CVS_PROXY_PORT')
  80. if cvsproxyport:
  81. cvsroot += ";proxyport=" + cvsproxyport
  82. cvsroot += ":" + ud.user
  83. if ud.pswd:
  84. cvsroot += ":" + ud.pswd
  85. cvsroot += "@" + ud.host + ":" + cvs_port + ud.path
  86. options = []
  87. if 'norecurse' in ud.parm:
  88. options.append("-l")
  89. if ud.date:
  90. # treat YYYYMMDDHHMM specially for CVS
  91. if len(ud.date) == 12:
  92. options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12]))
  93. else:
  94. options.append("-D \"%s UTC\"" % ud.date)
  95. if ud.tag:
  96. options.append("-r %s" % ud.tag)
  97. cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs"
  98. cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module
  99. cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options)
  100. if cvs_rsh:
  101. cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
  102. cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
  103. # create module directory
  104. logger.debug(2, "Fetch: checking for module directory")
  105. pkg = d.getVar('PN')
  106. cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs")
  107. pkgdir = os.path.join(cvsdir, pkg)
  108. moddir = os.path.join(pkgdir, localdir)
  109. workdir = None
  110. if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
  111. logger.info("Update " + ud.url)
  112. bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url)
  113. # update sources there
  114. workdir = moddir
  115. cmd = cvsupdatecmd
  116. else:
  117. logger.info("Fetch " + ud.url)
  118. # check out sources there
  119. bb.utils.mkdirhier(pkgdir)
  120. workdir = pkgdir
  121. logger.debug(1, "Running %s", cvscmd)
  122. bb.fetch2.check_network_access(d, cvscmd, ud.url)
  123. cmd = cvscmd
  124. runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir)
  125. if not os.access(moddir, os.R_OK):
  126. raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url)
  127. scmdata = ud.parm.get("scmdata", "")
  128. if scmdata == "keep":
  129. tar_flags = ""
  130. else:
  131. tar_flags = "--exclude='CVS'"
  132. # tar them up to a defined filename
  133. workdir = None
  134. if 'fullpath' in ud.parm:
  135. workdir = pkgdir
  136. cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)
  137. else:
  138. workdir = os.path.dirname(os.path.realpath(moddir))
  139. cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))
  140. runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir)
  141. def clean(self, ud, d):
  142. """ Clean CVS Files and tarballs """
  143. pkg = d.getVar('PN')
  144. pkgdir = os.path.join(d.getVar("CVSDIR"), pkg)
  145. bb.utils.remove(pkgdir, True)
  146. bb.utils.remove(ud.localpath)