cvs.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. """
  2. BitBake 'Fetch' implementations
  3. Classes for obtaining upstream sources for the
  4. BitBake build tools.
  5. """
  6. # Copyright (C) 2003, 2004 Chris Larson
  7. #
  8. # SPDX-License-Identifier: GPL-2.0-only
  9. #
  10. # Based on functions from the base bb module, Copyright 2003 Holger Schurig
  11. #
  12. import os
  13. import logging
  14. import bb
  15. from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger
  16. from bb.fetch2 import runfetchcmd
  17. class Cvs(FetchMethod):
  18. """
  19. Class to fetch a module or modules from cvs repositories
  20. """
  21. def supports(self, ud, d):
  22. """
  23. Check to see if a given url can be fetched with cvs.
  24. """
  25. return ud.type in ['cvs']
  26. def urldata_init(self, ud, d):
  27. if not "module" in ud.parm:
  28. raise MissingParameterError("module", ud.url)
  29. ud.module = ud.parm["module"]
  30. ud.tag = ud.parm.get('tag', "")
  31. # Override the default date in certain cases
  32. if 'date' in ud.parm:
  33. ud.date = ud.parm['date']
  34. elif ud.tag:
  35. ud.date = ""
  36. norecurse = ''
  37. if 'norecurse' in ud.parm:
  38. norecurse = '_norecurse'
  39. fullpath = ''
  40. if 'fullpath' in ud.parm:
  41. fullpath = '_fullpath'
  42. ud.localfile = d.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath))
  43. def need_update(self, ud, d):
  44. if (ud.date == "now"):
  45. return True
  46. if not os.path.exists(ud.localpath):
  47. return True
  48. return False
  49. def download(self, ud, d):
  50. method = ud.parm.get('method', 'pserver')
  51. localdir = ud.parm.get('localdir', ud.module)
  52. cvs_port = ud.parm.get('port', '')
  53. cvs_rsh = None
  54. if method == "ext":
  55. if "rsh" in ud.parm:
  56. cvs_rsh = ud.parm["rsh"]
  57. if method == "dir":
  58. cvsroot = ud.path
  59. else:
  60. cvsroot = ":" + method
  61. cvsproxyhost = d.getVar('CVS_PROXY_HOST')
  62. if cvsproxyhost:
  63. cvsroot += ";proxy=" + cvsproxyhost
  64. cvsproxyport = d.getVar('CVS_PROXY_PORT')
  65. if cvsproxyport:
  66. cvsroot += ";proxyport=" + cvsproxyport
  67. cvsroot += ":" + ud.user
  68. if ud.pswd:
  69. cvsroot += ":" + ud.pswd
  70. cvsroot += "@" + ud.host + ":" + cvs_port + ud.path
  71. options = []
  72. if 'norecurse' in ud.parm:
  73. options.append("-l")
  74. if ud.date:
  75. # treat YYYYMMDDHHMM specially for CVS
  76. if len(ud.date) == 12:
  77. options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12]))
  78. else:
  79. options.append("-D \"%s UTC\"" % ud.date)
  80. if ud.tag:
  81. options.append("-r %s" % ud.tag)
  82. cvsbasecmd = d.getVar("FETCHCMD_cvs") or "/usr/bin/env cvs"
  83. cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module
  84. cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options)
  85. if cvs_rsh:
  86. cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
  87. cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
  88. # create module directory
  89. logger.debug(2, "Fetch: checking for module directory")
  90. pkg = d.getVar('PN')
  91. cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs")
  92. pkgdir = os.path.join(cvsdir, pkg)
  93. moddir = os.path.join(pkgdir, localdir)
  94. workdir = None
  95. if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
  96. logger.info("Update " + ud.url)
  97. bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url)
  98. # update sources there
  99. workdir = moddir
  100. cmd = cvsupdatecmd
  101. else:
  102. logger.info("Fetch " + ud.url)
  103. # check out sources there
  104. bb.utils.mkdirhier(pkgdir)
  105. workdir = pkgdir
  106. logger.debug(1, "Running %s", cvscmd)
  107. bb.fetch2.check_network_access(d, cvscmd, ud.url)
  108. cmd = cvscmd
  109. runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir)
  110. if not os.access(moddir, os.R_OK):
  111. raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url)
  112. scmdata = ud.parm.get("scmdata", "")
  113. if scmdata == "keep":
  114. tar_flags = ""
  115. else:
  116. tar_flags = "--exclude='CVS'"
  117. # tar them up to a defined filename
  118. workdir = None
  119. if 'fullpath' in ud.parm:
  120. workdir = pkgdir
  121. cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)
  122. else:
  123. workdir = os.path.dirname(os.path.realpath(moddir))
  124. cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))
  125. runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir)
  126. def clean(self, ud, d):
  127. """ Clean CVS Files and tarballs """
  128. pkg = d.getVar('PN')
  129. pkgdir = os.path.join(d.getVar("CVSDIR"), pkg)
  130. bb.utils.remove(pkgdir, True)
  131. bb.utils.remove(ud.localpath)