Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 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 | |
| 6 | Classes for obtaining upstream sources for the |
| 7 | BitBake build tools. |
| 8 | |
| 9 | """ |
| 10 | |
| 11 | # Copyright (C) 2003, 2004 Chris Larson |
| 12 | # |
| 13 | # This program is free software; you can redistribute it and/or modify |
| 14 | # it under the terms of the GNU General Public License version 2 as |
| 15 | # published by the Free Software Foundation. |
| 16 | # |
| 17 | # This program is distributed in the hope that it will be useful, |
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | # GNU General Public License for more details. |
| 21 | # |
| 22 | # You should have received a copy of the GNU General Public License along |
| 23 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | # |
| 26 | #Based on functions from the base bb module, Copyright 2003 Holger Schurig |
| 27 | # |
| 28 | |
| 29 | import os |
| 30 | import logging |
| 31 | import bb |
| 32 | from bb.fetch2 import FetchMethod, FetchError, MissingParameterError, logger |
| 33 | from bb.fetch2 import runfetchcmd |
| 34 | |
| 35 | class Cvs(FetchMethod): |
| 36 | """ |
| 37 | Class to fetch a module or modules from cvs repositories |
| 38 | """ |
| 39 | def supports(self, ud, d): |
| 40 | """ |
| 41 | Check to see if a given url can be fetched with cvs. |
| 42 | """ |
| 43 | return ud.type in ['cvs'] |
| 44 | |
| 45 | def urldata_init(self, ud, d): |
| 46 | if not "module" in ud.parm: |
| 47 | raise MissingParameterError("module", ud.url) |
| 48 | ud.module = ud.parm["module"] |
| 49 | |
| 50 | ud.tag = ud.parm.get('tag', "") |
| 51 | |
| 52 | # Override the default date in certain cases |
| 53 | if 'date' in ud.parm: |
| 54 | ud.date = ud.parm['date'] |
| 55 | elif ud.tag: |
| 56 | ud.date = "" |
| 57 | |
| 58 | norecurse = '' |
| 59 | if 'norecurse' in ud.parm: |
| 60 | norecurse = '_norecurse' |
| 61 | |
| 62 | fullpath = '' |
| 63 | if 'fullpath' in ud.parm: |
| 64 | fullpath = '_fullpath' |
| 65 | |
| 66 | 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) |
| 67 | |
| 68 | def need_update(self, ud, d): |
| 69 | if (ud.date == "now"): |
| 70 | return True |
| 71 | if not os.path.exists(ud.localpath): |
| 72 | return True |
| 73 | return False |
| 74 | |
| 75 | def download(self, ud, d): |
| 76 | |
| 77 | method = ud.parm.get('method', 'pserver') |
| 78 | localdir = ud.parm.get('localdir', ud.module) |
| 79 | cvs_port = ud.parm.get('port', '') |
| 80 | |
| 81 | cvs_rsh = None |
| 82 | if method == "ext": |
| 83 | if "rsh" in ud.parm: |
| 84 | cvs_rsh = ud.parm["rsh"] |
| 85 | |
| 86 | if method == "dir": |
| 87 | cvsroot = ud.path |
| 88 | else: |
| 89 | cvsroot = ":" + method |
| 90 | cvsproxyhost = d.getVar('CVS_PROXY_HOST', True) |
| 91 | if cvsproxyhost: |
| 92 | cvsroot += ";proxy=" + cvsproxyhost |
| 93 | cvsproxyport = d.getVar('CVS_PROXY_PORT', True) |
| 94 | if cvsproxyport: |
| 95 | cvsroot += ";proxyport=" + cvsproxyport |
| 96 | cvsroot += ":" + ud.user |
| 97 | if ud.pswd: |
| 98 | cvsroot += ":" + ud.pswd |
| 99 | cvsroot += "@" + ud.host + ":" + cvs_port + ud.path |
| 100 | |
| 101 | options = [] |
| 102 | if 'norecurse' in ud.parm: |
| 103 | options.append("-l") |
| 104 | if ud.date: |
| 105 | # treat YYYYMMDDHHMM specially for CVS |
| 106 | if len(ud.date) == 12: |
| 107 | options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12])) |
| 108 | else: |
| 109 | options.append("-D \"%s UTC\"" % ud.date) |
| 110 | if ud.tag: |
| 111 | options.append("-r %s" % ud.tag) |
| 112 | |
| 113 | cvsbasecmd = d.getVar("FETCHCMD_cvs", True) |
| 114 | cvscmd = cvsbasecmd + " '-d" + cvsroot + "' co " + " ".join(options) + " " + ud.module |
| 115 | cvsupdatecmd = cvsbasecmd + " '-d" + cvsroot + "' update -d -P " + " ".join(options) |
| 116 | |
| 117 | if cvs_rsh: |
| 118 | cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd) |
| 119 | cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd) |
| 120 | |
| 121 | # create module directory |
| 122 | logger.debug(2, "Fetch: checking for module directory") |
| 123 | pkg = d.getVar('PN', True) |
| 124 | pkgdir = os.path.join(d.getVar('CVSDIR', True), pkg) |
| 125 | moddir = os.path.join(pkgdir, localdir) |
| 126 | if os.access(os.path.join(moddir, 'CVS'), os.R_OK): |
| 127 | logger.info("Update " + ud.url) |
| 128 | bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url) |
| 129 | # update sources there |
| 130 | os.chdir(moddir) |
| 131 | cmd = cvsupdatecmd |
| 132 | else: |
| 133 | logger.info("Fetch " + ud.url) |
| 134 | # check out sources there |
| 135 | bb.utils.mkdirhier(pkgdir) |
| 136 | os.chdir(pkgdir) |
| 137 | logger.debug(1, "Running %s", cvscmd) |
| 138 | bb.fetch2.check_network_access(d, cvscmd, ud.url) |
| 139 | cmd = cvscmd |
| 140 | |
| 141 | runfetchcmd(cmd, d, cleanup = [moddir]) |
| 142 | |
| 143 | if not os.access(moddir, os.R_OK): |
| 144 | raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url) |
| 145 | |
| 146 | scmdata = ud.parm.get("scmdata", "") |
| 147 | if scmdata == "keep": |
| 148 | tar_flags = "" |
| 149 | else: |
| 150 | tar_flags = "--exclude 'CVS'" |
| 151 | |
| 152 | # tar them up to a defined filename |
| 153 | if 'fullpath' in ud.parm: |
| 154 | os.chdir(pkgdir) |
| 155 | cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir) |
| 156 | else: |
| 157 | os.chdir(moddir) |
| 158 | os.chdir('..') |
| 159 | cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir)) |
| 160 | |
| 161 | runfetchcmd(cmd, d, cleanup = [ud.localpath]) |
| 162 | |
| 163 | def clean(self, ud, d): |
| 164 | """ Clean CVS Files and tarballs """ |
| 165 | |
| 166 | pkg = d.getVar('PN', True) |
| 167 | pkgdir = os.path.join(d.getVar("CVSDIR", True), pkg) |
| 168 | |
| 169 | bb.utils.remove(pkgdir, True) |
| 170 | bb.utils.remove(ud.localpath) |
| 171 | |