Wed, 10 Apr 2024 17:03:56 +0200
Merged with branch 'eric7' in order to track these changes.
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 | |
10668
2be6fadcac40
Fixed a little issue in the file system utilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
125 | def startsWithPath(path, start): |
9624
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 | """ |
10668
2be6fadcac40
Fixed a little issue in the file system utilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
137 | start1 = start if start.endswith(os.sep) else f"{start}{os.sep}" |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | return bool(start) and ( |
10668
2be6fadcac40
Fixed a little issue in the file system utilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
139 | path == start or normcasepath(path).startswith(normcasepath(start1)) |
9624
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | 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
|
144 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | 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
|
146 | 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
|
147 | |
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
|
148 | @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
|
149 | @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
|
150 | @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
|
151 | @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
|
152 | @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
|
153 | 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
|
154 | @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
|
155 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | 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
|
157 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | 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
|
160 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | 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
|
162 | absolute path. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | |
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
|
164 | @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
|
165 | @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
|
166 | @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
|
167 | @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
|
168 | @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
|
169 | @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
|
170 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | 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
|
172 | 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
|
173 | return path |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | 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
|
177 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | 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
|
179 | 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
|
180 | |
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
|
181 | @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
|
182 | @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
|
183 | @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
|
184 | @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
|
185 | @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
|
186 | @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
|
187 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | 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
|
189 | 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
|
190 | return path |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | 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
|
194 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | 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
|
196 | |
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
|
197 | @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
|
198 | @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
|
199 | @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
|
200 | 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
|
201 | 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
|
202 | @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
|
203 | """ |
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.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
|
205 | 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
|
206 | return file |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | return "" |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | 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
|
211 | 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
|
212 | 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
|
213 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | 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
|
215 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | # 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
|
217 | 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
|
218 | return "" |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | 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
|
221 | 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
|
222 | 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
|
223 | 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
|
224 | return exe |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | return "" |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | 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
|
230 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | 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
|
232 | |
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
|
233 | @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
|
234 | @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
|
235 | @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
|
236 | 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
|
237 | 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
|
238 | @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
|
239 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | paths = [] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | |
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.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
|
243 | 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
|
244 | return [file] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | return [] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | 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
|
249 | 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
|
250 | 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
|
251 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | 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
|
253 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | # 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
|
255 | 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
|
256 | 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
|
257 | 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
|
258 | 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
|
259 | 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
|
260 | 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
|
261 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | return paths |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | 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
|
266 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | 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
|
268 | 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
|
269 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | 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
|
271 | 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
|
272 | 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
|
273 | |
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
|
274 | @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
|
275 | @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
|
276 | @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
|
277 | 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
|
278 | 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
|
279 | @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
|
280 | """ |
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.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
|
282 | 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
|
283 | return file |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | return "" |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | 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
|
288 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | 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
|
290 | 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
|
291 | 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
|
292 | 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
|
293 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | 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
|
295 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | # 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
|
297 | 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
|
298 | return "" |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | 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
|
301 | 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
|
302 | 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
|
303 | 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
|
304 | 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
|
305 | return exe |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | return "" |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | 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
|
311 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | 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
|
313 | |
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
|
314 | @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
|
315 | @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
|
316 | @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
|
317 | @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
|
318 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | 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
|
320 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | 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
|
323 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | 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
|
325 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | @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
|
327 | @type str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | @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
|
329 | @rtype bool |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | isWindowsDrive = False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | 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
|
333 | if ( |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | drive |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | 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
|
336 | 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
|
337 | 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
|
338 | ): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | isWindowsDrive = True |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
341 | return isWindowsDrive |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | |
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
|
344 | 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
|
345 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | 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
|
347 | |
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
|
348 | @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
|
349 | @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
|
350 | @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
|
351 | @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
|
352 | @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
|
353 | (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
|
354 | @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
|
355 | @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
|
356 | 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
|
357 | @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
|
358 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
359 | 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
|
360 | return False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
361 | |
10561
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
362 | 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
|
363 | if followSymlinks: |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
364 | 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
|
365 | os.path.realpath(f2) |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
366 | ): |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
367 | return True |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
368 | else: |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
369 | 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
|
370 | return True |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
371 | |
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
|
372 | else: |
10561
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
373 | 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
|
374 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | return False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | |
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
|
378 | 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
|
379 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | 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
|
381 | |
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
|
382 | @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
|
383 | @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
|
384 | @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
|
385 | @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
|
386 | @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
|
387 | (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
|
388 | @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
|
389 | @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
|
390 | 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
|
391 | @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
|
392 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | 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
|
394 | return False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | |
10561
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
396 | 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
|
397 | if followSymlinks: |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
398 | if normcaseabspath( |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
399 | 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
|
400 | ) == 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
|
401 | return True |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
402 | else: |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
403 | 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
|
404 | os.path.dirname(f2) |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
405 | ): |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
406 | return True |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
407 | |
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
|
408 | else: |
10561
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
409 | 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
|
410 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
411 | return False |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | try: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | 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
|
416 | except AttributeError: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
417 | EXTSEP = "." |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | 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
|
421 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | 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
|
423 | |
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
|
424 | @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
|
425 | @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
|
426 | @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
|
427 | @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
|
428 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | 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
|
430 | 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
|
431 | fn = "." |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | 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
|
434 | 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
|
435 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | 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
|
438 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | 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
|
440 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
441 | 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
|
442 | 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
|
443 | |
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
|
444 | @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
|
445 | @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
|
446 | @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
|
447 | @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
|
448 | @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
|
449 | @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
|
450 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | 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
|
452 | 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
|
453 | # 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
|
454 | 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
|
455 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
456 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
457 | 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
|
458 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
459 | 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
|
460 | |
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
|
461 | @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
|
462 | @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
|
463 | @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
|
464 | @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
|
465 | @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
|
466 | 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
|
467 | @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
|
468 | @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
|
469 | @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
|
470 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
471 | 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
|
472 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
473 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
474 | ellipsis = "..." |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
475 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
476 | 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
|
477 | 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
|
478 | 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
|
479 | 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
|
480 | while head1: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | # 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
|
482 | 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
|
483 | 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
|
484 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
485 | 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
|
486 | 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
|
487 | 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
|
488 | 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
|
489 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | while tail: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | 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
|
492 | 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
|
493 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | 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
|
495 | return "" |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
498 | 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
|
499 | 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
|
500 | 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
|
501 | 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
|
502 | 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
|
503 | 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
|
504 | 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
|
505 | 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
|
506 | 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
|
507 | ): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
509 | 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
|
510 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
511 | @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
|
512 | @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
|
513 | @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
|
514 | @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
|
515 | @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
|
516 | 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
|
517 | @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
|
518 | @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
|
519 | 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
|
520 | @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
|
521 | @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
|
522 | @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
|
523 | @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
|
524 | @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
|
525 | @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
|
526 | @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
|
527 | @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
|
528 | 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
|
529 | @type bool |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
530 | @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
|
531 | 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
|
532 | @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
|
533 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
534 | 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
|
535 | 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
|
536 | 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
|
537 | ".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
|
538 | ".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
|
539 | ".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
|
540 | ".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
|
541 | ".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
|
542 | ".jedi", |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
543 | "__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
|
544 | ] |
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 | 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
|
546 | 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
|
547 | |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
548 | 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
|
549 | path |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
550 | ) as dirEntriesIterator: |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
551 | 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
|
552 | 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
|
553 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
554 | |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
555 | 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
|
556 | continue |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
557 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
558 | if ( |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
559 | pattern |
9646
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 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
|
561 | 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
|
562 | ): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
563 | # 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
|
564 | continue |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
565 | |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
566 | if dirEntry.is_dir(): |
10597
fbe93720ee9f
Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10583
diff
changeset
|
567 | if dirEntry.path in ignoreList or ( |
fbe93720ee9f
Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10583
diff
changeset
|
568 | 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
|
569 | ): |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
570 | 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
|
571 | 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
|
572 | 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
|
573 | 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
|
574 | 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
|
575 | 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
|
576 | 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
|
577 | 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
|
578 | 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
|
579 | ) |
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 | 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
|
581 | 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
|
582 | else: |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
583 | 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
|
584 | return files |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
587 | 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
|
588 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
589 | 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
|
590 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
591 | @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
|
592 | @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
|
593 | @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
|
594 | @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
|
595 | @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
|
596 | @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
|
597 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
598 | try: |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
599 | dirs = [] |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
600 | 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
|
601 | 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
|
602 | if ( |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
603 | 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
|
604 | 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
|
605 | 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
|
606 | ): |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
607 | 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
|
608 | 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
|
609 | 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
|
610 | except OSError: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
611 | return [] |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
614 | 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
|
615 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
616 | 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
|
617 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
618 | @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
|
619 | @type str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
620 | @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
|
621 | 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
|
622 | @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
|
623 | @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
|
624 | name |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
625 | @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
|
626 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
627 | volumeDirectories = [] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
628 | volumeDirectory = None |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
629 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
630 | 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
|
631 | # 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
|
632 | 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
|
633 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
634 | 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
|
635 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
636 | 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
|
637 | 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
|
638 | 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
|
639 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
640 | 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
|
641 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
642 | 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
|
643 | 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
|
644 | 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
|
645 | volumeNameBuffer, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
646 | 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
|
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 | None, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
651 | 0, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
652 | ) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
653 | 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
|
654 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
655 | # |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
656 | # 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
|
657 | # 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
|
658 | # 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
|
659 | # 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
|
660 | # |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
661 | 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
|
662 | try: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
663 | 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
|
664 | 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
|
665 | 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
|
666 | if findAll: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
667 | 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
|
668 | 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
|
669 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
670 | 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
|
671 | volumeDirectory = dirpath |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
672 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
673 | finally: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
674 | 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
|
675 | 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
|
676 | # 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
|
677 | 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
|
678 | 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
|
679 | 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
|
680 | 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
|
681 | ).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
|
682 | mountedVolumes = [ |
f706be800097
Refined the 'findVolume()' solution for Linux and macOS to work on both.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9920
diff
changeset
|
683 | 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
|
684 | 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
|
685 | ] |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
686 | if findAll: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
687 | for volume in mountedVolumes: |
9903 | 688 | 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
|
689 | 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
|
690 | if volumeDirectories: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
691 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
692 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
693 | for volume in mountedVolumes: |
9903 | 694 | 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
|
695 | volumeDirectory = volume |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
696 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
697 | if volumeDirectory: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
698 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
699 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
700 | if findAll: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
701 | return volumeDirectories |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
702 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
703 | return volumeDirectory |
9944 | 704 | |
705 | ||
706 | def getUserMounts(): | |
707 | """ | |
708 | Function to determine all available user mounts. | |
709 | ||
710 | Note: On Windows platforms all available drives are returned. | |
711 | ||
712 | @return list of user mounts or drives | |
713 | @rtype list of str | |
714 | """ | |
715 | mountedPaths = [] | |
716 | ||
717 | if OSUtilities.isWindowsPlatform(): | |
718 | # 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
|
719 | for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": |
68ac01294544
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9944
diff
changeset
|
720 | dirpath = "{0}:\\".format(disk) |
68ac01294544
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9944
diff
changeset
|
721 | if os.path.exists(dirpath): |
68ac01294544
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9944
diff
changeset
|
722 | mountedPaths.append(dirpath) |
9944 | 723 | 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
|
724 | # 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
|
725 | 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
|
726 | # 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
|
727 | 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
|
728 | 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
|
729 | # 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
|
730 | 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
|
731 | 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
|
732 | # 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
|
733 | 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
|
734 | 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
|
735 | # 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
|
736 | return [] |
9944 | 737 | |
738 | for mountCommand in ["mount", "/sbin/mount", "/usr/sbin/mount"]: | |
739 | with contextlib.suppress(FileNotFoundError): | |
740 | mountOutput = subprocess.run( # secok | |
741 | mountCommand, check=True, capture_output=True, text=True | |
742 | ).stdout.splitlines() | |
743 | mounts = [ | |
744 | x.split(" type", 1)[0].split(" (", 1)[0].split(maxsplit=2)[-1] | |
745 | for x in mountOutput | |
746 | ] | |
747 | mountedPaths = [x for x in mounts if x.startswith(mountPathStart)] | |
748 | break | |
749 | ||
750 | 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
|
751 | |
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
|
752 | |
10396 | 753 | def startfile(filePath): |
754 | """ | |
755 | Function to open the given file path with the system default application. | |
756 | ||
757 | @param filePath file path to be opened | |
758 | @type str or Path | |
759 | @return flag indicating a successful start of the associated application | |
760 | @rtype bool | |
761 | """ | |
762 | filePath = str(filePath) | |
763 | ||
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
|
764 | 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
|
765 | 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
|
766 | 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
|
767 | return True |
10396 | 768 | |
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
|
769 | 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
|
770 | return subprocess.call(("open", filePath)) == 0 # secok |
10396 | 771 | |
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
|
772 | 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
|
773 | 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
|
774 | |
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 | # 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
|
776 | return False |
10396 | 777 | |
778 | ||
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
|
779 | ################################################################################ |
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 | ## 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
|
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 | |
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
|
784 | _DeviceFileMarker = "device:" |
10521
a51b382e47d7
Did a little code reorganization to improve readability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
785 | _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
|
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 | |
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 | 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
|
789 | """ |
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 | 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
|
791 | |
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 | @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
|
793 | @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
|
794 | @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
|
795 | @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
|
796 | """ |
10603
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
797 | if fileName.startswith(_DeviceFileMarker): |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
798 | # 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
|
799 | return fileName |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
800 | else: |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
801 | 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
|
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 | |
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 | 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
|
805 | """ |
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 | 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
|
807 | |
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 | @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
|
809 | @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
|
810 | @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
|
811 | @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
|
812 | """ |
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 | 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
|
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 | |
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 | 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
|
817 | """ |
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 | 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
|
819 | |
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 | @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
|
821 | @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
|
822 | @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
|
823 | @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
|
824 | """ |
10603
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
825 | if fileName.startswith(_RemoteFileMarker): |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
826 | # 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
|
827 | return fileName |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
828 | else: |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
829 | 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
|
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 | |
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 | 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
|
833 | """ |
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 | 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
|
835 | |
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 | @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
|
837 | @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
|
838 | @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
|
839 | @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
|
840 | """ |
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 | 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
|
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 | |
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 | 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
|
845 | """ |
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 | 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
|
847 | |
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 | @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
|
849 | @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
|
850 | @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
|
851 | @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
|
852 | """ |
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 | 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
|
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 | |
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 | 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
|
857 | """ |
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 | 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
|
859 | |
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 | @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
|
861 | @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
|
862 | @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
|
863 | @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
|
864 | """ |
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
|
865 | return fileName.replace(_DeviceFileMarker, "").replace(_RemoteFileMarker, "") |