src/eric7/MicroPython/MicroPythonFileSystemUtilities.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
16 16
17 17
18 def mtime2string(mtime, adjustEpoch=False): 18 def mtime2string(mtime, adjustEpoch=False):
19 """ 19 """
20 Function to convert a time value to a string representation. 20 Function to convert a time value to a string representation.
21 21
22 @param mtime time value 22 @param mtime time value
23 @type int 23 @type int
24 @param adjustEpoch flag indicating to adjust the time for the difference 24 @param adjustEpoch flag indicating to adjust the time for the difference
25 of the MPy epoch (defaults to False) 25 of the MPy epoch (defaults to False)
26 @type bool (optional) 26 @type bool (optional)
33 33
34 34
35 def mode2string(mode): 35 def mode2string(mode):
36 """ 36 """
37 Function to convert a mode value to a string representation. 37 Function to convert a mode value to a string representation.
38 38
39 @param mode mode value 39 @param mode mode value
40 @type int 40 @type int
41 @return string representation of the given mode value 41 @return string representation of the given mode value
42 @rtype str 42 @rtype str
43 """ 43 """
45 45
46 46
47 def decoratedName(name, mode, isDir=False): 47 def decoratedName(name, mode, isDir=False):
48 """ 48 """
49 Function to decorate the given name according to the given mode. 49 Function to decorate the given name according to the given mode.
50 50
51 @param name file or directory name 51 @param name file or directory name
52 @type str 52 @type str
53 @param mode mode value 53 @param mode mode value
54 @type int 54 @type int
55 @param isDir flag indicating that name is a directory 55 @param isDir flag indicating that name is a directory
69 69
70 70
71 def isVisible(name, showHidden): 71 def isVisible(name, showHidden):
72 """ 72 """
73 Function to check, if a filesystem entry is a hidden file or directory. 73 Function to check, if a filesystem entry is a hidden file or directory.
74 74
75 @param name name to be checked 75 @param name name to be checked
76 @type str 76 @type str
77 @param showHidden flag indicating to show hidden files as well 77 @param showHidden flag indicating to show hidden files as well
78 @type bool 78 @type bool
79 @return flag indicating a visible filesystem entry 79 @return flag indicating a visible filesystem entry
80 @rtype bool 80 @rtype bool
81 """ 81 """
82 return ( 82 return showHidden or (not name.startswith(".") and not name.endswith("~"))
83 showHidden or
84 (not name.startswith(".") and not name.endswith("~"))
85 )
86 83
87 84
88 def fstat(filename): 85 def fstat(filename):
89 """ 86 """
90 Function to get the stat() of file. 87 Function to get the stat() of file.
91 88
92 @param filename name of the file 89 @param filename name of the file
93 @type str 90 @type str
94 @return tuple containing the stat() result 91 @return tuple containing the stat() result
95 @rtype tuple 92 @rtype tuple
96 """ 93 """
102 99
103 100
104 def listdirStat(dirname, showHidden=False): 101 def listdirStat(dirname, showHidden=False):
105 """ 102 """
106 Function to get a list of directory entries and associated stat() tuples. 103 Function to get a list of directory entries and associated stat() tuples.
107 104
108 @param dirname name of the directory to list 105 @param dirname name of the directory to list
109 @type str 106 @type str
110 @param showHidden flag indicating to show hidden files as well 107 @param showHidden flag indicating to show hidden files as well
111 @type bool 108 @type bool
112 @return list of tuples containing the entry name and the associated 109 @return list of tuples containing the entry name and the associated
115 """ 112 """
116 try: 113 try:
117 files = os.listdir(dirname) if dirname else os.listdir() 114 files = os.listdir(dirname) if dirname else os.listdir()
118 except OSError: 115 except OSError:
119 return [] 116 return []
120 117
121 if dirname in ('', '/'): 118 if dirname in ("", "/"):
122 return [(f, fstat(f)) for f in files if isVisible(f, showHidden)] 119 return [(f, fstat(f)) for f in files if isVisible(f, showHidden)]
123 120
124 return [(f, fstat(os.path.join(dirname, f))) for f in files 121 return [
125 if isVisible(f, showHidden)] 122 (f, fstat(os.path.join(dirname, f))) for f in files if isVisible(f, showHidden)
123 ]

eric ide

mercurial