cvs.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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, re
  26. import bb
  27. from bb import data
  28. from bb.fetch import Fetch
  29. from bb.fetch import FetchError
  30. from bb.fetch import MissingParameterError
  31. class Cvs(Fetch):
  32. """
  33. Class to fetch a module or modules from cvs repositories
  34. """
  35. def supports(self, url, ud, d):
  36. """
  37. Check to see if a given url can be fetched with cvs.
  38. """
  39. return ud.type in ['cvs', 'pserver']
  40. def localpath(self, url, ud, d):
  41. if not "module" in ud.parm:
  42. raise MissingParameterError("cvs method needs a 'module' parameter")
  43. ud.module = ud.parm["module"]
  44. ud.tag = ""
  45. if 'tag' in ud.parm:
  46. ud.tag = ud.parm['tag']
  47. # Override the default date in certain cases
  48. if 'date' in ud.parm:
  49. ud.date = ud.parm['date']
  50. elif ud.tag:
  51. ud.date = ""
  52. ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date), d)
  53. return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
  54. def forcefetch(self, url, ud, d):
  55. if (ud.date == "now"):
  56. return True
  57. return False
  58. def go(self, loc, ud, d):
  59. # try to use the tarball stash
  60. if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile):
  61. bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping cvs checkout." % ud.localpath)
  62. return
  63. method = "pserver"
  64. if "method" in ud.parm:
  65. method = ud.parm["method"]
  66. localdir = ud.module
  67. if "localdir" in ud.parm:
  68. localdir = ud.parm["localdir"]
  69. cvs_port = ""
  70. if "port" in ud.parm:
  71. cvs_port = ud.parm["port"]
  72. cvs_rsh = None
  73. if method == "ext":
  74. if "rsh" in ud.parm:
  75. cvs_rsh = ud.parm["rsh"]
  76. if method == "dir":
  77. cvsroot = ud.path
  78. else:
  79. cvsroot = ":" + method + ":" + ud.user
  80. if ud.pswd:
  81. cvsroot += ":" + ud.pswd
  82. cvsroot += "@" + ud.host + ":" + cvs_port + ud.path
  83. options = []
  84. if ud.date:
  85. options.append("-D %s" % ud.date)
  86. if ud.tag:
  87. options.append("-r %s" % ud.tag)
  88. localdata = data.createCopy(d)
  89. data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata)
  90. data.update_data(localdata)
  91. data.setVar('CVSROOT', cvsroot, localdata)
  92. data.setVar('CVSCOOPTS', " ".join(options), localdata)
  93. data.setVar('CVSMODULE', ud.module, localdata)
  94. cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
  95. cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
  96. if cvs_rsh:
  97. cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
  98. cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
  99. # create module directory
  100. bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory")
  101. pkg = data.expand('${PN}', d)
  102. pkgdir = os.path.join(data.expand('${CVSDIR}', localdata), pkg)
  103. moddir = os.path.join(pkgdir,localdir)
  104. if os.access(os.path.join(moddir,'CVS'), os.R_OK):
  105. bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
  106. # update sources there
  107. os.chdir(moddir)
  108. myret = os.system(cvsupdatecmd)
  109. else:
  110. bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
  111. # check out sources there
  112. bb.mkdirhier(pkgdir)
  113. os.chdir(pkgdir)
  114. bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % cvscmd)
  115. myret = os.system(cvscmd)
  116. if myret != 0 or not os.access(moddir, os.R_OK):
  117. try:
  118. os.rmdir(moddir)
  119. except OSError:
  120. pass
  121. raise FetchError(ud.module)
  122. os.chdir(moddir)
  123. os.chdir('..')
  124. # tar them up to a defined filename
  125. myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(moddir)))
  126. if myret != 0:
  127. try:
  128. os.unlink(ud.localpath)
  129. except OSError:
  130. pass
  131. raise FetchError(ud.module)