cvs.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 bb
  14. from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger
  15. from bb.fetch2 import runfetchcmd
  16. class Cvs(FetchMethod):
  17. """
  18. Class to fetch a module or modules from cvs repositories
  19. """
  20. def supports(self, ud, d):
  21. """
  22. Check to see if a given url can be fetched with cvs.
  23. """
  24. return ud.type in ['cvs']
  25. def urldata_init(self, ud, d):
  26. if not "module" in ud.parm:
  27. raise MissingParameterError("module", ud.url)
  28. ud.module = ud.parm["module"]
  29. ud.tag = ud.parm.get('tag', "")
  30. # Override the default date in certain cases
  31. if 'date' in ud.parm:
  32. ud.date = ud.parm['date']
  33. elif ud.tag:
  34. ud.date = ""
  35. norecurse = ''
  36. if 'norecurse' in ud.parm:
  37. norecurse = '_norecurse'
  38. fullpath = ''
  39. if 'fullpath' in ud.parm:
  40. fullpath = '_fullpath'
  41. ud.localfile = d.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath))
  42. pkg = d.getVar('PN')
  43. cvsdir = d.getVar("CVSDIR") or (d.getVar("DL_DIR") + "/cvs")
  44. ud.pkgdir = os.path.join(cvsdir, pkg)
  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. moddir = os.path.join(ud.pkgdir, localdir)
  93. workdir = None
  94. if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
  95. logger.info("Update " + ud.url)
  96. bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url)
  97. # update sources there
  98. workdir = moddir
  99. cmd = cvsupdatecmd
  100. else:
  101. logger.info("Fetch " + ud.url)
  102. # check out sources there
  103. bb.utils.mkdirhier(ud.pkgdir)
  104. workdir = ud.pkgdir
  105. logger.debug(1, "Running %s", cvscmd)
  106. bb.fetch2.check_network_access(d, cvscmd, ud.url)
  107. cmd = cvscmd
  108. runfetchcmd(cmd, d, cleanup=[moddir], workdir=workdir)
  109. if not os.access(moddir, os.R_OK):
  110. raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url)
  111. scmdata = ud.parm.get("scmdata", "")
  112. if scmdata == "keep":
  113. tar_flags = ""
  114. else:
  115. tar_flags = "--exclude='CVS'"
  116. # tar them up to a defined filename
  117. workdir = None
  118. if 'fullpath' in ud.parm:
  119. workdir = ud.pkgdir
  120. cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)
  121. else:
  122. workdir = os.path.dirname(os.path.realpath(moddir))
  123. cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))
  124. runfetchcmd(cmd, d, cleanup=[ud.localpath], workdir=workdir)
  125. def clean(self, ud, d):
  126. """ Clean CVS Files and tarballs """
  127. bb.utils.remove(ud.pkgdir, True)
  128. bb.utils.remove(ud.localpath)