Sun, 13 Oct 2024 12:03:05 +0200
Fixed an issue in the virtalenv manager caused by a defined virtual environment for an eric-ide server.
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 |
10791
ca9ece290f71
Changed some code to use 'shutil.which()'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10680
diff
changeset
|
15 | import shutil |
10170
6cf1ee737d8f
Corrected some more code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10108
diff
changeset
|
16 | 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
|
17 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | 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
|
19 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | 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
|
22 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | 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
|
24 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | @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
|
26 | @type str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | @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
|
28 | @rtype str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | 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
|
31 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | 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
|
34 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | 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
|
36 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | @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
|
38 | @type str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | @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
|
40 | @rtype str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | 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
|
43 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | 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
|
46 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | 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
|
48 | and references. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | |
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
|
50 | @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
|
51 | @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
|
52 | @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
|
53 | @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
|
54 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | 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
|
56 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | 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
|
59 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | 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
|
61 | 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
|
62 | |
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
|
63 | @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
|
64 | @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
|
65 | @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
|
66 | @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
|
67 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | 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
|
69 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | 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
|
72 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | 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
|
74 | |
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
|
75 | @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
|
76 | @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
|
77 | @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
|
78 | @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
|
79 | @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
|
80 | @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
|
81 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | 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
|
83 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | 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
|
86 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | 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
|
88 | into it. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | |
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
|
90 | @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
|
91 | @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
|
92 | @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
|
93 | @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
|
94 | @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
|
95 | @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
|
96 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | 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
|
98 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | 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
|
101 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | 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
|
103 | |
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
|
104 | @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
|
105 | @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
|
106 | @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
|
107 | 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
|
108 | @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
|
109 | """ |
10791
ca9ece290f71
Changed some code to use 'shutil.which()'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10680
diff
changeset
|
110 | return bool(shutil.which(file)) |
9624
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 | |
10668
2be6fadcac40
Fixed a little issue in the file system utilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
113 | 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
|
114 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | 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
|
116 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | @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
|
118 | @type str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | @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
|
120 | @type str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | @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
|
122 | path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | @rtype bool |
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 | 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
|
126 | 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
|
127 | 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
|
128 | ) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | 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
|
132 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | 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
|
134 | 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
|
135 | |
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
|
136 | @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
|
137 | @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
|
138 | @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
|
139 | @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
|
140 | @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
|
141 | 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
|
142 | @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
|
143 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | 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
|
145 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | 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
|
148 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | 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
|
150 | absolute path. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | |
10393
434e1b0bc49e
Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10388
diff
changeset
|
152 | @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
|
153 | @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
|
154 | @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
|
155 | @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
|
156 | @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
|
157 | @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
|
158 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | 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
|
160 | 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
|
161 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | 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
|
165 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | 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
|
167 | 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
|
168 | |
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
|
169 | @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
|
170 | @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
|
171 | @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
|
172 | @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
|
173 | @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
|
174 | @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
|
175 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | 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
|
177 | 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
|
178 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | 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
|
182 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | 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
|
184 | |
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
|
185 | @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
|
186 | @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
|
187 | @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
|
188 | 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
|
189 | 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
|
190 | @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
|
191 | """ |
10791
ca9ece290f71
Changed some code to use 'shutil.which()'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10680
diff
changeset
|
192 | exe = shutil.which(file) |
ca9ece290f71
Changed some code to use 'shutil.which()'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10680
diff
changeset
|
193 | return exe if bool(exe) else "" |
9624
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | 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
|
197 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | 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
|
199 | |
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 | @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
|
201 | @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
|
202 | @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
|
203 | 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
|
204 | 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
|
205 | @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
|
206 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | paths = [] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | 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
|
210 | 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
|
211 | return [file] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | return [] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | 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
|
216 | 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
|
217 | 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
|
218 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | 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
|
220 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | # 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
|
222 | 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
|
223 | 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
|
224 | 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
|
225 | 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
|
226 | 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
|
227 | 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
|
228 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | return paths |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | 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
|
233 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | 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
|
235 | |
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
|
236 | @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
|
237 | @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
|
238 | @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
|
239 | @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
|
240 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | 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
|
242 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | 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
|
245 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | 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
|
247 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | @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
|
249 | @type str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | @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
|
251 | @rtype bool |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | isWindowsDrive = False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | 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
|
255 | if ( |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | drive |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | 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
|
258 | 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
|
259 | 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
|
260 | ): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | isWindowsDrive = True |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | return isWindowsDrive |
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 | |
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
|
266 | 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
|
267 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | 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
|
269 | |
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
|
270 | @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
|
271 | @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
|
272 | @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
|
273 | @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
|
274 | @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
|
275 | (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
|
276 | @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
|
277 | @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
|
278 | 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
|
279 | @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
|
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 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
|
282 | return False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | |
10561
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
284 | 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
|
285 | if followSymlinks: |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
286 | 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
|
287 | os.path.realpath(f2) |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
288 | ): |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
289 | return True |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
290 | else: |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
291 | 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
|
292 | return True |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
293 | |
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
|
294 | else: |
10561
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
295 | 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
|
296 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | return False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | |
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
|
300 | 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
|
301 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | 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
|
303 | |
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
|
304 | @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
|
305 | @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
|
306 | @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
|
307 | @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
|
308 | @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
|
309 | (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
|
310 | @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
|
311 | @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
|
312 | 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
|
313 | @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
|
314 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | 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
|
316 | return False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | |
10561
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
318 | 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
|
319 | if followSymlinks: |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
320 | if normcaseabspath( |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
321 | 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
|
322 | ) == 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
|
323 | return True |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
324 | else: |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
325 | 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
|
326 | os.path.dirname(f2) |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
327 | ): |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
328 | return True |
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
329 | |
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
|
330 | else: |
10561
be23a662d709
Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10521
diff
changeset
|
331 | 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
|
332 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | return False |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | try: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
337 | 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
|
338 | except AttributeError: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | EXTSEP = "." |
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 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | 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
|
343 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | 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
|
345 | |
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
|
346 | @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
|
347 | @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
|
348 | @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
|
349 | @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
|
350 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | 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
|
352 | 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
|
353 | fn = "." |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | 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
|
356 | 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
|
357 | |
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 | 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
|
360 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
361 | 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
|
362 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
363 | 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
|
364 | 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
|
365 | |
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
|
366 | @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
|
367 | @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
|
368 | @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
|
369 | @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
|
370 | @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
|
371 | @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
|
372 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
373 | 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
|
374 | 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
|
375 | # 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
|
376 | 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
|
377 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | 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
|
380 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | 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
|
382 | |
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
|
383 | @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
|
384 | @type str |
434e1b0bc49e
Extended functionality in FileSystemUtilities.py and modified the doc strings to the newer format.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10388
diff
changeset
|
385 | @param 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
|
386 | @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
|
387 | @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
|
388 | 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
|
389 | @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
|
390 | @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
|
391 | @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
|
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 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
|
394 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | ellipsis = "..." |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
398 | 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
|
399 | 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
|
400 | 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
|
401 | 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
|
402 | while head1: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
403 | # 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
|
404 | 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
|
405 | 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
|
406 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | 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
|
408 | 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
|
409 | 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
|
410 | 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
|
411 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
412 | while tail: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | 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
|
414 | 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
|
415 | return path |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
416 | 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
|
417 | return "" |
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 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
|
421 | 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
|
422 | 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
|
423 | 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
|
424 | 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
|
425 | 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
|
426 | 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
|
427 | 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
|
428 | 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
|
429 | ): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
431 | 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
|
432 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | @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
|
434 | @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
|
435 | @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
|
436 | @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
|
437 | @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
|
438 | 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
|
439 | @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
|
440 | @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
|
441 | 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
|
442 | @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
|
443 | @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
|
444 | @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
|
445 | @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
|
446 | @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
|
447 | @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
|
448 | @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
|
449 | @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
|
450 | 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
|
451 | @type bool |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
452 | @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
|
453 | 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
|
454 | @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
|
455 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
456 | 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
|
457 | 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
|
458 | 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
|
459 | ".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
|
460 | ".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
|
461 | ".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
|
462 | ".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
|
463 | ".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
|
464 | ".jedi", |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
465 | "__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
|
466 | ] |
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
|
467 | 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
|
468 | 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
|
469 | |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
470 | 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
|
471 | path |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
472 | ) as dirEntriesIterator: |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
473 | 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
|
474 | 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
|
475 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
476 | |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
477 | 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
|
478 | continue |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
479 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
480 | if ( |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | pattern |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
482 | 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
|
483 | 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
|
484 | ): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
485 | # 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
|
486 | continue |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
487 | |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
488 | if dirEntry.is_dir(): |
10597
fbe93720ee9f
Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10583
diff
changeset
|
489 | if dirEntry.path in ignoreList or ( |
fbe93720ee9f
Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10583
diff
changeset
|
490 | 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
|
491 | ): |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | 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
|
493 | 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
|
494 | 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
|
495 | 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
|
496 | 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
|
497 | 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
|
498 | 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
|
499 | 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
|
500 | 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
|
501 | ) |
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
|
502 | 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
|
503 | 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
|
504 | else: |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
505 | 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
|
506 | return files |
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 | 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
|
510 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
511 | 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
|
512 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
513 | @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
|
514 | @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
|
515 | @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
|
516 | @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
|
517 | @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
|
518 | @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
|
519 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
520 | try: |
9646
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
521 | dirs = [] |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
522 | 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
|
523 | 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
|
524 | if ( |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
525 | 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
|
526 | 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
|
527 | 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
|
528 | ): |
ab5678db972f
Modernize the code by using os.scandir() instead of os.listdir().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9645
diff
changeset
|
529 | 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
|
530 | 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
|
531 | 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
|
532 | except OSError: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
533 | return [] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
534 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
535 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
536 | 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
|
537 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
538 | 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
|
539 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
540 | @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
|
541 | @type str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | @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
|
543 | 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
|
544 | @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
|
545 | @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
|
546 | name |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
547 | @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
|
548 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
549 | volumeDirectories = [] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
550 | volumeDirectory = None |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
551 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
552 | 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
|
553 | # 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
|
554 | 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
|
555 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
556 | 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
|
557 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
558 | 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
|
559 | 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
|
560 | 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
|
561 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
562 | 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
|
563 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
564 | 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
|
565 | 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
|
566 | 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
|
567 | volumeNameBuffer, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
568 | 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
|
569 | None, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
570 | None, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
571 | None, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
572 | None, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
573 | 0, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
574 | ) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
575 | 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
|
576 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
577 | # |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
578 | # 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
|
579 | # 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
|
580 | # 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
|
581 | # 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
|
582 | # |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
583 | 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
|
584 | try: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
585 | 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
|
586 | 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
|
587 | 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
|
588 | if findAll: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
589 | 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
|
590 | 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
|
591 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
592 | 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
|
593 | volumeDirectory = dirpath |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
594 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
595 | finally: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
596 | 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
|
597 | 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
|
598 | # 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
|
599 | 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
|
600 | 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
|
601 | 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
|
602 | 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
|
603 | ).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
|
604 | mountedVolumes = [ |
f706be800097
Refined the 'findVolume()' solution for Linux and macOS to work on both.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9920
diff
changeset
|
605 | 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
|
606 | 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
|
607 | ] |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
608 | if findAll: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
609 | for volume in mountedVolumes: |
9903 | 610 | 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
|
611 | 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
|
612 | if volumeDirectories: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
613 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
614 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
615 | for volume in mountedVolumes: |
9903 | 616 | 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
|
617 | volumeDirectory = volume |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
618 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
619 | if volumeDirectory: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
620 | break |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
621 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
622 | if findAll: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
623 | return volumeDirectories |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
624 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
625 | return volumeDirectory |
9944 | 626 | |
627 | ||
628 | def getUserMounts(): | |
629 | """ | |
630 | Function to determine all available user mounts. | |
631 | ||
632 | Note: On Windows platforms all available drives are returned. | |
633 | ||
634 | @return list of user mounts or drives | |
635 | @rtype list of str | |
636 | """ | |
637 | mountedPaths = [] | |
638 | ||
639 | if OSUtilities.isWindowsPlatform(): | |
640 | # 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
|
641 | for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": |
68ac01294544
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9944
diff
changeset
|
642 | dirpath = "{0}:\\".format(disk) |
68ac01294544
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9944
diff
changeset
|
643 | if os.path.exists(dirpath): |
68ac01294544
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9944
diff
changeset
|
644 | mountedPaths.append(dirpath) |
9944 | 645 | 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
|
646 | # 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
|
647 | 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
|
648 | # 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
|
649 | 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
|
650 | 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
|
651 | # 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
|
652 | 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
|
653 | 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
|
654 | # 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
|
655 | 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
|
656 | 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
|
657 | # 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
|
658 | return [] |
9944 | 659 | |
660 | for mountCommand in ["mount", "/sbin/mount", "/usr/sbin/mount"]: | |
661 | with contextlib.suppress(FileNotFoundError): | |
662 | mountOutput = subprocess.run( # secok | |
663 | mountCommand, check=True, capture_output=True, text=True | |
664 | ).stdout.splitlines() | |
665 | mounts = [ | |
666 | x.split(" type", 1)[0].split(" (", 1)[0].split(maxsplit=2)[-1] | |
667 | for x in mountOutput | |
668 | ] | |
669 | mountedPaths = [x for x in mounts if x.startswith(mountPathStart)] | |
670 | break | |
671 | ||
672 | 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
|
673 | |
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
|
674 | |
10396 | 675 | def startfile(filePath): |
676 | """ | |
677 | Function to open the given file path with the system default application. | |
678 | ||
679 | @param filePath file path to be opened | |
680 | @type str or Path | |
681 | @return flag indicating a successful start of the associated application | |
682 | @rtype bool | |
683 | """ | |
684 | filePath = str(filePath) | |
685 | ||
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
|
686 | 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
|
687 | 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
|
688 | 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
|
689 | return True |
10396 | 690 | |
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
|
691 | 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
|
692 | return subprocess.call(("open", filePath)) == 0 # secok |
10396 | 693 | |
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
|
694 | 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
|
695 | 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
|
696 | |
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
|
697 | # 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
|
698 | return False |
10396 | 699 | |
700 | ||
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
|
701 | ################################################################################ |
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
|
702 | ## 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
|
703 | ################################################################################ |
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
|
704 | |
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
|
705 | |
10971
b9d883f73dff
Fixed an issue in the virtalenv manager caused by a defined virtual environment for an eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10791
diff
changeset
|
706 | # TODO: change these because the pattern collides with Windows drives |
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
|
707 | _DeviceFileMarker = "device:" |
10521
a51b382e47d7
Did a little code reorganization to improve readability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
708 | _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
|
709 | |
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
|
710 | |
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
|
711 | 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
|
712 | """ |
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
|
713 | 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
|
714 | |
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
|
715 | @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
|
716 | @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
|
717 | @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
|
718 | @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
|
719 | """ |
10603
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
720 | if fileName.startswith(_DeviceFileMarker): |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
721 | # 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
|
722 | return fileName |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
723 | else: |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
724 | 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
|
725 | |
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
|
726 | |
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
|
727 | 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
|
728 | """ |
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
|
729 | 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
|
730 | |
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
|
731 | @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
|
732 | @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
|
733 | @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
|
734 | @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
|
735 | """ |
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
|
736 | 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
|
737 | |
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
|
738 | |
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
|
739 | 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
|
740 | """ |
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
|
741 | 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
|
742 | |
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
|
743 | @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
|
744 | @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
|
745 | @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
|
746 | @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
|
747 | """ |
10603
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
748 | if fileName.startswith(_RemoteFileMarker): |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
749 | # 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
|
750 | return fileName |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
751 | else: |
8093b9e14b75
Made some conversion function in FileSystemUtilities more resilient.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10597
diff
changeset
|
752 | 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
|
753 | |
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
|
754 | |
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
|
755 | 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
|
756 | """ |
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
|
757 | 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
|
758 | |
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
|
759 | @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
|
760 | @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
|
761 | @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
|
762 | @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
|
763 | """ |
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
|
764 | 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
|
765 | |
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
|
766 | |
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
|
767 | 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
|
768 | """ |
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
|
769 | 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
|
770 | |
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
|
771 | @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
|
772 | @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
|
773 | @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
|
774 | @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
|
775 | """ |
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
|
776 | 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
|
777 | |
a34ce7f42e8b
Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10339
diff
changeset
|
778 | |
a34ce7f42e8b
Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10339
diff
changeset
|
779 | 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
|
780 | """ |
a34ce7f42e8b
Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10339
diff
changeset
|
781 | 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
|
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 | @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
|
784 | @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
|
785 | @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
|
786 | @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
|
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 | return fileName.replace(_DeviceFileMarker, "").replace(_RemoteFileMarker, "") |