All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile
@ 2019-10-21  9:07 Ola x Nilsson
  2019-10-21  9:07 ` [PATCH 2/2] bitbake: ConfHandler: Use with to manage filehandle lifetime Ola x Nilsson
  0 siblings, 1 reply; 6+ messages in thread
From: Ola x Nilsson @ 2019-10-21  9:07 UTC (permalink / raw)
  To: bitbake-devel

Signed-off-by: Ola x Nilsson <olani@axis.com>
---
 lib/prserv/serv.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index be3acec3..2bc68904 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -379,9 +379,8 @@ def stop_daemon(host, port):
     ip = socket.gethostbyname(host)
     pidfile = PIDPREFIX % (ip, port)
     try:
-        pf = open(pidfile,'r')
-        pid = int(pf.readline().strip())
-        pf.close()
+        with open(pidfile) as pf:
+            pid = int(pf.readline().strip())
     except IOError:
         pid = None
 
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] bitbake: ConfHandler: Use with to manage filehandle lifetime
  2019-10-21  9:07 [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile Ola x Nilsson
@ 2019-10-21  9:07 ` Ola x Nilsson
  0 siblings, 0 replies; 6+ messages in thread
From: Ola x Nilsson @ 2019-10-21  9:07 UTC (permalink / raw)
  To: bitbake-devel

Signed-off-by: Ola x Nilsson <olani@axis.com>
---
 lib/bb/parse/parse_py/ConfHandler.py | 44 ++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/lib/bb/parse/parse_py/ConfHandler.py b/lib/bb/parse/parse_py/ConfHandler.py
index 2e84b913..af64d344 100644
--- a/lib/bb/parse/parse_py/ConfHandler.py
+++ b/lib/bb/parse/parse_py/ConfHandler.py
@@ -119,30 +119,30 @@ def handle(fn, data, include):
         oldfile = data.getVar('FILE', False)
 
     abs_fn = resolve_file(fn, data)
-    f = open(abs_fn, 'r')
+    with open(abs_fn, 'r') as f:
 
-    statements = ast.StatementGroup()
-    lineno = 0
-    while True:
-        lineno = lineno + 1
-        s = f.readline()
-        if not s:
-            break
-        w = s.strip()
-        # skip empty lines
-        if not w:
-            continue
-        s = s.rstrip()
-        while s[-1] == '\\':
-            s2 = f.readline().rstrip()
+        statements = ast.StatementGroup()
+        lineno = 0
+        while True:
             lineno = lineno + 1
-            if (not s2 or s2 and s2[0] != "#") and s[0] == "#" :
-                bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s))
-            s = s[:-1] + s2
-        # skip comments
-        if s[0] == '#':
-            continue
-        feeder(lineno, s, abs_fn, statements)
+            s = f.readline()
+            if not s:
+                break
+            w = s.strip()
+            # skip empty lines
+            if not w:
+                continue
+            s = s.rstrip()
+            while s[-1] == '\\':
+                s2 = f.readline().rstrip()
+                lineno = lineno + 1
+                if (not s2 or s2 and s2[0] != "#") and s[0] == "#" :
+                    bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s))
+                s = s[:-1] + s2
+            # skip comments
+            if s[0] == '#':
+                continue
+            feeder(lineno, s, abs_fn, statements)
 
     # DONE WITH PARSING... time to evaluate
     data.setVar('FILE', abs_fn)
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile
  2019-12-30 11:00   ` Richard Purdie
@ 2019-12-30 12:20     ` Peter Kjellerstedt
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Kjellerstedt @ 2019-12-30 12:20 UTC (permalink / raw)
  To: Richard Purdie, Ola x Nilsson, bitbake-devel

> -----Original Message-----
> From: Richard Purdie <richard.purdie@linuxfoundation.org>
> Sent: den 30 december 2019 12:00
> To: Peter Kjellerstedt <peter.kjellerstedt@axis.com>; Ola x Nilsson
> <Ola.x.Nilsson@axis.com>; bitbake-devel@lists.openembedded.org
> Subject: Re: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with
> while reading pidfile
> 
> On Fri, 2019-12-20 at 17:22 +0000, Peter Kjellerstedt wrote:
> > > -----Original Message-----
> > > From: bitbake-devel-bounces@lists.openembedded.org <bitbake-devel-
> > > bounces@lists.openembedded.org> On Behalf Of Ola x Nilsson
> > > Sent: den 20 december 2019 15:23
> > > To: bitbake-devel@lists.openembedded.org
> > > Subject: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with
> > > while
> > > reading pidfile
> > >
> > > Signed-off-by: Ola x Nilsson <olani@axis.com>
> > > ---
> > >  lib/prserv/serv.py | 5 ++---
> > >  1 file changed, 2 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
> > > index 3124b079..708b2e0a 100644
> > > --- a/lib/prserv/serv.py
> > > +++ b/lib/prserv/serv.py
> > > @@ -353,9 +353,8 @@ def start_daemon(dbfile, host, port, logfile):
> > >      ip = socket.gethostbyname(host)
> > >      pidfile = PIDPREFIX % (ip, port)
> > >      try:
> > > -        pf = open(pidfile,'r')
> > > -        pid = int(pf.readline().strip())
> > > -        pf.close()
> > > +        with open(pidfile) as pf:
> > > +            pid = int(pf.readline().strip())
> > >      except IOError:
> > >          pid = None
> > >
> > > --
> > > 2.11.0
> >
> > This only half the patch. Please add the following:
> >
> > @@ -292,10 +292,9 @@ class PRServer(SimpleXMLRPCServer):
> >          logger.addHandler(streamhandler)
> >
> >          # write pidfile
> > -        pid = str(os.getpid())
> > -        pf = open(self.pidfile, 'w')
> > -        pf.write("%s\n" % pid)
> > -        pf.close()
> > +        pid = str(os.getpid())
> > +        with open(self.pidfile, 'w') as pf:
> > +            pf.write("%s\n" % pid)
> >
> >          self.work_forever()
> >          self.delpid()
> >
> 
> I've handled this but asking me to manually merge hunks of patches
> together before applying them seems a little potentially error prone?
> 
> Cheers,
> 
> Richard

Well, I mainly meant for Ola to send an updated patch with both hunks, but 
I guess I should have stated that in my response. Anyway, thanks for taking 
care of it.

//Peter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile
  2019-12-20 17:22 ` Peter Kjellerstedt
@ 2019-12-30 11:00   ` Richard Purdie
  2019-12-30 12:20     ` Peter Kjellerstedt
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Purdie @ 2019-12-30 11:00 UTC (permalink / raw)
  To: Peter Kjellerstedt, Ola x Nilsson, bitbake-devel

On Fri, 2019-12-20 at 17:22 +0000, Peter Kjellerstedt wrote:
> > -----Original Message-----
> > From: bitbake-devel-bounces@lists.openembedded.org <bitbake-devel-
> > bounces@lists.openembedded.org> On Behalf Of Ola x Nilsson
> > Sent: den 20 december 2019 15:23
> > To: bitbake-devel@lists.openembedded.org
> > Subject: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with
> > while
> > reading pidfile
> > 
> > Signed-off-by: Ola x Nilsson <olani@axis.com>
> > ---
> >  lib/prserv/serv.py | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
> > index 3124b079..708b2e0a 100644
> > --- a/lib/prserv/serv.py
> > +++ b/lib/prserv/serv.py
> > @@ -353,9 +353,8 @@ def start_daemon(dbfile, host, port, logfile):
> >      ip = socket.gethostbyname(host)
> >      pidfile = PIDPREFIX % (ip, port)
> >      try:
> > -        pf = open(pidfile,'r')
> > -        pid = int(pf.readline().strip())
> > -        pf.close()
> > +        with open(pidfile) as pf:
> > +            pid = int(pf.readline().strip())
> >      except IOError:
> >          pid = None
> > 
> > --
> > 2.11.0
> 
> This only half the patch. Please add the following:
> 
> @@ -292,10 +292,9 @@ class PRServer(SimpleXMLRPCServer):
>          logger.addHandler(streamhandler)
>  
>          # write pidfile
> -        pid = str(os.getpid()) 
> -        pf = open(self.pidfile, 'w')
> -        pf.write("%s\n" % pid)
> -        pf.close()
> +        pid = str(os.getpid())
> +        with open(self.pidfile, 'w') as pf:
> +            pf.write("%s\n" % pid)
>  
>          self.work_forever()
>          self.delpid()
> 

I've handled this but asking me to manually merge hunks of patches
together before applying them seems a little potentially error prone?

Cheers,

Richard



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile
  2019-12-20 14:23 [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile Ola x Nilsson
@ 2019-12-20 17:22 ` Peter Kjellerstedt
  2019-12-30 11:00   ` Richard Purdie
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Kjellerstedt @ 2019-12-20 17:22 UTC (permalink / raw)
  To: Ola x Nilsson, bitbake-devel

> -----Original Message-----
> From: bitbake-devel-bounces@lists.openembedded.org <bitbake-devel-
> bounces@lists.openembedded.org> On Behalf Of Ola x Nilsson
> Sent: den 20 december 2019 15:23
> To: bitbake-devel@lists.openembedded.org
> Subject: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with while
> reading pidfile
> 
> Signed-off-by: Ola x Nilsson <olani@axis.com>
> ---
>  lib/prserv/serv.py | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
> index 3124b079..708b2e0a 100644
> --- a/lib/prserv/serv.py
> +++ b/lib/prserv/serv.py
> @@ -353,9 +353,8 @@ def start_daemon(dbfile, host, port, logfile):
>      ip = socket.gethostbyname(host)
>      pidfile = PIDPREFIX % (ip, port)
>      try:
> -        pf = open(pidfile,'r')
> -        pid = int(pf.readline().strip())
> -        pf.close()
> +        with open(pidfile) as pf:
> +            pid = int(pf.readline().strip())
>      except IOError:
>          pid = None
> 
> --
> 2.11.0

This only half the patch. Please add the following:

@@ -292,10 +292,9 @@ class PRServer(SimpleXMLRPCServer):
         logger.addHandler(streamhandler)
 
         # write pidfile
-        pid = str(os.getpid()) 
-        pf = open(self.pidfile, 'w')
-        pf.write("%s\n" % pid)
-        pf.close()
+        pid = str(os.getpid())
+        with open(self.pidfile, 'w') as pf:
+            pf.write("%s\n" % pid)
 
         self.work_forever()
         self.delpid()

//Peter



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile
@ 2019-12-20 14:23 Ola x Nilsson
  2019-12-20 17:22 ` Peter Kjellerstedt
  0 siblings, 1 reply; 6+ messages in thread
From: Ola x Nilsson @ 2019-12-20 14:23 UTC (permalink / raw)
  To: bitbake-devel

Signed-off-by: Ola x Nilsson <olani@axis.com>
---
 lib/prserv/serv.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 3124b079..708b2e0a 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -353,9 +353,8 @@ def start_daemon(dbfile, host, port, logfile):
     ip = socket.gethostbyname(host)
     pidfile = PIDPREFIX % (ip, port)
     try:
-        pf = open(pidfile,'r')
-        pid = int(pf.readline().strip())
-        pf.close()
+        with open(pidfile) as pf:
+            pid = int(pf.readline().strip())
     except IOError:
         pid = None
 
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-12-30 12:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21  9:07 [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile Ola x Nilsson
2019-10-21  9:07 ` [PATCH 2/2] bitbake: ConfHandler: Use with to manage filehandle lifetime Ola x Nilsson
2019-12-20 14:23 [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile Ola x Nilsson
2019-12-20 17:22 ` Peter Kjellerstedt
2019-12-30 11:00   ` Richard Purdie
2019-12-30 12:20     ` Peter Kjellerstedt

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.