cvs.py 5.2 KB

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