cvs.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.fetch2 import FetchMethod, FetchError, MissingParameterError, logger
  29. from bb.fetch2 import runfetchcmd
  30. class Cvs(FetchMethod):
  31. """
  32. Class to fetch a module or modules from cvs repositories
  33. """
  34. def supports(self, 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("module", ud.url)
  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 = bb.data.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath), d)
  56. def need_update(self, ud, d):
  57. if (ud.date == "now"):
  58. return True
  59. if not os.path.exists(ud.localpath):
  60. return True
  61. return False
  62. def download(self, 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 = d.getVar('CVS_PROXY_HOST', True)
  75. if cvsproxyhost:
  76. cvsroot += ";proxy=" + cvsproxyhost
  77. cvsproxyport = d.getVar('CVS_PROXY_PORT', 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. cvsbasecmd = d.getVar("FETCHCMD_cvs", True)
  96. cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module
  97. cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options)
  98. if cvs_rsh:
  99. cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
  100. cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
  101. # create module directory
  102. logger.debug(2, "Fetch: checking for module directory")
  103. pkg = d.getVar('PN', True)
  104. pkgdir = os.path.join(d.getVar('CVSDIR', True), pkg)
  105. moddir = os.path.join(pkgdir, localdir)
  106. if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
  107. logger.info("Update " + ud.url)
  108. bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url)
  109. # update sources there
  110. os.chdir(moddir)
  111. cmd = cvsupdatecmd
  112. else:
  113. logger.info("Fetch " + ud.url)
  114. # check out sources there
  115. bb.utils.mkdirhier(pkgdir)
  116. os.chdir(pkgdir)
  117. logger.debug(1, "Running %s", cvscmd)
  118. bb.fetch2.check_network_access(d, cvscmd, ud.url)
  119. cmd = cvscmd
  120. runfetchcmd(cmd, d, cleanup = [moddir])
  121. if not os.access(moddir, os.R_OK):
  122. raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url)
  123. scmdata = ud.parm.get("scmdata", "")
  124. if scmdata == "keep":
  125. tar_flags = ""
  126. else:
  127. tar_flags = "--exclude 'CVS'"
  128. # tar them up to a defined filename
  129. if 'fullpath' in ud.parm:
  130. os.chdir(pkgdir)
  131. cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)
  132. else:
  133. os.chdir(moddir)
  134. os.chdir('..')
  135. cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))
  136. runfetchcmd(cmd, d, cleanup = [ud.localpath])
  137. def clean(self, ud, d):
  138. """ Clean CVS Files and tarballs """
  139. pkg = d.getVar('PN', True)
  140. pkgdir = os.path.join(d.getVar("CVSDIR", True), pkg)
  141. bb.utils.remove(pkgdir, True)
  142. bb.utils.remove(ud.localpath)