osc.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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" implementation for osc (Opensuse build service client).
  5. Based on the svn "Fetch" implementation.
  6. """
  7. import os
  8. import sys
  9. import logging
  10. import bb
  11. from bb import data
  12. from bb.fetch2 import FetchMethod
  13. from bb.fetch2 import FetchError
  14. from bb.fetch2 import MissingParameterError
  15. from bb.fetch2 import runfetchcmd
  16. class Osc(FetchMethod):
  17. """Class to fetch a module or modules from Opensuse build server
  18. repositories."""
  19. def supports(self, ud, d):
  20. """
  21. Check to see if a given url can be fetched with osc.
  22. """
  23. return ud.type in ['osc']
  24. def urldata_init(self, ud, d):
  25. if not "module" in ud.parm:
  26. raise MissingParameterError('module', ud.url)
  27. ud.module = ud.parm["module"]
  28. # Create paths to osc checkouts
  29. relpath = self._strip_leading_slashes(ud.path)
  30. ud.pkgdir = os.path.join(data.expand('${OSCDIR}', d), ud.host)
  31. ud.moddir = os.path.join(ud.pkgdir, relpath, ud.module)
  32. if 'rev' in ud.parm:
  33. ud.revision = ud.parm['rev']
  34. else:
  35. pv = data.getVar("PV", d, 0)
  36. rev = bb.fetch2.srcrev_internal_helper(ud, d)
  37. if rev and rev != True:
  38. ud.revision = rev
  39. else:
  40. ud.revision = ""
  41. ud.localfile = data.expand('%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.path.replace('/', '.'), ud.revision), d)
  42. def _buildosccommand(self, ud, d, command):
  43. """
  44. Build up an ocs commandline based on ud
  45. command is "fetch", "update", "info"
  46. """
  47. basecmd = data.expand('${FETCHCMD_osc}', d)
  48. proto = ud.parm.get('protocol', 'ocs')
  49. options = []
  50. config = "-c %s" % self.generate_config(ud, d)
  51. if ud.revision:
  52. options.append("-r %s" % ud.revision)
  53. coroot = self._strip_leading_slashes(ud.path)
  54. if command == "fetch":
  55. osccmd = "%s %s co %s/%s %s" % (basecmd, config, coroot, ud.module, " ".join(options))
  56. elif command == "update":
  57. osccmd = "%s %s up %s" % (basecmd, config, " ".join(options))
  58. else:
  59. raise FetchError("Invalid osc command %s" % command, ud.url)
  60. return osccmd
  61. def download(self, ud, d):
  62. """
  63. Fetch url
  64. """
  65. logger.debug(2, "Fetch: checking for module directory '" + ud.moddir + "'")
  66. if os.access(os.path.join(data.expand('${OSCDIR}', d), ud.path, ud.module), os.R_OK):
  67. oscupdatecmd = self._buildosccommand(ud, d, "update")
  68. logger.info("Update "+ ud.url)
  69. # update sources there
  70. os.chdir(ud.moddir)
  71. logger.debug(1, "Running %s", oscupdatecmd)
  72. bb.fetch2.check_network_access(d, oscupdatecmd, ud.url)
  73. runfetchcmd(oscupdatecmd, d)
  74. else:
  75. oscfetchcmd = self._buildosccommand(ud, d, "fetch")
  76. logger.info("Fetch " + ud.url)
  77. # check out sources there
  78. bb.utils.mkdirhier(ud.pkgdir)
  79. os.chdir(ud.pkgdir)
  80. logger.debug(1, "Running %s", oscfetchcmd)
  81. bb.fetch2.check_network_access(d, oscfetchcmd, ud.url)
  82. runfetchcmd(oscfetchcmd, d)
  83. os.chdir(os.path.join(ud.pkgdir + ud.path))
  84. # tar them up to a defined filename
  85. runfetchcmd("tar -czf %s %s" % (ud.localpath, ud.module), d, cleanup = [ud.localpath])
  86. def supports_srcrev(self):
  87. return False
  88. def generate_config(self, ud, d):
  89. """
  90. Generate a .oscrc to be used for this run.
  91. """
  92. config_path = os.path.join(data.expand('${OSCDIR}', d), "oscrc")
  93. if (os.path.exists(config_path)):
  94. os.remove(config_path)
  95. f = open(config_path, 'w')
  96. f.write("[general]\n")
  97. f.write("apisrv = %s\n" % ud.host)
  98. f.write("scheme = http\n")
  99. f.write("su-wrapper = su -c\n")
  100. f.write("build-root = %s\n" % data.expand('${WORKDIR}', d))
  101. f.write("urllist = http://moblin-obs.jf.intel.com:8888/build/%(project)s/%(repository)s/%(buildarch)s/:full/%(name)s.rpm\n")
  102. f.write("extra-pkgs = gzip\n")
  103. f.write("\n")
  104. f.write("[%s]\n" % ud.host)
  105. f.write("user = %s\n" % ud.parm["user"])
  106. f.write("pass = %s\n" % ud.parm["pswd"])
  107. f.close()
  108. return config_path