* [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime
@ 2019-10-21 10:30 Ola x Nilsson
2019-10-21 10:30 ` [PATCH 2/9] oe.types.path: " Ola x Nilsson
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/lib/oeqa/selftest/cases/recipetool.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index 1c701a40bf..c1562c63b2 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -685,7 +685,9 @@ class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
bitbake('%s:do_unpack' % testrecipe)
- self.assertEqual(open(self.testfile, 'r').read(), open(os.path.join(srcdir, filepath), 'r').read())
+ with open(self.testfile, 'r') as testfile:
+ with open(os.path.join(srcdir, filepath), 'r') as makefilein:
+ self.assertEqual(testfile.read(), makefilein.read())
def test_recipetool_appendsrcfiles_basic(self, destdir=None):
newfiles = [self.testfile]
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/9] oe.types.path: Use with to control file handle lifetime
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
@ 2019-10-21 10:30 ` Ola x Nilsson
2019-10-21 10:30 ` [PATCH 3/9] lib/oe/packagedata: " Ola x Nilsson
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/lib/oe/types.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
index 77ee7ee541..bbbabafbf6 100644
--- a/meta/lib/oe/types.py
+++ b/meta/lib/oe/types.py
@@ -154,7 +154,8 @@ def path(value, relativeto='', normalize='true', mustexist='false'):
if boolean(mustexist):
try:
- open(value, 'r')
+ with open(value, 'r'):
+ pass
except IOError as exc:
if exc.errno == errno.ENOENT:
raise ValueError("{0}: {1}".format(value, os.strerror(errno.ENOENT)))
@@ -183,4 +184,3 @@ def qemu_use_kvm(kvm, target_arch):
elif build_arch == target_arch:
use_kvm = True
return use_kvm
-
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/9] lib/oe/packagedata: Use with to control file handle lifetime
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
2019-10-21 10:30 ` [PATCH 2/9] oe.types.path: " Ola x Nilsson
@ 2019-10-21 10:30 ` Ola x Nilsson
2019-10-21 10:30 ` [PATCH 4/9] lib/oe/package_manager: " Ola x Nilsson
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/lib/oe/packagedata.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/meta/lib/oe/packagedata.py b/meta/lib/oe/packagedata.py
index cbde380b03..a82085a792 100644
--- a/meta/lib/oe/packagedata.py
+++ b/meta/lib/oe/packagedata.py
@@ -17,9 +17,8 @@ def read_pkgdatafile(fn):
if os.access(fn, os.R_OK):
import re
- f = open(fn, 'r')
- lines = f.readlines()
- f.close()
+ with open(fn, 'r') as f:
+ lines = f.readlines()
r = re.compile("([^:]+):\s*(.*)")
for l in lines:
m = r.match(l)
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/9] lib/oe/package_manager: Use with to control file handle lifetime
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
2019-10-21 10:30 ` [PATCH 2/9] oe.types.path: " Ola x Nilsson
2019-10-21 10:30 ` [PATCH 3/9] lib/oe/packagedata: " Ola x Nilsson
@ 2019-10-21 10:30 ` Ola x Nilsson
2019-10-21 10:30 ` [PATCH 5/9] tinderbox.bbclass: " Ola x Nilsson
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/lib/oe/package_manager.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 7c373715ad..c841fdbf29 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -298,7 +298,7 @@ class DpkgIndexer(Indexer):
release.write("Label: %s\n" % arch)
cmd += "PSEUDO_UNLOAD=1 %s release . >> Release" % apt_ftparchive
-
+
index_cmds.append(cmd)
deb_dirs_found = True
@@ -655,7 +655,7 @@ def create_packages_dir(d, subrepo_dir, deploydir, taskname, filterbydependencie
pn = d.getVar("PN")
seendirs = set()
multilibs = {}
-
+
bb.utils.remove(subrepo_dir, recurse=True)
bb.utils.mkdirhier(subrepo_dir)
@@ -1006,8 +1006,8 @@ class RpmPM(PackageManager):
def load_old_install_solution(self):
if not os.path.exists(self.solution_manifest):
return []
-
- return open(self.solution_manifest, 'r').read().split()
+ with open(self.solution_manifest, 'r') as fd:
+ return fd.read().split()
def _script_num_prefix(self, path):
files = os.listdir(path)
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/9] tinderbox.bbclass: Use with to control file handle lifetime
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
` (2 preceding siblings ...)
2019-10-21 10:30 ` [PATCH 4/9] lib/oe/package_manager: " Ola x Nilsson
@ 2019-10-21 10:30 ` Ola x Nilsson
2019-10-21 10:30 ` [PATCH 6/9] report-error.bbclass: " Ola x Nilsson
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/classes/tinderclient.bbclass | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/meta/classes/tinderclient.bbclass b/meta/classes/tinderclient.bbclass
index 00f453cec1..f7e41f2959 100644
--- a/meta/classes/tinderclient.bbclass
+++ b/meta/classes/tinderclient.bbclass
@@ -82,8 +82,8 @@ def tinder_format_http_post(d,status,log):
# we only need on build_status.pl but sending it
# always does not hurt
try:
- f = open(d.getVar('TMPDIR')+'/tinder-machine.id', 'r')
- id = f.read()
+ with open(d.getVar('TMPDIR') + '/tinder-machine.id') as f:
+ id = f.read()
variables['machine_id'] = id
except:
pass
@@ -231,7 +231,7 @@ def tinder_tinder_start(d, event):
config = tinder_print_info(d)
#env = tinder_print_env()
time_end = tinder_time_string()
- packages = " ".join( event.getPkgs() )
+ packages = " ".join( event.getPkgs() )
output = []
output.append( "---> TINDERBOX PRINTING CONFIGURATION %(time_start)s" )
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/9] report-error.bbclass: Use with to control file handle lifetime
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
` (3 preceding siblings ...)
2019-10-21 10:30 ` [PATCH 5/9] tinderbox.bbclass: " Ola x Nilsson
@ 2019-10-21 10:30 ` Ola x Nilsson
2019-10-21 10:30 ` [PATCH 7/9] package.bbclass: Use with to manage file handle lifetimes Ola x Nilsson
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/classes/report-error.bbclass | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/meta/classes/report-error.bbclass b/meta/classes/report-error.bbclass
index ea043b23e1..1a12db1206 100644
--- a/meta/classes/report-error.bbclass
+++ b/meta/classes/report-error.bbclass
@@ -78,19 +78,15 @@ python errorreport_handler () {
taskdata['task'] = task
if log:
try:
- logFile = codecs.open(log, 'r', 'utf-8')
- logdata = logFile.read()
-
+ with codecs.open(log, encoding='utf-8') as logFile:
+ logdata = logFile.read()
# Replace host-specific paths so the logs are cleaner
for d in ("TOPDIR", "TMPDIR"):
s = e.data.getVar(d)
if s:
logdata = logdata.replace(s, d)
-
- logFile.close()
except:
logdata = "Unable to read log file"
-
else:
logdata = "No Log"
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/9] package.bbclass: Use with to manage file handle lifetimes
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
` (4 preceding siblings ...)
2019-10-21 10:30 ` [PATCH 6/9] report-error.bbclass: " Ola x Nilsson
@ 2019-10-21 10:30 ` Ola x Nilsson
2019-10-21 10:30 ` [PATCH 8/9] devtool-source.bbclass: Use with to manage file handle lifetime Ola x Nilsson
2019-10-21 10:30 ` [PATCH 9/9] libc-package.bbclass: Use with to manage filehandle in do_spit_gconvs Ola x Nilsson
7 siblings, 0 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/classes/package.bbclass | 76 ++++++++++++++++++++------------------------
1 file changed, 34 insertions(+), 42 deletions(-)
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index d8bef3afb0..f955df1111 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -826,8 +826,9 @@ python fixup_perms () {
# Now we actually load from the configuration files
for conf in get_fs_perms_list(d).split():
- if os.path.exists(conf):
- f = open(conf)
+ if not os.path.exists(conf):
+ continue
+ with open(conf) as f:
for line in f:
if line.startswith('#'):
continue
@@ -848,7 +849,6 @@ python fixup_perms () {
fs_perms_table[entry.path] = entry
if entry.path in fs_link_table:
fs_link_table.pop(entry.path)
- f.close()
# Debug -- list out in-memory table
#for dir in fs_perms_table:
@@ -1424,10 +1424,9 @@ fi
pkgdest = d.getVar('PKGDEST')
pkgdatadir = d.getVar('PKGDESTWORK')
- data_file = pkgdatadir + d.expand("/${PN}" )
- f = open(data_file, 'w')
- f.write("PACKAGES: %s\n" % packages)
- f.close()
+ data_file = pkgdatadir + d.expand("/${PN}")
+ with open(data_file, 'w') as fd:
+ fd.write("PACKAGES: %s\n" % packages)
pn = d.getVar('PN')
global_variants = (d.getVar('MULTILIB_GLOBAL_VARIANTS') or "").split()
@@ -1778,21 +1777,20 @@ python package_do_shlibs() {
bb.note("Renaming %s to %s" % (old, new))
os.rename(old, new)
pkgfiles[pkg].remove(old)
-
+
shlibs_file = os.path.join(shlibswork_dir, pkg + ".list")
if len(sonames):
- fd = open(shlibs_file, 'w')
- for s in sonames:
- if s[0] in shlib_provider and s[1] in shlib_provider[s[0]]:
- (old_pkg, old_pkgver) = shlib_provider[s[0]][s[1]]
- if old_pkg != pkg:
- bb.warn('%s-%s was registered as shlib provider for %s, changing it to %s-%s because it was built later' % (old_pkg, old_pkgver, s[0], pkg, pkgver))
- bb.debug(1, 'registering %s-%s as shlib provider for %s' % (pkg, pkgver, s[0]))
- fd.write(s[0] + ':' + s[1] + ':' + s[2] + '\n')
- if s[0] not in shlib_provider:
- shlib_provider[s[0]] = {}
- shlib_provider[s[0]][s[1]] = (pkg, pkgver)
- fd.close()
+ with open(shlibs_file, 'w') as fd:
+ for s in sonames:
+ if s[0] in shlib_provider and s[1] in shlib_provider[s[0]]:
+ (old_pkg, old_pkgver) = shlib_provider[s[0]][s[1]]
+ if old_pkg != pkg:
+ bb.warn('%s-%s was registered as shlib provider for %s, changing it to %s-%s because it was built later' % (old_pkg, old_pkgver, s[0], pkg, pkgver))
+ bb.debug(1, 'registering %s-%s as shlib provider for %s' % (pkg, pkgver, s[0]))
+ fd.write(s[0] + ':' + s[1] + ':' + s[2] + '\n')
+ if s[0] not in shlib_provider:
+ shlib_provider[s[0]] = {}
+ shlib_provider[s[0]][s[1]] = (pkg, pkgver)
if needs_ldconfig and use_ldconfig:
bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg)
postinst = d.getVar('pkg_postinst_%s' % pkg)
@@ -1864,11 +1862,10 @@ python package_do_shlibs() {
deps_file = os.path.join(pkgdest, pkg + ".shlibdeps")
if os.path.exists(deps_file):
os.remove(deps_file)
- if len(deps):
- fd = open(deps_file, 'w')
- for dep in sorted(deps):
- fd.write(dep + '\n')
- fd.close()
+ if deps:
+ with open(deps_file, 'w') as fd:
+ for dep in sorted(deps):
+ fd.write(dep + '\n')
}
python package_do_pkgconfig () {
@@ -1898,9 +1895,8 @@ python package_do_pkgconfig () {
pkgconfig_provided[pkg].append(name)
if not os.access(file, os.R_OK):
continue
- f = open(file, 'r')
- lines = f.readlines()
- f.close()
+ with open(file, 'r') as f:
+ lines = f.readlines()
for l in lines:
m = var_re.match(l)
if m:
@@ -1918,10 +1914,9 @@ python package_do_pkgconfig () {
for pkg in packages.split():
pkgs_file = os.path.join(shlibswork_dir, pkg + ".pclist")
if pkgconfig_provided[pkg] != []:
- f = open(pkgs_file, 'w')
- for p in pkgconfig_provided[pkg]:
- f.write('%s\n' % p)
- f.close()
+ with open(pkgs_file, 'w') as f:
+ for p in pkgconfig_provided[pkg]:
+ f.write('%s\n' % p)
# Go from least to most specific since the last one found wins
for dir in reversed(shlibs_dirs):
@@ -1931,9 +1926,8 @@ python package_do_pkgconfig () {
m = re.match(r'^(.*)\.pclist$', file)
if m:
pkg = m.group(1)
- fd = open(os.path.join(dir, file))
- lines = fd.readlines()
- fd.close()
+ with open(os.path.join(dir, file)) as fd:
+ lines = fd.readlines()
pkgconfig_provided[pkg] = []
for l in lines:
pkgconfig_provided[pkg].append(l.rstrip())
@@ -1951,10 +1945,9 @@ python package_do_pkgconfig () {
bb.note("couldn't find pkgconfig module '%s' in any package" % n)
deps_file = os.path.join(pkgdest, pkg + ".pcdeps")
if len(deps):
- fd = open(deps_file, 'w')
- for dep in deps:
- fd.write(dep + '\n')
- fd.close()
+ with open(deps_file, 'w') as fd:
+ for dep in deps:
+ fd.write(dep + '\n')
}
def read_libdep_files(d):
@@ -1965,9 +1958,8 @@ def read_libdep_files(d):
for extension in ".shlibdeps", ".pcdeps", ".clilibdeps":
depsfile = d.expand("${PKGDEST}/" + pkg + extension)
if os.access(depsfile, os.R_OK):
- fd = open(depsfile)
- lines = fd.readlines()
- fd.close()
+ with open(depsfile) as fd:
+ lines = fd.readlines()
for l in lines:
l.rstrip()
deps = bb.utils.explode_dep_versions2(l)
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 8/9] devtool-source.bbclass: Use with to manage file handle lifetime
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
` (5 preceding siblings ...)
2019-10-21 10:30 ` [PATCH 7/9] package.bbclass: Use with to manage file handle lifetimes Ola x Nilsson
@ 2019-10-21 10:30 ` Ola x Nilsson
2019-10-21 10:30 ` [PATCH 9/9] libc-package.bbclass: Use with to manage filehandle in do_spit_gconvs Ola x Nilsson
7 siblings, 0 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Replace copy-and-if with a filtering list comprehension.
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/classes/devtool-source.bbclass | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/meta/classes/devtool-source.bbclass b/meta/classes/devtool-source.bbclass
index a8110006fb..280d6009f3 100644
--- a/meta/classes/devtool-source.bbclass
+++ b/meta/classes/devtool-source.bbclass
@@ -97,17 +97,15 @@ python devtool_post_unpack() {
local_files = oe.recipeutils.get_recipe_local_files(d)
if is_kernel_yocto:
- for key in local_files.copy():
- if key.endswith('scc'):
- sccfile = open(local_files[key], 'r')
+ for key in [f for f in local_files if f.endswith('scc')]:
+ with open(local_files[key], 'r') as sccfile:
for l in sccfile:
line = l.split()
if line and line[0] in ('kconf', 'patch'):
cfg = os.path.join(os.path.dirname(local_files[key]), line[-1])
- if not cfg in local_files.values():
+ if cfg not in local_files.values():
local_files[line[-1]] = cfg
shutil.copy2(cfg, workdir)
- sccfile.close()
# Ignore local files with subdir={BP}
srcabspath = os.path.abspath(srcsubdir)
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 9/9] libc-package.bbclass: Use with to manage filehandle in do_spit_gconvs
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
` (6 preceding siblings ...)
2019-10-21 10:30 ` [PATCH 8/9] devtool-source.bbclass: Use with to manage file handle lifetime Ola x Nilsson
@ 2019-10-21 10:30 ` Ola x Nilsson
7 siblings, 0 replies; 9+ messages in thread
From: Ola x Nilsson @ 2019-10-21 10:30 UTC (permalink / raw)
To: openembedded-core
Tweak the write loop slightly to avoid dict lookups that can easily be
done in the for loop.
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
meta/classes/libc-package.bbclass | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/meta/classes/libc-package.bbclass b/meta/classes/libc-package.bbclass
index a66e540884..de816bcec1 100644
--- a/meta/classes/libc-package.bbclass
+++ b/meta/classes/libc-package.bbclass
@@ -346,14 +346,13 @@ python package_do_split_gconvs () {
if use_bin == "compile":
makefile = oe.path.join(d.getVar("WORKDIR"), "locale-tree", "Makefile")
- m = open(makefile, "w")
- m.write("all: %s\n\n" % " ".join(commands.keys()))
- total = len(commands)
- for i, cmd in enumerate(commands):
- m.write(cmd + ":\n")
- m.write("\t@echo 'Progress %d/%d'\n" % (i, total))
- m.write("\t" + commands[cmd] + "\n\n")
- m.close()
+ with open(makefile, "w") as m:
+ m.write("all: %s\n\n" % " ".join(commands.keys()))
+ total = len(commands)
+ for i, (maketarget, makerecipe) in enumerate(commands.items()):
+ m.write(maketarget + ":\n")
+ m.write("\t@echo 'Progress %d/%d'\n" % (i, total))
+ m.write("\t" + makerecipe + "\n\n")
d.setVar("EXTRA_OEMAKE", "-C %s ${PARALLEL_MAKE}" % (os.path.dirname(makefile)))
d.setVarFlag("oe_runmake", "progress", "outof:Progress\s(\d+)/(\d+)")
bb.note("Executing binary locale generation makefile")
--
2.11.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-10-21 10:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 10:30 [PATCH 1/9] oeqa/selftest/recipetool: Use with to control file handle lifetime Ola x Nilsson
2019-10-21 10:30 ` [PATCH 2/9] oe.types.path: " Ola x Nilsson
2019-10-21 10:30 ` [PATCH 3/9] lib/oe/packagedata: " Ola x Nilsson
2019-10-21 10:30 ` [PATCH 4/9] lib/oe/package_manager: " Ola x Nilsson
2019-10-21 10:30 ` [PATCH 5/9] tinderbox.bbclass: " Ola x Nilsson
2019-10-21 10:30 ` [PATCH 6/9] report-error.bbclass: " Ola x Nilsson
2019-10-21 10:30 ` [PATCH 7/9] package.bbclass: Use with to manage file handle lifetimes Ola x Nilsson
2019-10-21 10:30 ` [PATCH 8/9] devtool-source.bbclass: Use with to manage file handle lifetime Ola x Nilsson
2019-10-21 10:30 ` [PATCH 9/9] libc-package.bbclass: Use with to manage filehandle in do_spit_gconvs Ola x Nilsson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.