mirror of
https://git.yoctoproject.org/poky
synced 2026-05-30 00:20:08 +00:00
clases/lib: Use modern exception syntax
Update older code to use modern exception handling syntax which is the form accepted by python 3. (From OE-Core rev: b010501cd089e649a68f683be0cf4d0aac90fbe3) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
@@ -108,7 +108,7 @@ python base_do_fetch() {
|
|||||||
try:
|
try:
|
||||||
fetcher = bb.fetch2.Fetch(src_uri, localdata)
|
fetcher = bb.fetch2.Fetch(src_uri, localdata)
|
||||||
fetcher.download()
|
fetcher.download()
|
||||||
except bb.fetch2.BBFetchException, e:
|
except bb.fetch2.BBFetchException as e:
|
||||||
raise bb.build.FuncFailed(e)
|
raise bb.build.FuncFailed(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ python base_do_unpack() {
|
|||||||
try:
|
try:
|
||||||
fetcher = bb.fetch2.Fetch(src_uri, localdata)
|
fetcher = bb.fetch2.Fetch(src_uri, localdata)
|
||||||
fetcher.unpack(rootdir)
|
fetcher.unpack(rootdir)
|
||||||
except bb.fetch2.BBFetchException, e:
|
except bb.fetch2.BBFetchException as e:
|
||||||
raise bb.build.FuncFailed(e)
|
raise bb.build.FuncFailed(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -777,7 +777,8 @@ python split_and_strip_files () {
|
|||||||
try:
|
try:
|
||||||
ltarget = cpath.realpath(file, dvar, False)
|
ltarget = cpath.realpath(file, dvar, False)
|
||||||
s = cpath.lstat(ltarget)
|
s = cpath.lstat(ltarget)
|
||||||
except OSError, (err, strerror):
|
except OSError as e:
|
||||||
|
(err, strerror) = e.args
|
||||||
if err != errno.ENOENT:
|
if err != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
# Skip broken symlinks
|
# Skip broken symlinks
|
||||||
@@ -855,7 +856,8 @@ python split_and_strip_files () {
|
|||||||
# Skip it if the target doesn't exist
|
# Skip it if the target doesn't exist
|
||||||
try:
|
try:
|
||||||
s = os.stat(fpath)
|
s = os.stat(fpath)
|
||||||
except OSError, (err, strerror):
|
except OSError as e:
|
||||||
|
(err, strerror) = e.args
|
||||||
if err != errno.ENOENT:
|
if err != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -235,12 +235,14 @@ def check_create_long_filename(filepath, pathname):
|
|||||||
f = file(testfile, "w")
|
f = file(testfile, "w")
|
||||||
f.close()
|
f.close()
|
||||||
os.remove(testfile)
|
os.remove(testfile)
|
||||||
except IOError as (errno, strerror):
|
except IOError as e:
|
||||||
|
errno, strerror = e.args
|
||||||
if errno == 36: # ENAMETOOLONG
|
if errno == 36: # ENAMETOOLONG
|
||||||
return "Failed to create a file with a long name in %s. Please use a filesystem that does not unreasonably limit filename length.\n" % pathname
|
return "Failed to create a file with a long name in %s. Please use a filesystem that does not unreasonably limit filename length.\n" % pathname
|
||||||
else:
|
else:
|
||||||
return "Failed to create a file in %s: %s.\n" % (pathname, strerror)
|
return "Failed to create a file in %s: %s.\n" % (pathname, strerror)
|
||||||
except OSError as (errno, strerror):
|
except OSError as e:
|
||||||
|
errno, strerror = e.args
|
||||||
return "Failed to create %s directory in which to run long name sanity check: %s.\n" % (pathname, strerror)
|
return "Failed to create %s directory in which to run long name sanity check: %s.\n" % (pathname, strerror)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class CachedPath(object):
|
|||||||
# Note that listdir and error are globals in this module due
|
# Note that listdir and error are globals in this module due
|
||||||
# to earlier import-*.
|
# to earlier import-*.
|
||||||
names = os.listdir(top)
|
names = os.listdir(top)
|
||||||
except error, err:
|
except error as err:
|
||||||
if onerror is not None:
|
if onerror is not None:
|
||||||
onerror(err)
|
onerror(err)
|
||||||
return
|
return
|
||||||
@@ -221,7 +221,7 @@ class CachedPath(object):
|
|||||||
file = self.__realpath_rel(root, file[(len(root) - 1):], root, loop_cnt, assume_dir)
|
file = self.__realpath_rel(root, file[(len(root) - 1):], root, loop_cnt, assume_dir)
|
||||||
else:
|
else:
|
||||||
file = self.__realpath(file, root, loop_cnt, assume_dir)[0]
|
file = self.__realpath(file, root, loop_cnt, assume_dir)[0]
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno == errno.ELOOP:
|
if e.errno == errno.ELOOP:
|
||||||
# make ELOOP more readable; without catching it, there will
|
# make ELOOP more readable; without catching it, there will
|
||||||
# be printed a backtrace with 100s of OSError exceptions
|
# be printed a backtrace with 100s of OSError exceptions
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ class UserResolver(Resolver):
|
|||||||
os.chdir(self.patchset.dir)
|
os.chdir(self.patchset.dir)
|
||||||
try:
|
try:
|
||||||
self.patchset.Push(False)
|
self.patchset.Push(False)
|
||||||
except CmdError, v:
|
except CmdError as v:
|
||||||
# Patch application failed
|
# Patch application failed
|
||||||
patchcmd = self.patchset.Push(True, False, False)
|
patchcmd = self.patchset.Push(True, False, False)
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -107,7 +107,7 @@ def remove(path, recurse=True):
|
|||||||
for name in glob.glob(path):
|
for name in glob.glob(path):
|
||||||
try:
|
try:
|
||||||
os.unlink(name)
|
os.unlink(name)
|
||||||
except OSError, exc:
|
except OSError as exc:
|
||||||
if recurse and exc.errno == errno.EISDIR:
|
if recurse and exc.errno == errno.EISDIR:
|
||||||
shutil.rmtree(name)
|
shutil.rmtree(name)
|
||||||
elif exc.errno != errno.ENOENT:
|
elif exc.errno != errno.ENOENT:
|
||||||
@@ -119,7 +119,7 @@ def symlink(source, destination, force=False):
|
|||||||
if force:
|
if force:
|
||||||
remove(destination)
|
remove(destination)
|
||||||
os.symlink(source, destination)
|
os.symlink(source, destination)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno != errno.EEXIST or os.readlink(destination) != source:
|
if e.errno != errno.EEXIST or os.readlink(destination) != source:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@ def realpath(file, root, use_physdir = True, loop_cnt = 100, assume_dir = False)
|
|||||||
file = __realpath_rel(root, file[(len(root) - 1):], root, loop_cnt, assume_dir)
|
file = __realpath_rel(root, file[(len(root) - 1):], root, loop_cnt, assume_dir)
|
||||||
else:
|
else:
|
||||||
file = __realpath(file, root, loop_cnt, assume_dir)[0]
|
file = __realpath(file, root, loop_cnt, assume_dir)[0]
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno == errno.ELOOP:
|
if e.errno == errno.ELOOP:
|
||||||
# make ELOOP more readable; without catching it, there will
|
# make ELOOP more readable; without catching it, there will
|
||||||
# be printed a backtrace with 100s of OSError exceptions
|
# be printed a backtrace with 100s of OSError exceptions
|
||||||
|
|||||||
+1
-1
@@ -106,6 +106,6 @@ class ELFFile:
|
|||||||
bb.note("%s %s %s" % (objdump, cmd, self.name))
|
bb.note("%s %s %s" % (objdump, cmd, self.name))
|
||||||
self.objdump_output[cmd] = bb.process.run([objdump, cmd, self.name], env=env, shell=False)[0]
|
self.objdump_output[cmd] = bb.process.run([objdump, cmd, self.name], env=env, shell=False)[0]
|
||||||
return self.objdump_output[cmd]
|
return self.objdump_output[cmd]
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
bb.note("%s %s %s failed: %s" % (objdump, cmd, self.name, e))
|
bb.note("%s %s %s failed: %s" % (objdump, cmd, self.name, e))
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ def regex(value, regexflags=None):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
return re.compile(value, flagval)
|
return re.compile(value, flagval)
|
||||||
except re.error, exc:
|
except re.error as exc:
|
||||||
raise ValueError("Invalid regex value '%s': %s" %
|
raise ValueError("Invalid regex value '%s': %s" %
|
||||||
(value, exc.args[0]))
|
(value, exc.args[0]))
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
def read_file(filename):
|
def read_file(filename):
|
||||||
try:
|
try:
|
||||||
f = file( filename, "r" )
|
f = file( filename, "r" )
|
||||||
except IOError, reason:
|
except IOError as reason:
|
||||||
return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
|
return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
|
||||||
else:
|
else:
|
||||||
return f.read().strip()
|
return f.read().strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user