Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-28 Thread John Snow
On 9/28/20 8:09 AM, Markus Armbruster wrote: Eric Blake writes: On 9/25/20 8:52 AM, Markus Armbruster wrote: This was my best attempt to open the file read/write, creating it if it doesn't exist. Plain f = open(pathname, "r+", encoding='utf-8') fails instead of creates, and

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-28 Thread Markus Armbruster
Eric Blake writes: > On 9/25/20 8:52 AM, Markus Armbruster wrote: > This was my best attempt to open the file read/write, creating it if it doesn't exist. Plain f = open(pathname, "r+", encoding='utf-8') fails instead of creates, and

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-25 Thread John Snow
On 9/25/20 9:26 AM, Eduardo Habkost wrote: On Fri, Sep 25, 2020 at 03:15:57PM +0200, Markus Armbruster wrote: Cleber Rosa writes: On Wed, Sep 23, 2020 at 02:37:27PM -0400, John Snow wrote: On 9/23/20 11:26 AM, Eduardo Habkost wrote: On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow wrote:

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-25 Thread Eric Blake
On 9/25/20 8:52 AM, Markus Armbruster wrote: This was my best attempt to open the file read/write, creating it if it doesn't exist. Plain f = open(pathname, "r+", encoding='utf-8') fails instead of creates, and f = open(pathname, "w+", encoding='utf-8') truncates. If you

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-25 Thread Markus Armbruster
Daniel P. Berrangé writes: > On Fri, Sep 25, 2020 at 03:15:57PM +0200, Markus Armbruster wrote: >> Cleber Rosa writes: >> >> > On Wed, Sep 23, 2020 at 02:37:27PM -0400, John Snow wrote: >> >> On 9/23/20 11:26 AM, Eduardo Habkost wrote: >> >> > On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-25 Thread Eric Blake
On 9/25/20 8:24 AM, Daniel P. Berrangé wrote: This code: fd = os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666) f = open(fd, 'r+', encoding='utf-8') This was my best attempt to open the file read/write, creating it if it doesn't exist. Plain f = open(pathname, "r

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-25 Thread Eduardo Habkost
On Fri, Sep 25, 2020 at 03:15:57PM +0200, Markus Armbruster wrote: > Cleber Rosa writes: > > > On Wed, Sep 23, 2020 at 02:37:27PM -0400, John Snow wrote: > >> On 9/23/20 11:26 AM, Eduardo Habkost wrote: > >> > On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow wrote: > >> > > Make the file handl

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-25 Thread Daniel P . Berrangé
On Fri, Sep 25, 2020 at 03:15:57PM +0200, Markus Armbruster wrote: > Cleber Rosa writes: > > > On Wed, Sep 23, 2020 at 02:37:27PM -0400, John Snow wrote: > >> On 9/23/20 11:26 AM, Eduardo Habkost wrote: > >> > On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow wrote: > >> > > Make the file handl

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-25 Thread Markus Armbruster
Cleber Rosa writes: > On Wed, Sep 23, 2020 at 02:37:27PM -0400, John Snow wrote: >> On 9/23/20 11:26 AM, Eduardo Habkost wrote: >> > On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow wrote: >> > > Make the file handling here just a tiny bit more idiomatic. >> > > (I realize this is heavily subj

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-24 Thread Cleber Rosa
On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow wrote: > Make the file handling here just a tiny bit more idiomatic. > (I realize this is heavily subjective.) > > Use exist_ok=True for os.makedirs and remove the exception, > use fdopen() to wrap the file descriptor in a File-like object, > and

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-24 Thread Cleber Rosa
On Wed, Sep 23, 2020 at 02:37:27PM -0400, John Snow wrote: > On 9/23/20 11:26 AM, Eduardo Habkost wrote: > > On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow wrote: > > > Make the file handling here just a tiny bit more idiomatic. > > > (I realize this is heavily subjective.) > > > > > > Use ex

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-23 Thread John Snow
On 9/23/20 11:26 AM, Eduardo Habkost wrote: On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow wrote: Make the file handling here just a tiny bit more idiomatic. (I realize this is heavily subjective.) Use exist_ok=True for os.makedirs and remove the exception, use fdopen() to wrap the file de

Re: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-23 Thread Eduardo Habkost
On Tue, Sep 22, 2020 at 05:00:51PM -0400, John Snow wrote: > Make the file handling here just a tiny bit more idiomatic. > (I realize this is heavily subjective.) > > Use exist_ok=True for os.makedirs and remove the exception, > use fdopen() to wrap the file descriptor in a File-like object, > and

[PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic

2020-09-22 Thread John Snow
Make the file handling here just a tiny bit more idiomatic. (I realize this is heavily subjective.) Use exist_ok=True for os.makedirs and remove the exception, use fdopen() to wrap the file descriptor in a File-like object, and use a context manager for managing the file pointer. Signed-off-by: J