[Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-09 Thread Ben Hoyt
Hi folks, As pointed out to me recently in an issue report [1] on my scandir module, Python's os.stat() simply discards most of the file attribute information fetched via the Win32 system calls. On Windows, os.stat() calls CreateFile to open the file and get the dwFileAttributes value, but it thro

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Paul Moore
On 10 June 2014 05:02, Ben Hoyt wrote: > To solve this problem, what do people think about adding an > "st_winattrs" attribute to the object returned by os.stat() on > Windows? +1. Given the precedent of Linux- and OS X-specific attributes, this seems like a no-brainer to me. Paul __

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Victor Stinner
2014-06-10 6:02 GMT+02:00 Ben Hoyt : > To solve this problem, what do people think about adding an > "st_winattrs" attribute to the object returned by os.stat() on > Windows? > (...) > FILE_ATTRIBUTE_HIDDEN = 2 # constant defined in Windows.h > > if hasattr(st, 'st_winattrs') and st.st_winattr

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread MRAB
On 2014-06-10 05:02, Ben Hoyt wrote: [snip] FILE_ATTRIBUTE_HIDDEN = 2 # constant defined in Windows.h def is_hidden(path): if startswith(os.path.basename(path), '.'): return True st = os.stat(path) if hasattr(st, 'st_winattrs') and st.st_winattrs & FILE_ATTRIBUTE_HIDDEN

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Ben Hoyt
> > FILE_ATTRIBUTE_HIDDEN = 2 # constant defined in Windows.h > > > > if hasattr(st, 'st_winattrs') and st.st_winattrs & > > FILE_ATTRIBUTE_HIDDEN: > > I don't like such API, it requires to import constants, use masks, etc. > > I would prefer something like: > >if st.win_hidden: ... > > O

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Ben Hoyt
>> if hasattr(st, 'st_winattrs') and st.st_winattrs & >> FILE_ATTRIBUTE_HIDDEN: > > That could be written more succinctly as: > > if getattr(st, 'st_winattrs', 0) & FILE_ATTRIBUTE_HIDDEN: > >> return True >> return False Yes, good call. Or one further: return getattr(

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Paul Moore
On 10 June 2014 13:19, Ben Hoyt wrote: > Because these are fixed-forever constants, I suspect in library code > and the like people would just KISS and use an integer literal and a > comment, avoiding the import/constant thing: The stat module exposes a load of constants - why not add the (curren

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Ben Hoyt
> The stat module exposes a load of constants - why not add the > (currently known) ones there? Finding the values of Windows constants > if you don't have access to the C headers can be a pain, so having > them defined *somewhere* as named values is useful. So stat.FILE_ATTRIBUTES_HIDDEN and the

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Paul Moore
On 10 June 2014 13:58, Ben Hoyt wrote: > So stat.FILE_ATTRIBUTES_HIDDEN and the like? Yep. (Maybe WIN_FILE_ATTRIBUTES_HIDDEN, but the Unix ones don't have an OA name prefix, so I'd go with your original). Paul ___ Python-Dev mailing list Python-Dev@pyt

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Ethan Furman
On 06/09/2014 09:02 PM, Ben Hoyt wrote: To solve this problem, what do people think about adding an "st_winattrs" attribute to the object returned by os.stat() on Windows? +1 to the idea, whatever the exact implementation. -- ~Ethan~ ___ Python-Dev

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Zachary Ware
On Tue, Jun 10, 2014 at 12:17 PM, Ethan Furman wrote: > On 06/09/2014 09:02 PM, Ben Hoyt wrote: >> To solve this problem, what do people think about adding an >> "st_winattrs" attribute to the object returned by os.stat() on >> Windows? > > > +1 to the idea, whatever the exact implementation. Agr

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Ben Hoyt
>> To solve this problem, what do people think about adding an >> "st_winattrs" attribute to the object returned by os.stat() on >> Windows? > > +1 to the idea, whatever the exact implementation. Cool. I think we should add a st_winattrs integer attribute (on Windows) and then also add the FILE_A

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-10 Thread Zachary Ware
On Tue, Jun 10, 2014 at 2:04 PM, Ben Hoyt wrote: >>> To solve this problem, what do people think about adding an >>> "st_winattrs" attribute to the object returned by os.stat() on >>> Windows? >> >> +1 to the idea, whatever the exact implementation. > > Cool. > > I think we should add a st_winattr

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-11 Thread Ben Hoyt
>> What would be the next steps to get this to happen? Open an issue on >> bugs.python.org and submit a patch with tests? > > Yep! Okay, I've done step one (opened an issue on bugs.python.org), and hope to provide a patch in the next few weeks if no-one else does (I've never compiled CPython on Wi

Re: [Python-Dev] Returning Windows file attribute information via os.stat()

2014-06-11 Thread Terry Reedy
On 6/11/2014 9:27 AM, Ben Hoyt wrote: What would be the next steps to get this to happen? Open an issue on bugs.python.org and submit a patch with tests? Yep! Okay, I've done step one (opened an issue on bugs.python.org), and hope to provide a patch in the next few weeks if no-one else does (