src/eric7/SystemUtilities/FileSystemUtilities.py

Fri, 23 Feb 2024 16:49:42 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 23 Feb 2024 16:49:42 +0100
branch
server
changeset 10603
8093b9e14b75
parent 10597
fbe93720ee9f
child 10680
306373ccf8fd
permissions
-rw-r--r--

Made some conversion function in FileSystemUtilities more resilient.

9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10397
diff changeset
3 # Copyright (c) 2022 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing file system related utility functions.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import contextlib
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import ctypes
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import fnmatch
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import os
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import pathlib
10170
6cf1ee737d8f Corrected some more code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10108
diff changeset
15 import subprocess # secok
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from eric7.SystemUtilities import OSUtilities
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 def toNativeSeparators(path):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Function returning a path, that is using native separator characters.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @param path path to be converted
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @return path with converted separator characters
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @rtype str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 return str(pathlib.PurePath(path)) if bool(path) else ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 def fromNativeSeparators(path):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Function returning a path, that is using "/" separator characters.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param path path to be converted
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @return path with converted separator characters
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @rtype str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 return pathlib.PurePath(path).as_posix() if bool(path) else ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 def normcasepath(path):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 Function returning a path, that is normalized with respect to its case
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 and references.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
49 @param path file path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
50 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
51 @return case normalized path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
52 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 return os.path.normcase(os.path.normpath(path))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 def normcaseabspath(path):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 Function returning an absolute path, that is normalized with respect to
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 its case and references.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
62 @param path file path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
63 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
64 @return absolute, normalized path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
65 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 return os.path.normcase(os.path.abspath(path))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 def normjoinpath(a, *p):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 Function returning a normalized path of the joined parts passed into it.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
74 @param a first path to be joined
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
75 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
76 @param p variable number of path parts to be joined
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
77 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
78 @return normalized path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
79 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 return os.path.normpath(os.path.join(a, *p))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 def normabsjoinpath(a, *p):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 Function returning a normalized, absolute path of the joined parts passed
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 into it.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
89 @param a first path to be joined
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
90 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
91 @param p variable number of path parts to be joined
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
92 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
93 @return absolute, normalized path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
94 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 return os.path.abspath(os.path.join(a, *p))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 def isinpath(file):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 Function to check for an executable file.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
103 @param file filename of the executable to check
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
104 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
105 @return flag indicating, if the executable file is accessible via the executable
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
106 search path defined by the PATH environment variable.
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
107 @rtype bool
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 if os.path.isabs(file):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 return os.access(file, os.X_OK)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 if os.path.exists(os.path.join(os.curdir, file)):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 return os.access(os.path.join(os.curdir, file), os.X_OK)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 path = OSUtilities.getEnvironmentEntry("PATH")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 # environment variable not defined
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 if path is None:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 return False
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 dirs = path.split(os.pathsep)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 return any(os.access(os.path.join(directory, file), os.X_OK) for directory in dirs)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 def startswithPath(path, start):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 Function to check, if a path starts with a given start path.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 @param path path to be checked
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 @param start start path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 @return flag indicating that the path starts with the given start
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @rtype bool
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 return bool(start) and (
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 path == start or normcasepath(path).startswith(normcasepath(start + "/"))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 def relativeUniversalPath(path, start):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 Function to convert a file path to a path relative to a start path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 with universal separators.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
147 @param path file or directory name to convert
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
148 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
149 @param start start path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
150 @type str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 @return relative path or unchanged path, if path does not start with
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
152 the start path with universal separators
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
153 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 return fromNativeSeparators(os.path.relpath(path, start))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 def absolutePath(path, start):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 Public method to convert a path relative to a start path to an
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 absolute path.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
163 @param path file or directory name to convert
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
164 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
165 @param start start path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
166 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
167 @return absolute path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
168 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 if not os.path.isabs(path):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 path = os.path.normpath(os.path.join(start, path))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 return path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 def absoluteUniversalPath(path, start):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 Public method to convert a path relative to a start path with
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 universal separators to an absolute path.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
180 @param path file or directory name to convert
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
181 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
182 @param start start path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
183 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
184 @return absolute path with native separators
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
185 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 if not os.path.isabs(path):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 path = toNativeSeparators(os.path.normpath(os.path.join(start, path)))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 return path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 def getExecutablePath(file):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 Function to build the full path of an executable file from the environment.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
196 @param file filename of the executable to check
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
197 @type str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 @return full executable name, if the executable file is accessible
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
199 via the executable search path defined by the PATH environment variable, or an
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 empty string otherwise.
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
201 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 if os.path.isabs(file):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 if os.access(file, os.X_OK):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 return file
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 cur_path = os.path.join(os.curdir, file)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 if os.path.exists(cur_path) and os.access(cur_path, os.X_OK):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 return cur_path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 path = os.getenv("PATH")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 # environment variable not defined
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 if path is None:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 dirs = path.split(os.pathsep)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 for directory in dirs:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 exe = os.path.join(directory, file)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 if os.access(exe, os.X_OK):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 return exe
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 def getExecutablePaths(file):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 Function to build all full path of an executable file from the environment.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
232 @param file filename of the executable
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
233 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
234 @return list of full executable names, if the executable file is accessible via
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
235 the executable search path defined by the PATH environment variable, or an
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
236 empty list otherwise.
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
237 @rtype list of str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 paths = []
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 if os.path.isabs(file):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 if os.access(file, os.X_OK):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 return [file]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 return []
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 cur_path = os.path.join(os.curdir, file)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 if os.path.exists(cur_path) and os.access(cur_path, os.X_OK):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 paths.append(cur_path)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 path = os.getenv("PATH")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 # environment variable not defined
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 if path is not None:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 dirs = path.split(os.pathsep)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 for directory in dirs:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 exe = os.path.join(directory, file)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 if os.access(exe, os.X_OK) and exe not in paths:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 paths.append(exe)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 return paths
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 def getWindowsExecutablePath(file):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 Function to build the full path of an executable file from the environment
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 on Windows platforms.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 First an executable with the extension .exe is searched for, thereafter
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 such with the extensions .cmd or .bat and finally the given file name as
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 is. The first match is returned.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
273 @param file filename of the executable to check
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
274 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
275 @return full executable name, if the executable file is accessible via the
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
276 executable search path defined by the PATH environment variable, or an
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 empty string otherwise.
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
278 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 if os.path.isabs(file):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 if os.access(file, os.X_OK):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 return file
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 filenames = [file + ".exe", file + ".cmd", file + ".bat", file]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 for filename in filenames:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 cur_path = os.path.join(os.curdir, filename)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 if os.path.exists(cur_path) and os.access(cur_path, os.X_OK):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 return os.path.abspath(cur_path)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 path = os.getenv("PATH")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 # environment variable not defined
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 if path is None:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 dirs = path.split(os.pathsep)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 for directory in dirs:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 for filename in filenames:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 exe = os.path.join(directory, filename)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 if os.access(exe, os.X_OK):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 return exe
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 def isExecutable(exe):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 Function to check, if a file is executable.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
313 @param exe filename of the executable to check
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
314 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
315 @return flag indicating executable status
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
316 @rtype bool
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 return os.access(exe, os.X_OK)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 def isDrive(path):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 Function to check, if a path is a Windows drive.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 @param path path name to be checked
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 @return flag indicating a Windows drive
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 @rtype bool
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 isWindowsDrive = False
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 drive, directory = os.path.splitdrive(path)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 if (
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 drive
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 and len(drive) == 2
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 and drive.endswith(":")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 and directory in ["", "\\", "/"]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 ):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 isWindowsDrive = True
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 return isWindowsDrive
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
343 def samepath(f1, f2, followSymlinks=True):
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 Function to compare two paths.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
347 @param f1 first filepath for the compare
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
348 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
349 @param f2 second filepath for the compare
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
350 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
351 @param followSymlinks flag indicating to respect symbolic links for the comparison
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
352 (i.e. compare the real paths) (defaults to True)
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
353 @type bool (optional)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 @return flag indicating whether the two paths represent the
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
355 same path on disk
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
356 @rtype bool
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 if f1 is None or f2 is None:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 return False
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
361 if isPlainFileName(f1) and isPlainFileName(f2):
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
362 if followSymlinks:
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
363 if normcaseabspath(os.path.realpath(f1)) == normcaseabspath(
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
364 os.path.realpath(f2)
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
365 ):
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
366 return True
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
367 else:
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
368 if normcaseabspath(f1) == normcaseabspath(f2):
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
369 return True
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
370
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
371 else:
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
372 return f1 == f2
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 return False
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
377 def samefilepath(f1, f2, followSymlinks=True):
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 Function to compare two paths. Strips the filename.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
381 @param f1 first filepath for the compare
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
382 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
383 @param f2 second filepath for the compare
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
384 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
385 @param followSymlinks flag indicating to respect symbolic links for the comparison
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
386 (i.e. compare the real paths) (defaults to True)
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
387 @type bool (optional)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 @return flag indicating whether the two paths represent the
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
389 same path on disk
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
390 @rtype bool
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 if f1 is None or f2 is None:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 return False
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
395 if isPlainFileName(f1) and isPlainFileName(f2):
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
396 if followSymlinks:
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
397 if normcaseabspath(
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
398 os.path.dirname(os.path.realpath(f1))
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
399 ) == normcaseabspath(os.path.dirname(os.path.realpath(f2))):
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
400 return True
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
401 else:
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
402 if normcaseabspath(os.path.dirname(f1)) == normcaseabspath(
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
403 os.path.dirname(f2)
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
404 ):
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
405 return True
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
406
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
407 else:
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10521
diff changeset
408 return os.path.dirname(f1) == os.path.dirname(f2)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 return False
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 try:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 EXTSEP = os.extsep
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 except AttributeError:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 EXTSEP = "."
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 def splitPath(name):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 Function to split a pathname into a directory part and a file part.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
423 @param name path name
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
424 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
425 @return tuple containing directory name and file name
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
426 @rtype tuple of (str, str)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 if os.path.isdir(name):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 dn = os.path.abspath(name)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 fn = "."
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 dn, fn = os.path.split(name)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 return (dn, fn)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 def joinext(prefix, ext):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 Function to join a file extension to a path.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 The leading "." of ext is replaced by a platform specific extension
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 separator if necessary.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
443 @param prefix the basepart of the filename
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
444 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
445 @param ext the extension part
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
446 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
447 @return the complete filename
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
448 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 if ext[0] != ".":
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 ext = ".{0}".format(ext)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 # require leading separator to match os.path.splitext
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 return prefix + EXTSEP + ext[1:]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 def compactPath(path, width, measure=len):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 Function to return a compacted path fitting inside the given width.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
460 @param path path to be compacted
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
461 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
462 @param width width for the compacted path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
463 @type int
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 @param measure reference to a function used to measure the length of the
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 string
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
466 @type function(str)
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
467 @return compacted path
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
468 @rtype str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 if measure(path) <= width:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 return path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 ellipsis = "..."
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 head, tail = os.path.split(path)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476 mid = len(head) // 2
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 head1 = head[:mid]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 head2 = head[mid:]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 while head1:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
480 # head1 is same size as head2 or one shorter
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481 path = os.path.join("{0}{1}{2}".format(head1, ellipsis, head2), tail)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 if measure(path) <= width:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 return path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 head1 = head1[:-1]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 head2 = head2[1:]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 path = os.path.join(ellipsis, tail)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487 if measure(path) <= width:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488 return path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
489 while tail:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
490 path = "{0}{1}".format(ellipsis, tail)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
491 if measure(path) <= width:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 return path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 tail = tail[1:]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
495
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 def direntries(
9639
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
498 path,
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
499 filesonly=False,
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
500 pattern=None,
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
501 followsymlinks=True,
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
502 checkStop=None,
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
503 ignore=None,
10583
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
504 recursive=True,
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
505 dirsonly=False,
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 ):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 Function returning a list of all files and directories.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
509
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 @param path root of the tree to check
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511 @type str
10583
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
512 @param filesonly flag indicating that only files are wanted (defaults to False)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
513 @type bool (optional)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 @param pattern a filename pattern or list of filename patterns to check
10583
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
515 against (defaults to None)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
516 @type str or list of str (optional)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 @param followsymlinks flag indicating whether symbolic links
10583
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
518 should be followed (defaults to True)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
519 @type bool (optional)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
520 @param checkStop function to be called to check for a stop (defaults to None)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
521 @type function (optional)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
522 @param ignore list of entries to be ignored (defaults to None)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
523 @type list of str (optional)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
524 @param recursive flag indicating a recursive search (defaults to True)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
525 @type bool (optional)
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
526 @param dirsonly flag indicating to return only directories. When True it has
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
527 precedence over the 'filesonly' parameter ((defaults to False)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528 @type bool
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 @return list of all files and directories in the tree rooted
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 at path. The names are expanded to start with path.
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
531 @rtype list of str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
532 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
533 patterns = pattern if isinstance(pattern, list) else [pattern]
10583
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
534 files = [] if (filesonly and not dirsonly) else [path]
9639
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
535 ignoreList = [
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
536 ".svn",
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
537 ".hg",
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
538 ".git",
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
539 ".ropeproject",
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
540 ".eric7project",
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
541 ".jedi",
9646
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
542 "__pycache__",
9639
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
543 ]
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
544 if ignore is not None:
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
545 ignoreList.extend(ignore)
9e66fd88193c Corrected the logic for the project creation if the project directory already contains files and an embedded environment (see issue 480).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
546
9646
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
547 with contextlib.suppress(OSError, UnicodeDecodeError), os.scandir(
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
548 path
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
549 ) as dirEntriesIterator:
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
550 for dirEntry in dirEntriesIterator:
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
551 if checkStop and checkStop():
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 break
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553
9646
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
554 if dirEntry.name in ignoreList:
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 continue
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557 if (
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 pattern
9646
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
559 and not dirEntry.is_dir()
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
560 and not any(fnmatch.fnmatch(dirEntry.name, p) for p in patterns)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
561 ):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
562 # entry doesn't fit the given pattern
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563 continue
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564
9646
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
565 if dirEntry.is_dir():
10597
fbe93720ee9f Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10583
diff changeset
566 if dirEntry.path in ignoreList or (
fbe93720ee9f Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10583
diff changeset
567 dirEntry.is_symlink() and not followsymlinks
10583
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
568 ):
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
569 continue
10583
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
570 if recursive:
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
571 files += direntries(
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
572 dirEntry.path,
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
573 filesonly=filesonly,
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
574 pattern=pattern,
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
575 followsymlinks=followsymlinks,
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
576 checkStop=checkStop,
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
577 ignore=ignore,
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
578 )
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
579 elif dirsonly:
2114cc7275e8 Adapted the UML Class diagram and the Package diagram to support the 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
580 files.append(dirEntry.path)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
581 else:
9646
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
582 files.append(dirEntry.path)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
583 return files
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
585
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
586 def getDirs(path, excludeDirs):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588 Function returning a list of all directories below path.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
589
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
590 @param path root of the tree to check
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
591 @type str
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
592 @param excludeDirs base name of directories to ignore
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
593 @type list of str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 @return list of all directories found
10393
434e1b0bc49e Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10388
diff changeset
595 @rtype list of str
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
596 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
597 try:
9646
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
598 dirs = []
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
599 with os.scandir(path) as dirEntriesIterator:
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
600 for dirEntry in dirEntriesIterator:
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
601 if (
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
602 dirEntry.is_dir()
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
603 and not dirEntry.is_symlink()
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
604 and dirEntry.name not in excludeDirs
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
605 ):
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
606 dirs.append(dirEntry.path)
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
607 dirs.extend(getDirs(dirEntry.path, excludeDirs))
ab5678db972f Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9645
diff changeset
608 return dirs
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
609 except OSError:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610 return []
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
611
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
612
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
613 def findVolume(volumeName, findAll=False):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
614 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
615 Function to find the directory belonging to a given volume name.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
616
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
617 @param volumeName name of the volume to search for
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
618 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
619 @param findAll flag indicating to get the directories for all volumes
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620 starting with the given name (defaults to False)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
621 @type bool (optional)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
622 @return directory path or list of directory paths for the given volume
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
623 name
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
624 @rtype str or list of str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
625 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
626 volumeDirectories = []
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
627 volumeDirectory = None
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
629 if OSUtilities.isWindowsPlatform():
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630 # we are on a Windows platform
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
631 def getVolumeName(diskName):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
633 Local function to determine the volume of a disk or device.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
635 Each disk or external device connected to windows has an
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 attribute called "volume name". This function returns the
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637 volume name for the given disk/device.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
638
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
639 Code from http://stackoverflow.com/a/12056414
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
640 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
641 volumeNameBuffer = ctypes.create_unicode_buffer(1024)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
642 ctypes.windll.kernel32.GetVolumeInformationW(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
643 ctypes.c_wchar_p(diskName),
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
644 volumeNameBuffer,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645 ctypes.sizeof(volumeNameBuffer),
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
646 None,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
647 None,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
648 None,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
649 None,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
650 0,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
651 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
652 return volumeNameBuffer.value
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
653
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
654 #
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
655 # In certain circumstances, volumes are allocated to USB
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
656 # storage devices which cause a Windows popup to raise if their
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
657 # volume contains no media. Wrapping the check in SetErrorMode
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
658 # with SEM_FAILCRITICALERRORS (1) prevents this popup.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
659 #
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
660 oldMode = ctypes.windll.kernel32.SetErrorMode(1)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
661 try:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
662 for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
663 dirpath = "{0}:\\".format(disk)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
664 if os.path.exists(dirpath):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
665 if findAll:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
666 if getVolumeName(dirpath).startswith(volumeName):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
667 volumeDirectories.append(dirpath)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
668 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
669 if getVolumeName(dirpath) == volumeName:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
670 volumeDirectory = dirpath
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
671 break
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
672 finally:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
673 ctypes.windll.kernel32.SetErrorMode(oldMode)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
674 else:
10338
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
675 # we are on a Linux, FreeBSD or macOS platform
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
676 for mountCommand in ["mount", "/sbin/mount", "/usr/sbin/mount"]:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
677 with contextlib.suppress(FileNotFoundError):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
678 mountOutput = subprocess.run( # secok
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
679 mountCommand, check=True, capture_output=True, text=True
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
680 ).stdout.splitlines()
9923
f706be800097 Refined the 'findVolume()' solution for Linux and macOS to work on both.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9920
diff changeset
681 mountedVolumes = [
f706be800097 Refined the 'findVolume()' solution for Linux and macOS to work on both.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9920
diff changeset
682 x.split(" type", 1)[0].split(" (", 1)[0].split(maxsplit=2)[-1]
f706be800097 Refined the 'findVolume()' solution for Linux and macOS to work on both.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9920
diff changeset
683 for x in mountOutput
f706be800097 Refined the 'findVolume()' solution for Linux and macOS to work on both.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9920
diff changeset
684 ]
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
685 if findAll:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
686 for volume in mountedVolumes:
9903
52132654939b MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
687 if os.path.basename(volume).startswith(volumeName):
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
688 volumeDirectories.append(volume)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
689 if volumeDirectories:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690 break
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
691 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
692 for volume in mountedVolumes:
9903
52132654939b MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
693 if os.path.basename(volume) == volumeName:
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
694 volumeDirectory = volume
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
695 break
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
696 if volumeDirectory:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
697 break
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
698
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
699 if findAll:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
700 return volumeDirectories
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
701 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
702 return volumeDirectory
9944
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
703
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
704
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
705 def getUserMounts():
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
706 """
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
707 Function to determine all available user mounts.
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
708
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
709 Note: On Windows platforms all available drives are returned.
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
710
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
711 @return list of user mounts or drives
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
712 @rtype list of str
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
713 """
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
714 mountedPaths = []
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
715
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
716 if OSUtilities.isWindowsPlatform():
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
717 # we are on a Windows platform
9972
68ac01294544 Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9944
diff changeset
718 for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
68ac01294544 Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9944
diff changeset
719 dirpath = "{0}:\\".format(disk)
68ac01294544 Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9944
diff changeset
720 if os.path.exists(dirpath):
68ac01294544 Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9944
diff changeset
721 mountedPaths.append(dirpath)
9944
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
722 else:
10338
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
723 # we are on a Linux, FreeBSD or macOS platform
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
724 if OSUtilities.isMacPlatform():
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
725 # macOS
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
726 mountPathStart = "/Volumes/"
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
727 elif OSUtilities.isLinuxPlatform():
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
728 # Linux
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
729 mountPathStart = "/media/{0}/".format(OSUtilities.getUserName())
10339
446d22fa1aea Renamed "isBsdPlatform()" to "isFreeBsdPlatform()" to express its real test.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10338
diff changeset
730 elif OSUtilities.isFreeBsdPlatform():
10338
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
731 # FreeBSD
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
732 mountPathStart = "/media/"
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
733 else:
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
734 # unsupported platform
7329b8d78f7b Modified the "getUserMounts()" function of FileSystemUtilities.py to work on FreeBSD as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10170
diff changeset
735 return []
9944
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
736
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
737 for mountCommand in ["mount", "/sbin/mount", "/usr/sbin/mount"]:
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
738 with contextlib.suppress(FileNotFoundError):
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
739 mountOutput = subprocess.run( # secok
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
740 mountCommand, check=True, capture_output=True, text=True
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
741 ).stdout.splitlines()
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
742 mounts = [
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
743 x.split(" type", 1)[0].split(" (", 1)[0].split(maxsplit=2)[-1]
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
744 for x in mountOutput
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
745 ]
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
746 mountedPaths = [x for x in mounts if x.startswith(mountPathStart)]
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
747 break
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
748
011ae0edbcff MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9923
diff changeset
749 return mountedPaths
10388
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
750
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
751
10396
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
752 def startfile(filePath):
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
753 """
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
754 Function to open the given file path with the system default application.
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
755
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
756 @param filePath file path to be opened
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
757 @type str or Path
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
758 @return flag indicating a successful start of the associated application
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
759 @rtype bool
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
760 """
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
761 filePath = str(filePath)
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
762
10397
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
763 with contextlib.suppress(OSError):
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
764 if OSUtilities.isWindowsPlatform():
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
765 os.startfile(filePath) # secok
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
766 return True
10396
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
767
10397
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
768 elif OSUtilities.isMacPlatform():
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
769 return subprocess.call(("open", filePath)) == 0 # secok
10396
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
770
10397
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
771 elif OSUtilities.isLinuxPlatform() or OSUtilities.isFreeBsdPlatform():
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
772 return subprocess.call(("xdg-open", filePath)) == 0 # secok
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
773
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
774 # unsupported platform or OSError
f60464a5f7ea Modified the last implementation to work on Windows as well and made the code more robust against errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10396
diff changeset
775 return False
10396
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
776
2f72e9330af2 File Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10393
diff changeset
777
10388
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
778 ################################################################################
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
779 ## Functions below handle (MicroPython) device and remote file names.
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
780 ################################################################################
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
781
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
782
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
783 _DeviceFileMarker = "device:"
10521
a51b382e47d7 Did a little code reorganization to improve readability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
784 _RemoteFileMarker = "remote:"
10388
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
785
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
786
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
787 def deviceFileName(fileName):
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
788 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
789 Function to create a device (MicroPython) file name given a plain file name.
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
790
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
791 @param fileName plain file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
792 @type str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
793 @return device file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
794 @rtype str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
795 """
10603
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
796 if fileName.startswith(_DeviceFileMarker):
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
797 # it is already a device file name
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
798 return fileName
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
799 else:
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
800 return f"{_DeviceFileMarker}{fileName}"
10388
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
801
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
802
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
803 def isDeviceFileName(fileName):
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
804 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
805 Function to check, if the given file name is a device file name.
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
806
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
807 @param fileName file name to be checked
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
808 @type str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
809 @return flag indicating a device file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
810 @rtype bool
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
811 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
812 return fileName.startswith(_DeviceFileMarker)
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
813
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
814
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
815 def remoteFileName(fileName):
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
816 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
817 Function to create a remote file name given a plain file name.
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
818
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
819 @param fileName plain file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
820 @type str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
821 @return remote file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
822 @rtype str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
823 """
10603
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
824 if fileName.startswith(_RemoteFileMarker):
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
825 # it is already a remote file name
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
826 return fileName
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
827 else:
8093b9e14b75 Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
828 return f"{_RemoteFileMarker}{fileName}"
10388
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
829
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
830
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
831 def isRemoteFileName(fileName):
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
832 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
833 Function to check, if the given file name is a remote file name.
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
834
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
835 @param fileName file name to be checked
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
836 @type str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
837 @return flag indicating a remote file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
838 @rtype bool
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
839 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
840 return fileName.startswith(_RemoteFileMarker)
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
841
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
842
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
843 def isPlainFileName(fileName):
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
844 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
845 Function to check, if the given file name is a plain (i.e. local) file name.
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
846
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
847 @param fileName file name to be checked
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
848 @type str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
849 @return flag indicating a local file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
850 @rtype bool
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
851 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
852 return not fileName.startswith((_DeviceFileMarker, _RemoteFileMarker))
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
853
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
854
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
855 def plainFileName(fileName):
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
856 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
857 Function to create a plain file name given a device or remote file name.
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
858
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
859 @param fileName device or remote file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
860 @type str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
861 @return plain file name
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
862 @rtype str
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
863 """
a34ce7f42e8b Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
864 return fileName.replace(_DeviceFileMarker, "").replace(_RemoteFileMarker, "")

eric ide

mercurial