Fixed an issue showing the MPy file system data because MPy uses an epoch different from Posix standard. eric7

Sun, 20 Feb 2022 16:25:22 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 20 Feb 2022 16:25:22 +0100
branch
eric7
changeset 8952
b6311a17471a
parent 8951
996bb6fea7dd
child 8953
3e8adcb59aad

Fixed an issue showing the MPy file system data because MPy uses an epoch different from Posix standard.

eric7/APIs/Python3/eric7.api file | annotate | diff | comparison | revisions
eric7/Documentation/Help/source.qch file | annotate | diff | comparison | revisions
eric7/Documentation/Source/eric7.MicroPython.MicroPythonFileSystemUtilities.html file | annotate | diff | comparison | revisions
eric7/MicroPython/MicroPythonFileManager.py file | annotate | diff | comparison | revisions
eric7/MicroPython/MicroPythonFileSystemUtilities.py file | annotate | diff | comparison | revisions
--- a/eric7/APIs/Python3/eric7.api	Fri Feb 18 17:44:19 2022 +0100
+++ b/eric7/APIs/Python3/eric7.api	Sun Feb 20 16:25:22 2022 +0100
@@ -2628,12 +2628,13 @@
 eric7.MicroPython.MicroPythonFileManagerWidget.MicroPythonFileManagerWidget.start?4()
 eric7.MicroPython.MicroPythonFileManagerWidget.MicroPythonFileManagerWidget.stop?4()
 eric7.MicroPython.MicroPythonFileManagerWidget.MicroPythonFileManagerWidget?1(commandsInterface, deviceWithLocalAccess, parent=None)
+eric7.MicroPython.MicroPythonFileSystemUtilities.MPY_EPOCH?7
 eric7.MicroPython.MicroPythonFileSystemUtilities.decoratedName?4(name, mode, isDir=False)
 eric7.MicroPython.MicroPythonFileSystemUtilities.fstat?4(filename)
 eric7.MicroPython.MicroPythonFileSystemUtilities.isVisible?4(name, showHidden)
 eric7.MicroPython.MicroPythonFileSystemUtilities.listdirStat?4(dirname, showHidden=False)
 eric7.MicroPython.MicroPythonFileSystemUtilities.mode2string?4(mode)
-eric7.MicroPython.MicroPythonFileSystemUtilities.mtime2string?4(mtime)
+eric7.MicroPython.MicroPythonFileSystemUtilities.mtime2string?4(mtime, adjustEpoch=False)
 eric7.MicroPython.MicroPythonGraphWidget.MicroPythonGraphWidget.dataFlood?7
 eric7.MicroPython.MicroPythonGraphWidget.MicroPythonGraphWidget.hasData?4()
 eric7.MicroPython.MicroPythonGraphWidget.MicroPythonGraphWidget.isDirty?4()
Binary file eric7/Documentation/Help/source.qch has changed
--- a/eric7/Documentation/Source/eric7.MicroPython.MicroPythonFileSystemUtilities.html	Fri Feb 18 17:44:19 2022 +0100
+++ b/eric7/Documentation/Source/eric7.MicroPython.MicroPythonFileSystemUtilities.html	Sun Feb 20 16:25:22 2022 +0100
@@ -14,7 +14,7 @@
 <h3>Global Attributes</h3>
 
 <table>
-<tr><td>None</td></tr>
+<tr><td>MPY_EPOCH</td></tr>
 </table>
 <h3>Classes</h3>
 
@@ -216,7 +216,7 @@
 <hr />
 <a NAME="mtime2string" ID="mtime2string"></a>
 <h2>mtime2string</h2>
-<b>mtime2string</b>(<i>mtime</i>)
+<b>mtime2string</b>(<i>mtime, adjustEpoch=False</i>)
 
 <p>
     Function to convert a time value to a string representation.
@@ -227,6 +227,11 @@
 <dd>
 time value
 </dd>
+<dt><i>adjustEpoch</i> (bool (optional))</dt>
+<dd>
+flag indicating to adjust the time for the difference
+        of the MPy epoch (defaults to False)
+</dd>
 </dl>
 <dl>
 <dt>Return:</dt>
--- a/eric7/MicroPython/MicroPythonFileManager.py	Fri Feb 18 17:44:19 2022 +0100
+++ b/eric7/MicroPython/MicroPythonFileManager.py	Sun Feb 20 16:25:22 2022 +0100
@@ -90,7 +90,7 @@
             result = [(decoratedName(name, mode),
                        mode2string(mode),
                        str(size),
-                       mtime2string(mtime)) for
+                       mtime2string(mtime, adjustEpoch=True)) for
                       name, (mode, size, mtime) in filesList]
             self.longListFiles.emit(tuple(result))
         except Exception as exc:
--- a/eric7/MicroPython/MicroPythonFileSystemUtilities.py	Fri Feb 18 17:44:19 2022 +0100
+++ b/eric7/MicroPython/MicroPythonFileSystemUtilities.py	Sun Feb 20 16:25:22 2022 +0100
@@ -11,16 +11,24 @@
 import stat
 import os
 
+MPY_EPOCH = time.mktime((2000, 1, 1, 0, 0, 0, 0, 1, -1))
+# MPy epoch is 2000-01-01 0:0:0 UTC
 
-def mtime2string(mtime):
+
+def mtime2string(mtime, adjustEpoch=False):
     """
     Function to convert a time value to a string representation.
     
     @param mtime time value
     @type int
+    @param adjustEpoch flag indicating to adjust the time for the difference
+        of the MPy epoch (defaults to False)
+    @type bool (optional)
     @return string representation of the given time
     @rtype str
     """
+    if adjustEpoch:
+        mtime += MPY_EPOCH
     return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(mtime))
 
 

eric ide

mercurial