diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-02-04 10:26:21 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-02-07 09:06:36 +0000 |
commit | d08397ba4d1331993300eacbb2f78fcfef19c1cf (patch) | |
tree | 374d8aa46a69fbae08d2b3e8e7456a5c61005e4c /bitbake/lib/bb/fetch2 | |
parent | f6eefb3ca3bb2a5ea0ec1364bdb0bc41ae58c815 (diff) | |
download | poky-d08397ba4d1331993300eacbb2f78fcfef19c1cf.tar.gz |
bitbake/fetch2: Rewrite and improve exception handling, reusing core functions for common operations where possible
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2')
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 116 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/bzr.py | 12 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/cvs.py | 30 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/git.py | 4 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/hg.py | 14 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/osc.py | 14 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/perforce.py | 20 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/ssh.py | 6 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/svk.py | 23 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/svn.py | 14 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/wget.py | 13 |
11 files changed, 121 insertions, 145 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index 54812eec43..10c1e73554 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py | |||
@@ -38,28 +38,62 @@ __version__ = "2" | |||
38 | logger = logging.getLogger("BitBake.Fetch") | 38 | logger = logging.getLogger("BitBake.Fetch") |
39 | 39 | ||
40 | class BBFetchException(Exception): | 40 | class BBFetchException(Exception): |
41 | """Class all fetch exceptions inherit from""" | 41 | """Class all fetch exceptions inherit from""" |
42 | def __init__(self, message): | ||
43 | self.msg = message | ||
44 | Exception.__init__(self, message) | ||
45 | |||
46 | def __str__(self): | ||
47 | return self.msg | ||
42 | 48 | ||
43 | class MalformedUrl(BBFetchException): | 49 | class MalformedUrl(BBFetchException): |
44 | """Exception raised when encountering an invalid url""" | 50 | """Exception raised when encountering an invalid url""" |
51 | def __init__(self, url): | ||
52 | self.msg = "The URL: '%s' is invalid and cannot be interpreted" % url | ||
53 | self.url = url | ||
54 | Exception.__init__(self, self.msg) | ||
45 | 55 | ||
46 | class FetchError(BBFetchException): | 56 | class FetchError(BBFetchException): |
47 | """Exception raised when a download fails""" | 57 | """General fetcher exception when something happens incorrectly""" |
58 | def __init__(self, message, url = None): | ||
59 | self.msg = "Fetcher failure for URL: '%s'. %s" % (url, message) | ||
60 | self.url = url | ||
61 | Exception.__init__(self, self.msg) | ||
48 | 62 | ||
49 | class NoMethodError(BBFetchException): | 63 | class NoMethodError(BBFetchException): |
50 | """Exception raised when there is no method to obtain a supplied url or set of urls""" | 64 | """Exception raised when there is no method to obtain a supplied url or set of urls""" |
65 | def __init__(self, url): | ||
66 | self.msg = "Could not find a fetcher which supports the URL: '%s'" % url | ||
67 | self.url = url | ||
68 | Exception.__init__(self, self.msg) | ||
51 | 69 | ||
52 | class MissingParameterError(BBFetchException): | 70 | class MissingParameterError(BBFetchException): |
53 | """Exception raised when a fetch method is missing a critical parameter in the url""" | 71 | """Exception raised when a fetch method is missing a critical parameter in the url""" |
72 | def __init__(self, missing, url): | ||
73 | self.msg = "URL: '%s' is missing the required parameter '%s'" % (url, missing) | ||
74 | self.url = url | ||
75 | self.missing = missing | ||
76 | Exception.__init__(self, self.msg) | ||
54 | 77 | ||
55 | class ParameterError(BBFetchException): | 78 | class ParameterError(BBFetchException): |
56 | """Exception raised when a url cannot be proccessed due to invalid parameters.""" | 79 | """Exception raised when a url cannot be proccessed due to invalid parameters.""" |
80 | def __init__(self, message, url): | ||
81 | self.msg = "URL: '%s' has invalid parameters. %s" % (url, message) | ||
82 | self.url = url | ||
83 | Exception.__init__(self, self.msg) | ||
57 | 84 | ||
58 | class MD5SumError(BBFetchException): | 85 | class MD5SumError(BBFetchException): |
59 | """Exception raised when a MD5SUM of a file does not match the expected one""" | 86 | """Exception raised when a MD5 checksum of a file does not match for a downloaded file""" |
60 | 87 | def __init__(self, path, wanted, got, url): | |
61 | class InvalidSRCREV(BBFetchException): | 88 | self.msg = "File: '%s' has md5 sum %s when %s was expected (from URL: '%s')" % (path, got, wanted, url) |
62 | """Exception raised when an invalid SRCREV is encountered""" | 89 | self.url = url |
90 | self.path = path | ||
91 | self.wanted = wanted | ||
92 | self.got = got | ||
93 | Exception.__init__(self, self.msg) | ||
94 | |||
95 | class SHA256SumError(MD5SumError): | ||
96 | """Exception raised when a SHA256 checksum of a file does not match for a downloaded file""" | ||
63 | 97 | ||
64 | def decodeurl(url): | 98 | def decodeurl(url): |
65 | """Decodes an URL into the tokens (scheme, network location, path, | 99 | """Decodes an URL into the tokens (scheme, network location, path, |
@@ -108,8 +142,10 @@ def encodeurl(decoded): | |||
108 | 142 | ||
109 | (type, host, path, user, pswd, p) = decoded | 143 | (type, host, path, user, pswd, p) = decoded |
110 | 144 | ||
111 | if not type or not path: | 145 | if not path: |
112 | raise MissingParameterError("Type or path url components missing when encoding %s" % decoded) | 146 | raise MissingParameterError('path', "encoded from the data %s" % str(decoded)) |
147 | if not type: | ||
148 | raise MissingParameterError('type', "encoded from the data %s" % str(decoded)) | ||
113 | url = '%s://' % type | 149 | url = '%s://' % type |
114 | if user and type != "file": | 150 | if user and type != "file": |
115 | url += "%s" % user | 151 | url += "%s" % user |
@@ -243,16 +279,14 @@ def verify_checksum(u, ud, d): | |||
243 | ud.localpath, ud.md5_name, md5data, | 279 | ud.localpath, ud.md5_name, md5data, |
244 | ud.sha256_name, sha256data) | 280 | ud.sha256_name, sha256data) |
245 | if bb.data.getVar("BB_STRICT_CHECKSUM", d, True) == "1": | 281 | if bb.data.getVar("BB_STRICT_CHECKSUM", d, True) == "1": |
246 | raise FetchError("No checksum specified for %s." % u) | 282 | raise FetchError("No checksum specified for %s." % u, u) |
247 | return | 283 | return |
248 | 284 | ||
249 | if (ud.md5_expected != md5data or ud.sha256_expected != sha256data): | 285 | if ud.md5_expected != md5data: |
250 | logger.error('The checksums for "%s" did not match.\n' | 286 | raise MD5SumError(ud.localpath, ud.md5_expected, md5data, u) |
251 | ' MD5: expected "%s", got "%s"\n' | 287 | |
252 | ' SHA256: expected "%s", got "%s"\n', | 288 | if ud.sha256_expected != sha256data: |
253 | ud.localpath, ud.md5_expected, md5data, | 289 | raise SHA256SumError(ud.localpath, ud.sha256_expected, sha256data, u) |
254 | ud.sha256_expected, sha256data) | ||
255 | raise FetchError("%s checksum mismatch." % u) | ||
256 | 290 | ||
257 | def subprocess_setup(): | 291 | def subprocess_setup(): |
258 | import signal | 292 | import signal |
@@ -319,7 +353,7 @@ def download(d, urls = None): | |||
319 | localpath = try_mirrors (d, u, mirrors) | 353 | localpath = try_mirrors (d, u, mirrors) |
320 | 354 | ||
321 | if not localpath or not os.path.exists(localpath): | 355 | if not localpath or not os.path.exists(localpath): |
322 | raise FetchError("Unable to fetch URL %s from any source." % u) | 356 | raise FetchError("Unable to fetch URL %s from any source." % u, u) |
323 | 357 | ||
324 | download_update(localpath, ud.localpath) | 358 | download_update(localpath, ud.localpath) |
325 | 359 | ||
@@ -365,7 +399,7 @@ def checkstatus(d, urls = None): | |||
365 | ret = try_mirrors (d, u, mirrors, True) | 399 | ret = try_mirrors (d, u, mirrors, True) |
366 | 400 | ||
367 | if not ret: | 401 | if not ret: |
368 | raise FetchError("URL %s doesn't work" % u) | 402 | raise FetchError("URL %s doesn't work" % u, u) |
369 | 403 | ||
370 | def localpaths(d): | 404 | def localpaths(d): |
371 | """ | 405 | """ |
@@ -403,8 +437,7 @@ def get_srcrev(d): | |||
403 | scms.append(u) | 437 | scms.append(u) |
404 | 438 | ||
405 | if len(scms) == 0: | 439 | if len(scms) == 0: |
406 | logger.error("SRCREV was used yet no valid SCM was found in SRC_URI") | 440 | raise FetchError("SRCREV was used yet no valid SCM was found in SRC_URI") |
407 | raise ParameterError | ||
408 | 441 | ||
409 | if len(scms) == 1 and len(urldata[scms[0]].names) == 1: | 442 | if len(scms) == 1 and len(urldata[scms[0]].names) == 1: |
410 | return urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d, urldata[scms[0]].names[0]) | 443 | return urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d, urldata[scms[0]].names[0]) |
@@ -414,8 +447,7 @@ def get_srcrev(d): | |||
414 | # | 447 | # |
415 | format = bb.data.getVar('SRCREV_FORMAT', d, 1) | 448 | format = bb.data.getVar('SRCREV_FORMAT', d, 1) |
416 | if not format: | 449 | if not format: |
417 | logger.error("The SRCREV_FORMAT variable must be set when multiple SCMs are used.") | 450 | raise FetchError("The SRCREV_FORMAT variable must be set when multiple SCMs are used.") |
418 | raise ParameterError | ||
419 | 451 | ||
420 | for scm in scms: | 452 | for scm in scms: |
421 | ud = urldata[scm] | 453 | ud = urldata[scm] |
@@ -435,11 +467,12 @@ def localpath(url, d): | |||
435 | return ud[url].localpath | 467 | return ud[url].localpath |
436 | return url | 468 | return url |
437 | 469 | ||
438 | def runfetchcmd(cmd, d, quiet = False): | 470 | def runfetchcmd(cmd, d, quiet = False, cleanup = []): |
439 | """ | 471 | """ |
440 | Run cmd returning the command output | 472 | Run cmd returning the command output |
441 | Raise an error if interrupted or cmd fails | 473 | Raise an error if interrupted or cmd fails |
442 | Optionally echo command output to stdout | 474 | Optionally echo command output to stdout |
475 | Optionally remove the files/directories listed in cleanup upon failure | ||
443 | """ | 476 | """ |
444 | 477 | ||
445 | # Need to export PATH as binary could be in metadata paths | 478 | # Need to export PATH as binary could be in metadata paths |
@@ -474,10 +507,17 @@ def runfetchcmd(cmd, d, quiet = False): | |||
474 | signal = status >> 8 | 507 | signal = status >> 8 |
475 | exitstatus = status & 0xff | 508 | exitstatus = status & 0xff |
476 | 509 | ||
477 | if signal: | 510 | if (signal or status != 0): |
478 | raise FetchError("Fetch command %s failed with signal %s, output:\n%s" % (cmd, signal, output)) | 511 | for f in cleanup: |
479 | elif status != 0: | 512 | try: |
480 | raise FetchError("Fetch command %s failed with exit code %s, output:\n%s" % (cmd, status, output)) | 513 | bb.utils.remove(f, True) |
514 | except OSError: | ||
515 | pass | ||
516 | |||
517 | if signal: | ||
518 | raise FetchError("Fetch command %s failed with signal %s, output:\n%s" % (cmd, signal, output)) | ||
519 | elif status != 0: | ||
520 | raise FetchError("Fetch command %s failed with exit code %s, output:\n%s" % (cmd, status, output)) | ||
481 | 521 | ||
482 | return output | 522 | return output |
483 | 523 | ||
@@ -486,10 +526,9 @@ def check_network_access(d, info = ""): | |||
486 | log remote network access, and error if BB_NO_NETWORK is set | 526 | log remote network access, and error if BB_NO_NETWORK is set |
487 | """ | 527 | """ |
488 | if bb.data.getVar("BB_NO_NETWORK", d, True) == "1": | 528 | if bb.data.getVar("BB_NO_NETWORK", d, True) == "1": |
489 | bb.error("BB_NO_NETWORK is set, but the fetcher code attempted network access with the command %s" % info) | 529 | raise FetchError("BB_NO_NETWORK is set, but the fetcher code attempted network access with the command %s" % info) |
490 | raise FetchError("BB_NO_NETWORK violation") | ||
491 | else: | 530 | else: |
492 | bb.note("Fetcher accessed the network with the command %s" % info) | 531 | logger.debug(1, "Fetcher accessed the network with the command %s" % info) |
493 | 532 | ||
494 | def try_mirrors(d, uri, mirrors, check = False, force = False): | 533 | def try_mirrors(d, uri, mirrors, check = False, force = False): |
495 | """ | 534 | """ |
@@ -573,7 +612,7 @@ class FetchData(object): | |||
573 | break | 612 | break |
574 | 613 | ||
575 | if not self.method: | 614 | if not self.method: |
576 | raise NoMethodError("Missing implementation for url %s" % url) | 615 | raise NoMethodError(url) |
577 | 616 | ||
578 | if self.method.supports_srcrev(): | 617 | if self.method.supports_srcrev(): |
579 | self.revisions = {} | 618 | self.revisions = {} |
@@ -658,7 +697,7 @@ class Fetch(object): | |||
658 | Fetch urls | 697 | Fetch urls |
659 | Assumes localpath was called first | 698 | Assumes localpath was called first |
660 | """ | 699 | """ |
661 | raise NoMethodError("Missing implementation for url") | 700 | raise NoMethodError(url) |
662 | 701 | ||
663 | def unpack(self, urldata, rootdir, data): | 702 | def unpack(self, urldata, rootdir, data): |
664 | import subprocess | 703 | import subprocess |
@@ -795,7 +834,7 @@ class Fetch(object): | |||
795 | if not rev: | 834 | if not rev: |
796 | rev = data.getVar("SRCREV", d, 1) | 835 | rev = data.getVar("SRCREV", d, 1) |
797 | if rev == "INVALID": | 836 | if rev == "INVALID": |
798 | raise InvalidSRCREV("Please set SRCREV to a valid value") | 837 | raise FetchError("Please set SRCREV to a valid value", ud.url) |
799 | if rev == "AUTOINC": | 838 | if rev == "AUTOINC": |
800 | rev = ud.method.latest_revision(ud.url, ud, d, name) | 839 | rev = ud.method.latest_revision(ud.url, ud, d, name) |
801 | 840 | ||
@@ -828,14 +867,15 @@ class Fetch(object): | |||
828 | if not wanted_sum: | 867 | if not wanted_sum: |
829 | return True | 868 | return True |
830 | 869 | ||
831 | return wanted_sum == got_sum | 870 | if wanted_sum != got_sum: |
871 | raise MD5SumError(ud.localpath, wanted_sum, got_sum, ud.url) | ||
872 | |||
832 | verify_md5sum = staticmethod(verify_md5sum) | 873 | verify_md5sum = staticmethod(verify_md5sum) |
833 | 874 | ||
834 | def write_md5sum(url, ud, d): | 875 | def write_md5sum(url, ud, d): |
835 | md5data = bb.utils.md5_file(ud.localpath) | 876 | md5data = bb.utils.md5_file(ud.localpath) |
836 | # verify the md5sum | 877 | |
837 | if not Fetch.verify_md5sum(ud, md5data): | 878 | Fetch.verify_md5sum(ud, md5data) |
838 | raise MD5SumError(url) | ||
839 | 879 | ||
840 | md5out = file(ud.md5, 'w') | 880 | md5out = file(ud.md5, 'w') |
841 | md5out.write(md5data) | 881 | md5out.write(md5data) |
@@ -847,7 +887,7 @@ class Fetch(object): | |||
847 | Look in the cache for the latest revision, if not present ask the SCM. | 887 | Look in the cache for the latest revision, if not present ask the SCM. |
848 | """ | 888 | """ |
849 | if not hasattr(self, "_latest_revision"): | 889 | if not hasattr(self, "_latest_revision"): |
850 | raise ParameterError | 890 | raise ParameterError("The fetcher for this URL does not support _latest_revision", url) |
851 | 891 | ||
852 | pd = persist_data.persist(d) | 892 | pd = persist_data.persist(d) |
853 | revs = pd['BB_URI_HEADREVS'] | 893 | revs = pd['BB_URI_HEADREVS'] |
diff --git a/bitbake/lib/bb/fetch2/bzr.py b/bitbake/lib/bb/fetch2/bzr.py index 1e25207b19..22168a8351 100644 --- a/bitbake/lib/bb/fetch2/bzr.py +++ b/bitbake/lib/bb/fetch2/bzr.py | |||
@@ -72,7 +72,7 @@ class Bzr(Fetch): | |||
72 | elif command is "update": | 72 | elif command is "update": |
73 | bzrcmd = "%s pull %s --overwrite" % (basecmd, " ".join(options)) | 73 | bzrcmd = "%s pull %s --overwrite" % (basecmd, " ".join(options)) |
74 | else: | 74 | else: |
75 | raise FetchError("Invalid bzr command %s" % command) | 75 | raise FetchError("Invalid bzr command %s" % command, ud.url) |
76 | 76 | ||
77 | return bzrcmd | 77 | return bzrcmd |
78 | 78 | ||
@@ -104,15 +104,7 @@ class Bzr(Fetch): | |||
104 | tar_flags = "--exclude '.bzr' --exclude '.bzrtags'" | 104 | tar_flags = "--exclude '.bzr' --exclude '.bzrtags'" |
105 | 105 | ||
106 | # tar them up to a defined filename | 106 | # tar them up to a defined filename |
107 | try: | 107 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(ud.pkgdir)), d, cleanup = [ud.localpath]) |
108 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(ud.pkgdir)), d) | ||
109 | except: | ||
110 | t, v, tb = sys.exc_info() | ||
111 | try: | ||
112 | os.unlink(ud.localpath) | ||
113 | except OSError: | ||
114 | pass | ||
115 | raise t, v, tb | ||
116 | 108 | ||
117 | def supports_srcrev(self): | 109 | def supports_srcrev(self): |
118 | return True | 110 | return True |
diff --git a/bitbake/lib/bb/fetch2/cvs.py b/bitbake/lib/bb/fetch2/cvs.py index 907812d717..d792328c25 100644 --- a/bitbake/lib/bb/fetch2/cvs.py +++ b/bitbake/lib/bb/fetch2/cvs.py | |||
@@ -44,7 +44,7 @@ class Cvs(Fetch): | |||
44 | 44 | ||
45 | def urldata_init(self, ud, d): | 45 | def urldata_init(self, ud, d): |
46 | if not "module" in ud.parm: | 46 | if not "module" in ud.parm: |
47 | raise MissingParameterError("cvs method needs a 'module' parameter") | 47 | raise MissingParameterError("module", ud.url) |
48 | ud.module = ud.parm["module"] | 48 | ud.module = ud.parm["module"] |
49 | 49 | ||
50 | ud.tag = ud.parm.get('tag', "") | 50 | ud.tag = ud.parm.get('tag', "") |
@@ -132,7 +132,7 @@ class Cvs(Fetch): | |||
132 | bb.fetch2.check_network_access(d, cvsupdatecmd) | 132 | bb.fetch2.check_network_access(d, cvsupdatecmd) |
133 | # update sources there | 133 | # update sources there |
134 | os.chdir(moddir) | 134 | os.chdir(moddir) |
135 | myret = os.system(cvsupdatecmd) | 135 | cmd = cvsupdatecmd |
136 | else: | 136 | else: |
137 | logger.info("Fetch " + loc) | 137 | logger.info("Fetch " + loc) |
138 | # check out sources there | 138 | # check out sources there |
@@ -140,14 +140,12 @@ class Cvs(Fetch): | |||
140 | os.chdir(pkgdir) | 140 | os.chdir(pkgdir) |
141 | logger.debug(1, "Running %s", cvscmd) | 141 | logger.debug(1, "Running %s", cvscmd) |
142 | bb.fetch2.check_network_access(d, cvscmd) | 142 | bb.fetch2.check_network_access(d, cvscmd) |
143 | myret = os.system(cvscmd) | 143 | cmd = cvscmd |
144 | 144 | ||
145 | if myret != 0 or not os.access(moddir, os.R_OK): | 145 | runfetchcmd(cmd, d, cleanup = [moddir]) |
146 | try: | 146 | |
147 | os.rmdir(moddir) | 147 | if not os.access(moddir, os.R_OK): |
148 | except OSError: | 148 | raise FetchError("Directory %s was not readable despite sucessful fetch?!" % moddir, ud.url) |
149 | pass | ||
150 | raise FetchError(ud.module) | ||
151 | 149 | ||
152 | scmdata = ud.parm.get("scmdata", "") | 150 | scmdata = ud.parm.get("scmdata", "") |
153 | if scmdata == "keep": | 151 | if scmdata == "keep": |
@@ -158,15 +156,11 @@ class Cvs(Fetch): | |||
158 | # tar them up to a defined filename | 156 | # tar them up to a defined filename |
159 | if 'fullpath' in ud.parm: | 157 | if 'fullpath' in ud.parm: |
160 | os.chdir(pkgdir) | 158 | os.chdir(pkgdir) |
161 | myret = os.system("tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)) | 159 | cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir) |
162 | else: | 160 | else: |
163 | os.chdir(moddir) | 161 | os.chdir(moddir) |
164 | os.chdir('..') | 162 | os.chdir('..') |
165 | myret = os.system("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))) | 163 | cmd = "tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir)) |
166 | 164 | ||
167 | if myret != 0: | 165 | runfetchcmd(cmd, d, cleanup = [ud.localpath]) |
168 | try: | 166 | |
169 | os.unlink(ud.localpath) | ||
170 | except OSError: | ||
171 | pass | ||
172 | raise FetchError(ud.module) | ||
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index 392491ed87..1ae1d40302 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py | |||
@@ -59,7 +59,7 @@ class Git(Fetch): | |||
59 | 59 | ||
60 | branches = ud.parm.get("branch", "master").split(',') | 60 | branches = ud.parm.get("branch", "master").split(',') |
61 | if len(branches) != len(ud.names): | 61 | if len(branches) != len(ud.names): |
62 | raise bb.fetch2.ParameterError("SRC_URI (%) name and branch number mismatch" % ud.url) | 62 | raise bb.fetch2.ParameterError("The number of name and branch parameters is not balanced", ud.url) |
63 | ud.branches = {} | 63 | ud.branches = {} |
64 | for name in ud.names: | 64 | for name in ud.names: |
65 | branch = branches[ud.names.index(name)] | 65 | branch = branches[ud.names.index(name)] |
@@ -194,7 +194,7 @@ class Git(Fetch): | |||
194 | cmd = "%s ls-remote %s://%s%s%s %s" % (basecmd, ud.proto, username, ud.host, ud.path, ud.branches[name]) | 194 | cmd = "%s ls-remote %s://%s%s%s %s" % (basecmd, ud.proto, username, ud.host, ud.path, ud.branches[name]) |
195 | output = runfetchcmd(cmd, d, True) | 195 | output = runfetchcmd(cmd, d, True) |
196 | if not output: | 196 | if not output: |
197 | raise bb.fetch2.FetchError("Fetch command %s gave empty output\n" % (cmd)) | 197 | raise bb.fetch2.FetchError("The command %s gave empty output unexpectedly" % cmd, url) |
198 | return output.split()[0] | 198 | return output.split()[0] |
199 | 199 | ||
200 | def _build_revision(self, url, ud, d, name): | 200 | def _build_revision(self, url, ud, d, name): |
diff --git a/bitbake/lib/bb/fetch2/hg.py b/bitbake/lib/bb/fetch2/hg.py index 6929d971f5..ffede8cf5a 100644 --- a/bitbake/lib/bb/fetch2/hg.py +++ b/bitbake/lib/bb/fetch2/hg.py | |||
@@ -48,7 +48,7 @@ class Hg(Fetch): | |||
48 | init hg specific variable within url data | 48 | init hg specific variable within url data |
49 | """ | 49 | """ |
50 | if not "module" in ud.parm: | 50 | if not "module" in ud.parm: |
51 | raise MissingParameterError("hg method needs a 'module' parameter") | 51 | raise MissingParameterError('module', ud.url) |
52 | 52 | ||
53 | ud.module = ud.parm["module"] | 53 | ud.module = ud.parm["module"] |
54 | 54 | ||
@@ -105,7 +105,7 @@ class Hg(Fetch): | |||
105 | elif command is "update": | 105 | elif command is "update": |
106 | cmd = "%s update -C %s" % (basecmd, " ".join(options)) | 106 | cmd = "%s update -C %s" % (basecmd, " ".join(options)) |
107 | else: | 107 | else: |
108 | raise FetchError("Invalid hg command %s" % command) | 108 | raise FetchError("Invalid hg command %s" % command, ud.url) |
109 | 109 | ||
110 | return cmd | 110 | return cmd |
111 | 111 | ||
@@ -147,15 +147,7 @@ class Hg(Fetch): | |||
147 | tar_flags = "--exclude '.hg' --exclude '.hgrags'" | 147 | tar_flags = "--exclude '.hg' --exclude '.hgrags'" |
148 | 148 | ||
149 | os.chdir(ud.pkgdir) | 149 | os.chdir(ud.pkgdir) |
150 | try: | 150 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d, cleanup = [ud.localpath]) |
151 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d) | ||
152 | except: | ||
153 | t, v, tb = sys.exc_info() | ||
154 | try: | ||
155 | os.unlink(ud.localpath) | ||
156 | except OSError: | ||
157 | pass | ||
158 | raise t, v, tb | ||
159 | 151 | ||
160 | def supports_srcrev(self): | 152 | def supports_srcrev(self): |
161 | return True | 153 | return True |
diff --git a/bitbake/lib/bb/fetch2/osc.py b/bitbake/lib/bb/fetch2/osc.py index 14bde82fd7..9b97cf1cc7 100644 --- a/bitbake/lib/bb/fetch2/osc.py +++ b/bitbake/lib/bb/fetch2/osc.py | |||
@@ -28,7 +28,7 @@ class Osc(Fetch): | |||
28 | 28 | ||
29 | def urldata_init(self, ud, d): | 29 | def urldata_init(self, ud, d): |
30 | if not "module" in ud.parm: | 30 | if not "module" in ud.parm: |
31 | raise MissingParameterError("osc method needs a 'module' parameter.") | 31 | raise MissingParameterError('module', ud.url) |
32 | 32 | ||
33 | ud.module = ud.parm["module"] | 33 | ud.module = ud.parm["module"] |
34 | 34 | ||
@@ -73,7 +73,7 @@ class Osc(Fetch): | |||
73 | elif command is "update": | 73 | elif command is "update": |
74 | osccmd = "%s %s up %s" % (basecmd, config, " ".join(options)) | 74 | osccmd = "%s %s up %s" % (basecmd, config, " ".join(options)) |
75 | else: | 75 | else: |
76 | raise FetchError("Invalid osc command %s" % command) | 76 | raise FetchError("Invalid osc command %s" % command, ud.url) |
77 | 77 | ||
78 | return osccmd | 78 | return osccmd |
79 | 79 | ||
@@ -104,15 +104,7 @@ class Osc(Fetch): | |||
104 | 104 | ||
105 | os.chdir(os.path.join(ud.pkgdir + ud.path)) | 105 | os.chdir(os.path.join(ud.pkgdir + ud.path)) |
106 | # tar them up to a defined filename | 106 | # tar them up to a defined filename |
107 | try: | 107 | runfetchcmd("tar -czf %s %s" % (ud.localpath, ud.module), d, cleanup = [ud.localpath]) |
108 | runfetchcmd("tar -czf %s %s" % (ud.localpath, ud.module), d) | ||
109 | except: | ||
110 | t, v, tb = sys.exc_info() | ||
111 | try: | ||
112 | os.unlink(ud.localpath) | ||
113 | except OSError: | ||
114 | pass | ||
115 | raise t, v, tb | ||
116 | 108 | ||
117 | def supports_srcrev(self): | 109 | def supports_srcrev(self): |
118 | return False | 110 | return False |
diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py index 5c128b3fde..e98440f59f 100644 --- a/bitbake/lib/bb/fetch2/perforce.py +++ b/bitbake/lib/bb/fetch2/perforce.py | |||
@@ -156,8 +156,7 @@ class Perforce(Fetch): | |||
156 | tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false") | 156 | tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false") |
157 | tmpfile = tmppipe.readline().strip() | 157 | tmpfile = tmppipe.readline().strip() |
158 | if not tmpfile: | 158 | if not tmpfile: |
159 | logger.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.") | 159 | raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", loc) |
160 | raise FetchError(module) | ||
161 | 160 | ||
162 | if "label" in parm: | 161 | if "label" in parm: |
163 | depot = "%s@%s" % (depot, parm["label"]) | 162 | depot = "%s@%s" % (depot, parm["label"]) |
@@ -171,8 +170,7 @@ class Perforce(Fetch): | |||
171 | p4file = os.popen("%s%s files %s" % (p4cmd, p4opt, depot)) | 170 | p4file = os.popen("%s%s files %s" % (p4cmd, p4opt, depot)) |
172 | 171 | ||
173 | if not p4file: | 172 | if not p4file: |
174 | logger.error("Fetch: unable to get the P4 files from %s", depot) | 173 | raise FetchError("Fetch: unable to get the P4 files from %s" % depot, loc) |
175 | raise FetchError(module) | ||
176 | 174 | ||
177 | count = 0 | 175 | count = 0 |
178 | 176 | ||
@@ -189,15 +187,9 @@ class Perforce(Fetch): | |||
189 | count = count + 1 | 187 | count = count + 1 |
190 | 188 | ||
191 | if count == 0: | 189 | if count == 0: |
192 | logger.error("Fetch: No files gathered from the P4 fetch") | 190 | logger.error() |
193 | raise FetchError(module) | 191 | raise FetchError("Fetch: No files gathered from the P4 fetch", loc) |
194 | 192 | ||
195 | myret = os.system("tar -czf %s %s" % (ud.localpath, module)) | 193 | runfetchcmd("tar -czf %s %s" % (ud.localpath, module), d, cleanup = [ud.localpath]) |
196 | if myret != 0: | ||
197 | try: | ||
198 | os.unlink(ud.localpath) | ||
199 | except OSError: | ||
200 | pass | ||
201 | raise FetchError(module) | ||
202 | # cleanup | 194 | # cleanup |
203 | bb.utils.prunedir(tmpfile) | 195 | bb.utils.prunedir(tmpfile) |
diff --git a/bitbake/lib/bb/fetch2/ssh.py b/bitbake/lib/bb/fetch2/ssh.py index 246439ef19..29cc272193 100644 --- a/bitbake/lib/bb/fetch2/ssh.py +++ b/bitbake/lib/bb/fetch2/ssh.py | |||
@@ -114,7 +114,5 @@ class SSH(Fetch): | |||
114 | 114 | ||
115 | bb.fetch2.check_network_access(d, cmd) | 115 | bb.fetch2.check_network_access(d, cmd) |
116 | 116 | ||
117 | (exitstatus, output) = commands.getstatusoutput(cmd) | 117 | runfetchcmd(cmd, d) |
118 | if exitstatus != 0: | 118 | |
119 | print(output) | ||
120 | raise FetchError('Unable to fetch %s' % url) | ||
diff --git a/bitbake/lib/bb/fetch2/svk.py b/bitbake/lib/bb/fetch2/svk.py index 95206f52fb..8220bf3dc2 100644 --- a/bitbake/lib/bb/fetch2/svk.py +++ b/bitbake/lib/bb/fetch2/svk.py | |||
@@ -45,7 +45,7 @@ class Svk(Fetch): | |||
45 | def urldata_init(self, ud, d): | 45 | def urldata_init(self, ud, d): |
46 | 46 | ||
47 | if not "module" in ud.parm: | 47 | if not "module" in ud.parm: |
48 | raise MissingParameterError("svk method needs a 'module' parameter") | 48 | raise MissingParameterError('module', ud.url) |
49 | else: | 49 | else: |
50 | ud.module = ud.parm["module"] | 50 | ud.module = ud.parm["module"] |
51 | 51 | ||
@@ -75,29 +75,18 @@ class Svk(Fetch): | |||
75 | tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false") | 75 | tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false") |
76 | tmpfile = tmppipe.readline().strip() | 76 | tmpfile = tmppipe.readline().strip() |
77 | if not tmpfile: | 77 | if not tmpfile: |
78 | logger.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.") | 78 | logger.error() |
79 | raise FetchError(ud.module) | 79 | raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", loc) |
80 | 80 | ||
81 | # check out sources there | 81 | # check out sources there |
82 | os.chdir(tmpfile) | 82 | os.chdir(tmpfile) |
83 | logger.info("Fetch " + loc) | 83 | logger.info("Fetch " + loc) |
84 | logger.debug(1, "Running %s", svkcmd) | 84 | logger.debug(1, "Running %s", svkcmd) |
85 | myret = os.system(svkcmd) | 85 | runfetchcmd(svkcmd, d, cleanup = [tmpfile]) |
86 | if myret != 0: | ||
87 | try: | ||
88 | os.rmdir(tmpfile) | ||
89 | except OSError: | ||
90 | pass | ||
91 | raise FetchError(ud.module) | ||
92 | 86 | ||
93 | os.chdir(os.path.join(tmpfile, os.path.dirname(ud.module))) | 87 | os.chdir(os.path.join(tmpfile, os.path.dirname(ud.module))) |
94 | # tar them up to a defined filename | 88 | # tar them up to a defined filename |
95 | myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module))) | 89 | runfetchcmd("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)), d, cleanup = [ud.localpath]) |
96 | if myret != 0: | 90 | |
97 | try: | ||
98 | os.unlink(ud.localpath) | ||
99 | except OSError: | ||
100 | pass | ||
101 | raise FetchError(ud.module) | ||
102 | # cleanup | 91 | # cleanup |
103 | bb.utils.prunedir(tmpfile) | 92 | bb.utils.prunedir(tmpfile) |
diff --git a/bitbake/lib/bb/fetch2/svn.py b/bitbake/lib/bb/fetch2/svn.py index 5ff064ebf3..267c9bb7e6 100644 --- a/bitbake/lib/bb/fetch2/svn.py +++ b/bitbake/lib/bb/fetch2/svn.py | |||
@@ -47,7 +47,7 @@ class Svn(Fetch): | |||
47 | init svn specific variable within url data | 47 | init svn specific variable within url data |
48 | """ | 48 | """ |
49 | if not "module" in ud.parm: | 49 | if not "module" in ud.parm: |
50 | raise MissingParameterError("svn method needs a 'module' parameter") | 50 | raise MissingParameterError('module', ud.url) |
51 | 51 | ||
52 | ud.module = ud.parm["module"] | 52 | ud.module = ud.parm["module"] |
53 | 53 | ||
@@ -118,7 +118,7 @@ class Svn(Fetch): | |||
118 | elif command is "update": | 118 | elif command is "update": |
119 | svncmd = "%s update %s" % (basecmd, " ".join(options)) | 119 | svncmd = "%s update %s" % (basecmd, " ".join(options)) |
120 | else: | 120 | else: |
121 | raise FetchError("Invalid svn command %s" % command) | 121 | raise FetchError("Invalid svn command %s" % command, ud.url) |
122 | 122 | ||
123 | if svn_rsh: | 123 | if svn_rsh: |
124 | svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd) | 124 | svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd) |
@@ -156,15 +156,7 @@ class Svn(Fetch): | |||
156 | 156 | ||
157 | os.chdir(ud.pkgdir) | 157 | os.chdir(ud.pkgdir) |
158 | # tar them up to a defined filename | 158 | # tar them up to a defined filename |
159 | try: | 159 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d, cleanup = [ud.localpath]) |
160 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d) | ||
161 | except: | ||
162 | t, v, tb = sys.exc_info() | ||
163 | try: | ||
164 | os.unlink(ud.localpath) | ||
165 | except OSError: | ||
166 | pass | ||
167 | raise t, v, tb | ||
168 | 160 | ||
169 | def supports_srcrev(self): | 161 | def supports_srcrev(self): |
170 | return True | 162 | return True |
diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py index 8d623721a9..e33265e1cc 100644 --- a/bitbake/lib/bb/fetch2/wget.py +++ b/bitbake/lib/bb/fetch2/wget.py | |||
@@ -72,20 +72,15 @@ class Wget(Fetch): | |||
72 | # Sanity check since wget can pretend it succeed when it didn't | 72 | # Sanity check since wget can pretend it succeed when it didn't |
73 | # Also, this used to happen if sourceforge sent us to the mirror page | 73 | # Also, this used to happen if sourceforge sent us to the mirror page |
74 | if not os.path.exists(ud.localpath) and not checkonly: | 74 | if not os.path.exists(ud.localpath) and not checkonly: |
75 | logger.debug(2, "The fetch command for %s returned success but %s doesn't exist?...", uri, ud.localpath) | 75 | raise FetchError("The fetch command returned success but %s doesn't exist?!" % (uri, ud.localpath), uri) |
76 | return False | ||
77 | |||
78 | return True | ||
79 | 76 | ||
80 | localdata = data.createCopy(d) | 77 | localdata = data.createCopy(d) |
81 | data.setVar('OVERRIDES', "wget:" + data.getVar('OVERRIDES', localdata), localdata) | 78 | data.setVar('OVERRIDES', "wget:" + data.getVar('OVERRIDES', localdata), localdata) |
82 | data.update_data(localdata) | 79 | data.update_data(localdata) |
83 | 80 | ||
84 | if fetch_uri(uri, ud, localdata): | 81 | fetch_uri(uri, ud, localdata) |
85 | return True | 82 | |
86 | 83 | return True | |
87 | raise FetchError(uri) | ||
88 | |||
89 | 84 | ||
90 | def checkstatus(self, uri, ud, d): | 85 | def checkstatus(self, uri, ud, d): |
91 | return self.download(uri, ud, d, True) | 86 | return self.download(uri, ud, d, True) |