-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added utime() to the os library #6923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
We are getting incredibly short on space on the non-Express SAMD21 builds again, so when #6247 is merged, this is probably going to make some builds too big. This is true even though I disabled the bulk of #6247 on the small builds. With #6247, before this addition, the I am not saying not to add this, just that we will need to do some more squeezing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! We want to make our API's be the same or a subset of what CPython provides. For that reason, could you make utime()
take a 2-tuple instead of a plain int? Ignore one or the other value, I guess, or require that they are the same.
You can skip the ns
argument support.
From https://docs.python.org/3/library/os.html#os.utime):
os.utime(path, times=None, *, [ns, ]dir_fd=None, follow_symlinks=True)
Set the access and modified times of the file specified by path.
utime() takes two optional parameters, times and ns. These specify the times set on path and are used as follows:
- If ns is specified, it must be a 2-tuple of the form (atime_ns, mtime_ns) where each member is an int expressing nanoseconds.
- If times is not None, it must be a 2-tuple of the form (atime, mtime) where each member is an int or float expressing seconds.
- If times is None and ns is unspecified, this is equivalent to specifying ns=(atime_ns, mtime_ns) where both times are the current time.
Hi @dhalbert , Thank you for your review and feedback! I have completed the changes to accept a Tuple[int, int], and ignore the second int. Please let me know if you have any comments. As you anticipated, there are a few builds that get too big with this change. Please let me know if there is anything I can help with. Thank you in advance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ! Impl looks good. I still need to figure out how to make this fit, so I will leave it open for now.
Thank you Dan! |
I squeezed some builds, but since the last time the jobs were run, there was other code added elsewhere, so I need to look further. |
Hi Dan. I understand. I can see this can take some time and effort. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally it fits! @isacben thanks for your patience!
Wow @dhalbert that's amazing! |
Hi,
This PR is to add the utime() function to the os library, to solve issue #5978.
Description
This implementation changes the timestamp of a file. The function takes 2 positional arguments:
Example:
Limitations
The implementation takes advantage of the function f_utime() from the oofatfs library. Because of that, utime() sets the access time and the modified time of the file to the same timestamp. Due to this limitation, utime() only takes 1 integer for the timestamp expressed in seconds, compared to the CPython implementation, which takes a 2-tuple for the access time and the modified time express either in seconds or nanoseconds.
I tested with the Adafruit Father RP2040.
Thanks!