path2success 3.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- path2success-3.6/LICENSE +201 -0
- path2success-3.6/PKG-INFO +116 -0
- path2success-3.6/README.md +104 -0
- path2success-3.6/pyproject.toml +16 -0
- path2success-3.6/setup.cfg +4 -0
- path2success-3.6/src/path2success/__init__.py +1 -0
- path2success-3.6/src/path2success/__main__.py +20 -0
- path2success-3.6/src/path2success/_internal.py +46 -0
- path2success-3.6/src/path2success/main.py +206 -0
- path2success-3.6/src/path2success.egg-info/PKG-INFO +116 -0
- path2success-3.6/src/path2success.egg-info/SOURCES.txt +11 -0
- path2success-3.6/src/path2success.egg-info/dependency_links.txt +1 -0
- path2success-3.6/src/path2success.egg-info/top_level.txt +1 -0
path2success-3.6/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Joel Horensma
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: path2success
|
|
3
|
+
Version: 3.6
|
|
4
|
+
Summary: The "path2success" library, is a multi-OS compatible python library, that includes advanced path-related functions.
|
|
5
|
+
Author: Joel Horensma
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: path,paths,filter,convert bytes,copy,progress bar,ETA
|
|
8
|
+
Requires-Python: >=3.14
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
The **path2success** library, is a multi-OS compatible python library, that includes advanced path-related functions.
|
|
14
|
+
|
|
15
|
+
## **The "is_safely_quoted()" Function:**
|
|
16
|
+
|
|
17
|
+
### **Description:**
|
|
18
|
+
**1.)** Checks if the supplied path, is OS-appropriately quoted and has no extra quotes\
|
|
19
|
+
**2.)** Returns True, if the supplied path is appropriately quoted (Or appropriately not), otherwise returns False
|
|
20
|
+
|
|
21
|
+
### **Example Usage:**
|
|
22
|
+
import path2success\
|
|
23
|
+
PATH = input('Enter a path: ')\
|
|
24
|
+
print(path2success.is_safely_quoted(PATH))\
|
|
25
|
+
input('Press Enter: ')
|
|
26
|
+
|
|
27
|
+
## **The "filter_path()" Function:**
|
|
28
|
+
|
|
29
|
+
### **Description:**
|
|
30
|
+
**1.)** Uses path2success' "appropriate_quotes()" function, to remove any prepended and matching quotes, at the end of the supplied path, as well as, replace any OS-inappropriate quotes, in the supplied path, with OS-appropriate ones\
|
|
31
|
+
**2.)** The "appropriate_quotes()" function, checks if the supplied path contains a space, if it does,\
|
|
32
|
+
the OS-appropriate quotes are added, to the beginning and end of the path, and the OS-appropriately quoted path, is returned to the "filter_path()" function\
|
|
33
|
+
**3.)** Uses path2success' "unquote_path()" function, to remove the beginning and end quotes, added by the "appropriate_quotes()" function (if the supplied path contained a space), then returns the unquoted path, to the "filter_path()" function\
|
|
34
|
+
**4.)** Converts any OS-specific environment variables, in the supplied path, using the "os" module\
|
|
35
|
+
**5.)** Converts any dot-sequences, in the supplied path, and replaces OS-inappropriate slashes, with OS-appropriate slashes, using the "pathlib" module\
|
|
36
|
+
**6.)** Returns a filtered and converted path
|
|
37
|
+
|
|
38
|
+
### **Example Usage:**
|
|
39
|
+
import path2success\
|
|
40
|
+
PATH = input('Enter a path: ')\
|
|
41
|
+
print(path2success.filter_path(PATH))\
|
|
42
|
+
input('Press Enter: ')
|
|
43
|
+
|
|
44
|
+
## **The "appropriate_quotes()" Function:**
|
|
45
|
+
|
|
46
|
+
### **Description:**
|
|
47
|
+
**1.)** Removes any prepended quotes, from the supplied path, as well as matching ones, at the end of the path\
|
|
48
|
+
**2.)** Replaces any OS-inappropriate quotes, with OS-appropriate ones\
|
|
49
|
+
**3.)** Checks if the supplied path contains a space, if it does, the OS-appropriate quotes are added to the beginning and end, of the supplied path\
|
|
50
|
+
**4.)** Returns an appropriately quoted path
|
|
51
|
+
|
|
52
|
+
### **Example Usage:**
|
|
53
|
+
import path2success\
|
|
54
|
+
PATH = input('Enter a path: ')\
|
|
55
|
+
print(path2success.appropriate_quotes(PATH))\
|
|
56
|
+
input('Press Enter: ')
|
|
57
|
+
|
|
58
|
+
## **The "unquote_path()" Function:**
|
|
59
|
+
|
|
60
|
+
### **Description:**
|
|
61
|
+
**1.)** If the first and last characters, in the supplied path, are matching quotes, they are removed\
|
|
62
|
+
**2.)** Returns an unquoted path
|
|
63
|
+
|
|
64
|
+
### **Example Usage:**
|
|
65
|
+
import path2success\
|
|
66
|
+
PATH = input('Enter a path: ')\
|
|
67
|
+
print(path2success.unquote_path(PATH))\
|
|
68
|
+
input('Press Enter: ')
|
|
69
|
+
|
|
70
|
+
## **The "recursive_files_and_bytes_total()" Function:**
|
|
71
|
+
|
|
72
|
+
### **Description:**
|
|
73
|
+
**1.)** Uses path2success' "filter_path()" function, to filter the supplied path\
|
|
74
|
+
**2.)** Recursively scans, for the total number of files and bytes, of data, with the help of the "os" module\
|
|
75
|
+
**3.)** Returns the total number of files and bytes, of data\
|
|
76
|
+
**Note:** path2success' "convert_bytes()" function, can convert the total bytes return value, to kilobytes, megabytes, gigabytes, or even terabytes
|
|
77
|
+
|
|
78
|
+
### **Example Usage:**
|
|
79
|
+
import path2success\
|
|
80
|
+
PATH = input('Enter a path: ')\
|
|
81
|
+
TOTAL_FILES, TOTAL_BYTES = path2success.recursive_files_and_bytes_total(PATH)\
|
|
82
|
+
print(f'Total files: {TOTAL_FILES}')\
|
|
83
|
+
print(f'Total bytes: {TOTAL_BYTES}')\
|
|
84
|
+
input('Press Enter: ')
|
|
85
|
+
|
|
86
|
+
## **The "convert_bytes()" Function:**
|
|
87
|
+
|
|
88
|
+
### **Description:**
|
|
89
|
+
**1.)** Accepts a number of bytes\
|
|
90
|
+
**2.)** Returns the total b, Kb, Mb, Gb, or Tb (Max) value
|
|
91
|
+
|
|
92
|
+
### **Example Usage:**
|
|
93
|
+
import path2success\
|
|
94
|
+
BYTES = input('Enter a number, of bytes: ')\
|
|
95
|
+
CONVERTED_BYTES = path2success.convert_bytes(BYTES)\
|
|
96
|
+
print(f'Converted bytes: {CONVERTED_BYTES}')\
|
|
97
|
+
input('Press Enter: ')
|
|
98
|
+
|
|
99
|
+
## **The "recursive_copy_with_progress()" Function:**
|
|
100
|
+
|
|
101
|
+
### **Description:**
|
|
102
|
+
**1.)** Uses path2success' "filter_path()" function, to filter the supplied source and destination paths\
|
|
103
|
+
**2.)** Calculates and displays the total number of files and bytes, of data, to be copied, from the source path, using path2success' "recursive_files_and_bytes_total()" function and it's internal "convert_bytes()" function, along with the help, of the "os" module\
|
|
104
|
+
**3.)** Creates a new directory, in the destination path, matching the source path's folder name, using the "os" module, if the folder does not already exist in the destination path, however,\
|
|
105
|
+
if the folder does already exist in the destination path, a new directory with a new name is created, in the destination path\
|
|
106
|
+
**4.)** Recursively copies all files and folders within the supplied source path, to the supplied destination path, while displaying a live progress bar and ETA until finished, with the help of the "sys" and "time" modules
|
|
107
|
+
|
|
108
|
+
### **Example Usage:**
|
|
109
|
+
import path2success\
|
|
110
|
+
SOURCE_PATH = input('Enter a source path: ')\
|
|
111
|
+
DESTINATION_PATH = input('Enter a destination path: ')\
|
|
112
|
+
path2success.recursive_copy_with_progress(SOURCE_PATH, DESTINATION_PATH)\
|
|
113
|
+
input('Press Enter: ')
|
|
114
|
+
|
|
115
|
+
### **The "recursive_copy_with_progress()" function, CLI Usage:**
|
|
116
|
+
python -m path2success recursive_copy_with_progress SOURCE_PATH DESTINATION_PATH
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
The **path2success** library, is a multi-OS compatible python library, that includes advanced path-related functions.
|
|
2
|
+
|
|
3
|
+
## **The "is_safely_quoted()" Function:**
|
|
4
|
+
|
|
5
|
+
### **Description:**
|
|
6
|
+
**1.)** Checks if the supplied path, is OS-appropriately quoted and has no extra quotes\
|
|
7
|
+
**2.)** Returns True, if the supplied path is appropriately quoted (Or appropriately not), otherwise returns False
|
|
8
|
+
|
|
9
|
+
### **Example Usage:**
|
|
10
|
+
import path2success\
|
|
11
|
+
PATH = input('Enter a path: ')\
|
|
12
|
+
print(path2success.is_safely_quoted(PATH))\
|
|
13
|
+
input('Press Enter: ')
|
|
14
|
+
|
|
15
|
+
## **The "filter_path()" Function:**
|
|
16
|
+
|
|
17
|
+
### **Description:**
|
|
18
|
+
**1.)** Uses path2success' "appropriate_quotes()" function, to remove any prepended and matching quotes, at the end of the supplied path, as well as, replace any OS-inappropriate quotes, in the supplied path, with OS-appropriate ones\
|
|
19
|
+
**2.)** The "appropriate_quotes()" function, checks if the supplied path contains a space, if it does,\
|
|
20
|
+
the OS-appropriate quotes are added, to the beginning and end of the path, and the OS-appropriately quoted path, is returned to the "filter_path()" function\
|
|
21
|
+
**3.)** Uses path2success' "unquote_path()" function, to remove the beginning and end quotes, added by the "appropriate_quotes()" function (if the supplied path contained a space), then returns the unquoted path, to the "filter_path()" function\
|
|
22
|
+
**4.)** Converts any OS-specific environment variables, in the supplied path, using the "os" module\
|
|
23
|
+
**5.)** Converts any dot-sequences, in the supplied path, and replaces OS-inappropriate slashes, with OS-appropriate slashes, using the "pathlib" module\
|
|
24
|
+
**6.)** Returns a filtered and converted path
|
|
25
|
+
|
|
26
|
+
### **Example Usage:**
|
|
27
|
+
import path2success\
|
|
28
|
+
PATH = input('Enter a path: ')\
|
|
29
|
+
print(path2success.filter_path(PATH))\
|
|
30
|
+
input('Press Enter: ')
|
|
31
|
+
|
|
32
|
+
## **The "appropriate_quotes()" Function:**
|
|
33
|
+
|
|
34
|
+
### **Description:**
|
|
35
|
+
**1.)** Removes any prepended quotes, from the supplied path, as well as matching ones, at the end of the path\
|
|
36
|
+
**2.)** Replaces any OS-inappropriate quotes, with OS-appropriate ones\
|
|
37
|
+
**3.)** Checks if the supplied path contains a space, if it does, the OS-appropriate quotes are added to the beginning and end, of the supplied path\
|
|
38
|
+
**4.)** Returns an appropriately quoted path
|
|
39
|
+
|
|
40
|
+
### **Example Usage:**
|
|
41
|
+
import path2success\
|
|
42
|
+
PATH = input('Enter a path: ')\
|
|
43
|
+
print(path2success.appropriate_quotes(PATH))\
|
|
44
|
+
input('Press Enter: ')
|
|
45
|
+
|
|
46
|
+
## **The "unquote_path()" Function:**
|
|
47
|
+
|
|
48
|
+
### **Description:**
|
|
49
|
+
**1.)** If the first and last characters, in the supplied path, are matching quotes, they are removed\
|
|
50
|
+
**2.)** Returns an unquoted path
|
|
51
|
+
|
|
52
|
+
### **Example Usage:**
|
|
53
|
+
import path2success\
|
|
54
|
+
PATH = input('Enter a path: ')\
|
|
55
|
+
print(path2success.unquote_path(PATH))\
|
|
56
|
+
input('Press Enter: ')
|
|
57
|
+
|
|
58
|
+
## **The "recursive_files_and_bytes_total()" Function:**
|
|
59
|
+
|
|
60
|
+
### **Description:**
|
|
61
|
+
**1.)** Uses path2success' "filter_path()" function, to filter the supplied path\
|
|
62
|
+
**2.)** Recursively scans, for the total number of files and bytes, of data, with the help of the "os" module\
|
|
63
|
+
**3.)** Returns the total number of files and bytes, of data\
|
|
64
|
+
**Note:** path2success' "convert_bytes()" function, can convert the total bytes return value, to kilobytes, megabytes, gigabytes, or even terabytes
|
|
65
|
+
|
|
66
|
+
### **Example Usage:**
|
|
67
|
+
import path2success\
|
|
68
|
+
PATH = input('Enter a path: ')\
|
|
69
|
+
TOTAL_FILES, TOTAL_BYTES = path2success.recursive_files_and_bytes_total(PATH)\
|
|
70
|
+
print(f'Total files: {TOTAL_FILES}')\
|
|
71
|
+
print(f'Total bytes: {TOTAL_BYTES}')\
|
|
72
|
+
input('Press Enter: ')
|
|
73
|
+
|
|
74
|
+
## **The "convert_bytes()" Function:**
|
|
75
|
+
|
|
76
|
+
### **Description:**
|
|
77
|
+
**1.)** Accepts a number of bytes\
|
|
78
|
+
**2.)** Returns the total b, Kb, Mb, Gb, or Tb (Max) value
|
|
79
|
+
|
|
80
|
+
### **Example Usage:**
|
|
81
|
+
import path2success\
|
|
82
|
+
BYTES = input('Enter a number, of bytes: ')\
|
|
83
|
+
CONVERTED_BYTES = path2success.convert_bytes(BYTES)\
|
|
84
|
+
print(f'Converted bytes: {CONVERTED_BYTES}')\
|
|
85
|
+
input('Press Enter: ')
|
|
86
|
+
|
|
87
|
+
## **The "recursive_copy_with_progress()" Function:**
|
|
88
|
+
|
|
89
|
+
### **Description:**
|
|
90
|
+
**1.)** Uses path2success' "filter_path()" function, to filter the supplied source and destination paths\
|
|
91
|
+
**2.)** Calculates and displays the total number of files and bytes, of data, to be copied, from the source path, using path2success' "recursive_files_and_bytes_total()" function and it's internal "convert_bytes()" function, along with the help, of the "os" module\
|
|
92
|
+
**3.)** Creates a new directory, in the destination path, matching the source path's folder name, using the "os" module, if the folder does not already exist in the destination path, however,\
|
|
93
|
+
if the folder does already exist in the destination path, a new directory with a new name is created, in the destination path\
|
|
94
|
+
**4.)** Recursively copies all files and folders within the supplied source path, to the supplied destination path, while displaying a live progress bar and ETA until finished, with the help of the "sys" and "time" modules
|
|
95
|
+
|
|
96
|
+
### **Example Usage:**
|
|
97
|
+
import path2success\
|
|
98
|
+
SOURCE_PATH = input('Enter a source path: ')\
|
|
99
|
+
DESTINATION_PATH = input('Enter a destination path: ')\
|
|
100
|
+
path2success.recursive_copy_with_progress(SOURCE_PATH, DESTINATION_PATH)\
|
|
101
|
+
input('Press Enter: ')
|
|
102
|
+
|
|
103
|
+
### **The "recursive_copy_with_progress()" function, CLI Usage:**
|
|
104
|
+
python -m path2success recursive_copy_with_progress SOURCE_PATH DESTINATION_PATH
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ['setuptools']
|
|
3
|
+
build-backend = 'setuptools.build_meta'
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
keywords = ['path', 'paths', 'filter', 'convert bytes', 'copy', 'progress bar', 'ETA']
|
|
7
|
+
name = 'path2success'
|
|
8
|
+
version = '3.6'
|
|
9
|
+
description = 'The "path2success" library, is a multi-OS compatible python library, that includes advanced path-related functions.'
|
|
10
|
+
readme = 'README.md'
|
|
11
|
+
license = 'Apache-2.0'
|
|
12
|
+
authors = [{name = 'Joel Horensma'}]
|
|
13
|
+
requires-python = '>=3.14'
|
|
14
|
+
|
|
15
|
+
[tool.setuptools.packages.find]
|
|
16
|
+
where = ['src']
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .main import *
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from .main import recursive_copy_with_progress
|
|
3
|
+
|
|
4
|
+
def main():
|
|
5
|
+
if len(sys.argv) < 4:
|
|
6
|
+
print('Usage: python -m path2success recursive_copy_with_progress SOURCE_PATH DESTINATION_PATH\n')
|
|
7
|
+
sys.exit(1)
|
|
8
|
+
|
|
9
|
+
COMMAND = sys.argv[1]
|
|
10
|
+
|
|
11
|
+
if COMMAND == 'recursive_copy_with_progress':
|
|
12
|
+
SOURCE_PATH = sys.argv[2]
|
|
13
|
+
DESTINATION_PATH = sys.argv[3]
|
|
14
|
+
recursive_copy_with_progress(SOURCE_PATH, DESTINATION_PATH)
|
|
15
|
+
else:
|
|
16
|
+
print(f'Unknown command: {COMMAND}')
|
|
17
|
+
sys.exit(1)
|
|
18
|
+
|
|
19
|
+
if __name__ == '__main__':
|
|
20
|
+
main()
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import os, sys
|
|
2
|
+
|
|
3
|
+
#CONVERTS SECONDS, TO FULL TIME FORMAT
|
|
4
|
+
def convert_seconds(SECONDS):
|
|
5
|
+
SECONDS = str(SECONDS).strip()
|
|
6
|
+
if SECONDS:
|
|
7
|
+
if SECONDS.isnumeric():
|
|
8
|
+
SECONDS = int(SECONDS)
|
|
9
|
+
YEARS = f'{SECONDS // 31536000}y:' if (SECONDS // 31536000) > 0 else ''
|
|
10
|
+
REMAINDER_SECONDS = SECONDS % 31536000
|
|
11
|
+
MONTHS = f'{REMAINDER_SECONDS // 2628000}M:' if (REMAINDER_SECONDS // 2628000) > 0 else ''
|
|
12
|
+
REMAINDER_SECONDS %= 2628000
|
|
13
|
+
WEEKS = f'{REMAINDER_SECONDS // 604800}w:' if (REMAINDER_SECONDS // 604800) > 0 else ''
|
|
14
|
+
REMAINDER_SECONDS %= 604800
|
|
15
|
+
DAYS = f'{REMAINDER_SECONDS // 86400}d:' if (REMAINDER_SECONDS // 86400) > 0 else ''
|
|
16
|
+
REMAINDER_SECONDS %= 86400
|
|
17
|
+
HOURS = f'{REMAINDER_SECONDS // 3600}h:' if (REMAINDER_SECONDS // 3600) > 0 else ''
|
|
18
|
+
REMAINDER_SECONDS %= 3600
|
|
19
|
+
MINUTES = f'{REMAINDER_SECONDS // 60}m:' if (REMAINDER_SECONDS // 60) > 0 else ''
|
|
20
|
+
REMAINDER_SECONDS %= 60
|
|
21
|
+
SECONDS = f'{REMAINDER_SECONDS % 60}s'
|
|
22
|
+
CONVERTED_SECONDS = f'{YEARS}{MONTHS}{WEEKS}{DAYS}{HOURS}{MINUTES}{SECONDS}'
|
|
23
|
+
return CONVERTED_SECONDS
|
|
24
|
+
else:
|
|
25
|
+
raise TypeError('"convert_seconds()": The "SECONDS" variable, must be an integer')
|
|
26
|
+
else:
|
|
27
|
+
raise EOFError('"convert_seconds()": The "SECONDS" variable, cannot be empty')
|
|
28
|
+
|
|
29
|
+
#DISPLAY A PROGRESS BAR, FOR THE "recursive_copy_with_progress()" FUNCTION
|
|
30
|
+
def recursive_copy_progress_bar(COPIED_BYTES, TOTAL_BYTES, ETA_SECONDS, PADDING_WIDTH = 10):
|
|
31
|
+
COPIED_BYTES, TOTAL_BYTES, ETA_SECONDS = str(COPIED_BYTES).strip(), str(TOTAL_BYTES).strip(), str(ETA_SECONDS).strip()
|
|
32
|
+
if all([COPIED_BYTES, TOTAL_BYTES, ETA_SECONDS]):
|
|
33
|
+
if all([COPIED_BYTES.isnumeric(), TOTAL_BYTES.isnumeric(), ETA_SECONDS.isnumeric()]):
|
|
34
|
+
COPIED_BYTES, TOTAL_BYTES, ETA_SECONDS = int(COPIED_BYTES), int(TOTAL_BYTES), int(ETA_SECONDS)
|
|
35
|
+
PERCENT = (COPIED_BYTES / TOTAL_BYTES) * 100
|
|
36
|
+
BARS_FILLED = (30 * COPIED_BYTES) // TOTAL_BYTES
|
|
37
|
+
PROGRESS_BAR = '=' * BARS_FILLED + '-' * (30 - BARS_FILLED)
|
|
38
|
+
ETA = convert_seconds(ETA_SECONDS)
|
|
39
|
+
sys.stdout.write(f'\rProgress: [{PROGRESS_BAR}]({round(PERCENT)}%) ETA: {ETA.ljust((PADDING_WIDTH))}')
|
|
40
|
+
sys.stdout.flush()
|
|
41
|
+
else:
|
|
42
|
+
raise TypeError('"recursive_copy_progress_bar()": One or more non-integer variables, were supplied')
|
|
43
|
+
else:
|
|
44
|
+
raise EOFError('"recursive_copy_progress_bar()": One or more empty variables, were supplied')
|
|
45
|
+
if PERCENT == 100.0:
|
|
46
|
+
print('\nFinished!\n')
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import os, platform, time
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from . import _internal
|
|
4
|
+
|
|
5
|
+
#RETURNS "True", IF THE SUPPLIED PATH IS OS-APPROPRIATELY AND CORRECTLY QUOTED, OTHERWISE "False"
|
|
6
|
+
def is_safely_quoted(PATH):
|
|
7
|
+
PATH = PATH.strip()
|
|
8
|
+
if PATH:
|
|
9
|
+
if isinstance(PATH, str):
|
|
10
|
+
OS_QUOTE = '"' if platform.system() == 'Windows' else "'"
|
|
11
|
+
PREPENDED_QUOTES = 0
|
|
12
|
+
for CHARACTER in PATH:
|
|
13
|
+
if CHARACTER in ["'", '"']:
|
|
14
|
+
PREPENDED_QUOTES += 1
|
|
15
|
+
else:
|
|
16
|
+
break
|
|
17
|
+
if os.path.isabs(PATH[1:-1]) and ' ' in PATH and PATH.startswith(OS_QUOTE) and PATH.endswith(OS_QUOTE) and PATH.count(OS_QUOTE) == 2 and PREPENDED_QUOTES < 2:
|
|
18
|
+
return True
|
|
19
|
+
elif ' ' not in PATH and OS_QUOTE not in PATH and PREPENDED_QUOTES == 0:
|
|
20
|
+
return True
|
|
21
|
+
else:
|
|
22
|
+
return False
|
|
23
|
+
else:
|
|
24
|
+
raise TypeError('"is_safely_quoted()": The "PATH" variable, must be a string')
|
|
25
|
+
else:
|
|
26
|
+
raise EOFError('"is_safely_quoted()": The "PATH" variable, cannot be empty')
|
|
27
|
+
|
|
28
|
+
#OS-APPROPRIATELY QUOTES, A SUPPLIED PATH (IF A SPACE, IS PRESENT) AND FIXES INCORRECT QUOTING
|
|
29
|
+
def appropriate_quotes(PATH):
|
|
30
|
+
PATH = PATH.strip()
|
|
31
|
+
if PATH:
|
|
32
|
+
if isinstance(PATH, str):
|
|
33
|
+
if is_safely_quoted(PATH):
|
|
34
|
+
return PATH
|
|
35
|
+
else:
|
|
36
|
+
NON_OS_QUOTE = "'" if platform.system() == 'Windows' else '"'
|
|
37
|
+
OS_QUOTE = '"' if platform.system() == 'Windows' else "'"
|
|
38
|
+
PREPENDED_QUOTES = 0
|
|
39
|
+
MATCHED_QUOTES = 0
|
|
40
|
+
for CHARACTER in PATH:
|
|
41
|
+
if CHARACTER in ["'", '"']:
|
|
42
|
+
PREPENDED_QUOTES += 1
|
|
43
|
+
if CHARACTER == PATH[-PREPENDED_QUOTES]:
|
|
44
|
+
MATCHED_QUOTES += 1
|
|
45
|
+
else:
|
|
46
|
+
break
|
|
47
|
+
PATH = PATH[PREPENDED_QUOTES:-MATCHED_QUOTES].replace(OS_QUOTE, NON_OS_QUOTE) if MATCHED_QUOTES > 0 else PATH[PREPENDED_QUOTES:].replace(OS_QUOTE, NON_OS_QUOTE)
|
|
48
|
+
PATH = f'{OS_QUOTE}{PATH}{OS_QUOTE}' if ' ' in PATH else PATH.replace(OS_QUOTE, NON_OS_QUOTE)
|
|
49
|
+
return PATH
|
|
50
|
+
else:
|
|
51
|
+
raise TypeError('"appropriate_quotes()": The "PATH" variable, must be a string')
|
|
52
|
+
else:
|
|
53
|
+
raise EOFError('"appropriate_quotes()": The "PATH" variable, cannot be empty')
|
|
54
|
+
|
|
55
|
+
#UNQUOTES, THE FIRST INSTANCES, OF BEGINNING AND END QUOTES, OF THE SUPPLIED PATH
|
|
56
|
+
def unquote_path(PATH):
|
|
57
|
+
PATH = PATH.strip()
|
|
58
|
+
if PATH:
|
|
59
|
+
if isinstance(PATH, str):
|
|
60
|
+
QUOTES = ["'", '"']
|
|
61
|
+
if PATH[0] in QUOTES and PATH[0] == PATH[-1]:
|
|
62
|
+
return PATH[1:-1]
|
|
63
|
+
else:
|
|
64
|
+
return PATH
|
|
65
|
+
else:
|
|
66
|
+
raise TypeError('"unquote_path()": The "PATH" variable, must be a string')
|
|
67
|
+
else:
|
|
68
|
+
raise EOFError('"unquote_path()": The "PATH" variable, cannot be empty')
|
|
69
|
+
|
|
70
|
+
#STRIPS, EXPANDS VARIABLES, OS-NORMALIZES SLASHES, AND CONVERTS DOT-SEQUENCES, FROM THE SUPPLIED PATH
|
|
71
|
+
def filter_path(PATH):
|
|
72
|
+
PATH = PATH.strip()
|
|
73
|
+
if PATH:
|
|
74
|
+
if isinstance(PATH, str):
|
|
75
|
+
PATH = appropriate_quotes(PATH)
|
|
76
|
+
PATH = unquote_path(PATH)
|
|
77
|
+
PATHLIB_PATH = str(Path.cwd())
|
|
78
|
+
PATH = os.path.expandvars(PATH)
|
|
79
|
+
RESOLVED = str(Path(PATH).resolve(strict=False))
|
|
80
|
+
STRIP_LENGTH = 0 if len(PATHLIB_PATH) == 0 else len(PATHLIB_PATH) + 1
|
|
81
|
+
if not os.path.isabs(PATH) and RESOLVED.lower().startswith(PATHLIB_PATH.lower()):
|
|
82
|
+
PATH = RESOLVED[STRIP_LENGTH:]
|
|
83
|
+
else:
|
|
84
|
+
PATH = RESOLVED
|
|
85
|
+
return PATH
|
|
86
|
+
else:
|
|
87
|
+
raise TypeError('"filter_path()": The "PATH" variable, must be a string')
|
|
88
|
+
else:
|
|
89
|
+
raise EOFError('"filter_path()": The "PATH" variable, cannot be empty')
|
|
90
|
+
|
|
91
|
+
#RECURSIVELY SCANS A FOLDER PATH, FOR THE TOTAL NUMBER, OF FILES OF BYTES, KILOBYTES, MEGABYTES, ETC.
|
|
92
|
+
def recursive_files_and_bytes_total(PATH):
|
|
93
|
+
PATH = PATH.strip()
|
|
94
|
+
if PATH:
|
|
95
|
+
if isinstance(PATH, str):
|
|
96
|
+
PATH = filter_path(PATH)
|
|
97
|
+
if os.path.exists(PATH):
|
|
98
|
+
if os.path.isdir(PATH):
|
|
99
|
+
FILES_TOTAL = 0
|
|
100
|
+
BYTES_TOTAL = 0
|
|
101
|
+
|
|
102
|
+
#LOOP THROUGH FOLDERS, IN THE PATH, RECURSIVELY
|
|
103
|
+
for WALK_PATH, DIRECTORIES, FILES in os.walk(PATH):
|
|
104
|
+
|
|
105
|
+
#REMOVE HIDDEN AND LINK FILES, FROM THE FILES LIST
|
|
106
|
+
FILES = [FILE for FILE in FILES if not FILE.startswith('.') and not os.path.islink(os.path.join(WALK_PATH, FILE))]
|
|
107
|
+
|
|
108
|
+
#LOOP THROUGH FILES, IN THE FOLDER
|
|
109
|
+
for FILE in FILES:
|
|
110
|
+
FILES_TOTAL += 1
|
|
111
|
+
SCAN_PATH = os.path.join(WALK_PATH, FILE)
|
|
112
|
+
FILE_SIZE = os.path.getsize(SCAN_PATH)
|
|
113
|
+
BYTES_TOTAL += FILE_SIZE
|
|
114
|
+
return FILES_TOTAL, BYTES_TOTAL
|
|
115
|
+
else:
|
|
116
|
+
raise NotADirectoryError('"recursive_files_and_bytes_total()": The "PATH" variable, must be a path, to a folder')
|
|
117
|
+
else:
|
|
118
|
+
raise FileNotFoundError(f'"recursive_files_and_bytes_total()": The path: {PATH}, was not found')
|
|
119
|
+
else:
|
|
120
|
+
raise TypeError('"recursive_files_and_bytes_total()": The "PATH" variable, must be a string')
|
|
121
|
+
else:
|
|
122
|
+
raise EOFError('"recursive_files_and_bytes_total()": The "PATH" variable, cannot be empty')
|
|
123
|
+
|
|
124
|
+
#CONVERTS BYTES, TO OTHER MEASUREMENTS, IN BINARY FORMAT
|
|
125
|
+
def convert_bytes(BYTES):
|
|
126
|
+
BYTES = str(BYTES).strip()
|
|
127
|
+
if BYTES:
|
|
128
|
+
if BYTES.isnumeric():
|
|
129
|
+
BYTES = int(BYTES)
|
|
130
|
+
BINARY_INCREMENT = 1024
|
|
131
|
+
if BYTES < BINARY_INCREMENT:return f'{BYTES} b'
|
|
132
|
+
KILOBYTES = f'{round(BYTES/BINARY_INCREMENT, 2)}'
|
|
133
|
+
if BYTES >= BINARY_INCREMENT and BYTES < BINARY_INCREMENT ** 2:return f'{KILOBYTES} kb'
|
|
134
|
+
MEGABYTES = round(BYTES/(BINARY_INCREMENT ** 2), 2)
|
|
135
|
+
if BYTES >= (BINARY_INCREMENT ** 2) and BYTES < BINARY_INCREMENT ** 3:return f'{MEGABYTES} Mb'
|
|
136
|
+
GIGABYTES = round(BYTES/(BINARY_INCREMENT ** 3), 2)
|
|
137
|
+
if BYTES >= (BINARY_INCREMENT ** 3) and BYTES < BINARY_INCREMENT ** 4:return f'{GIGABYTES} Gb'
|
|
138
|
+
TERABYTES = round(BYTES/(BINARY_INCREMENT ** 4), 2)
|
|
139
|
+
return f'{round(TERABYTES, 2)} Tb'
|
|
140
|
+
else:
|
|
141
|
+
raise TypeError('"convert_bytes()": The "BYTES" variable, must be an integer')
|
|
142
|
+
else:
|
|
143
|
+
raise EOFError('"convert_bytes()": The "BYTES" variable, cannot be empty')
|
|
144
|
+
|
|
145
|
+
#RECURSIVELY COPIES A SUPPLIED SOURCE PATH, TO A SUPPLIED DESTINATION PATH,
|
|
146
|
+
#WHILE SKIPPING FILES THAT CANNOT BE COPIED, LIKE HIDDEN AND SYM-LINK FILES
|
|
147
|
+
def recursive_copy_with_progress(SOURCE_PATH, DESTINATION_PATH):
|
|
148
|
+
SOURCE_PATH, DESTINATION_PATH = SOURCE_PATH.strip(), DESTINATION_PATH.strip()
|
|
149
|
+
if SOURCE_PATH and DESTINATION_PATH:
|
|
150
|
+
if isinstance(SOURCE_PATH, str) and isinstance(DESTINATION_PATH, str):
|
|
151
|
+
SOURCE_PATH = filter_path(SOURCE_PATH)
|
|
152
|
+
DESTINATION_PATH = filter_path(DESTINATION_PATH)
|
|
153
|
+
if os.path.exists(SOURCE_PATH) and os.path.exists(DESTINATION_PATH):
|
|
154
|
+
if os.path.isdir(SOURCE_PATH) and os.path.isdir(DESTINATION_PATH):
|
|
155
|
+
TOTAL_FILES, TOTAL_BYTES = recursive_files_and_bytes_total(SOURCE_PATH)
|
|
156
|
+
print(f'Copying a total of: {TOTAL_FILES} files ({convert_bytes(TOTAL_BYTES)})')
|
|
157
|
+
DESTINATION_PATH = os.path.join(DESTINATION_PATH, os.path.basename(SOURCE_PATH))
|
|
158
|
+
if SOURCE_PATH == DESTINATION_PATH or os.path.exists(DESTINATION_PATH):
|
|
159
|
+
i = 0
|
|
160
|
+
MAKE_DESTINATION_DIRECTORY = DESTINATION_PATH
|
|
161
|
+
|
|
162
|
+
#CHECK IF THE FOLDER ALREADY EXISTS, IN THE DESTINATION PATH
|
|
163
|
+
#AND MAKE A NEW FOLDER, WITH A DIFFERENT NAME, IF SO
|
|
164
|
+
while os.path.exists(MAKE_DESTINATION_DIRECTORY) == True:
|
|
165
|
+
i += 1
|
|
166
|
+
MAKE_DESTINATION_DIRECTORY = DESTINATION_PATH + ' ' + str(f'- Copy {i}').strip()
|
|
167
|
+
DESTINATION_PATH = MAKE_DESTINATION_DIRECTORY
|
|
168
|
+
|
|
169
|
+
#MAKE THE FOLDER, IN THE DESTINATION PATH
|
|
170
|
+
os.makedirs(DESTINATION_PATH, exist_ok=True)
|
|
171
|
+
START_COPY = time.time()
|
|
172
|
+
COPIED_BYTES = 0
|
|
173
|
+
for WALK_PATH, DIRECTORIES, FILES in os.walk(SOURCE_PATH):
|
|
174
|
+
RELATIVE_DIRECTORY = os.path.relpath(WALK_PATH, SOURCE_PATH)
|
|
175
|
+
SUB_DESTINATION_DIRECTORY = os.path.join(DESTINATION_PATH, RELATIVE_DIRECTORY)
|
|
176
|
+
os.makedirs(SUB_DESTINATION_DIRECTORY, exist_ok=True)
|
|
177
|
+
|
|
178
|
+
#REMOVE HIDDEN AND SYM-LINK FILES, FROM THE FILES LIST
|
|
179
|
+
FILES = [FILE_NAME for FILE_NAME in FILES if not FILE_NAME.startswith('.') and not os.path.islink(os.path.join(WALK_PATH, FILE_NAME))]
|
|
180
|
+
|
|
181
|
+
for FILE_NAME in FILES:
|
|
182
|
+
SOURCE_FILE_PATH = os.path.join(WALK_PATH, FILE_NAME)
|
|
183
|
+
DESTINATION_FILE_PATH = os.path.join(SUB_DESTINATION_DIRECTORY, FILE_NAME)
|
|
184
|
+
with open(SOURCE_FILE_PATH, 'rb') as FILE_SOURCE, open(DESTINATION_FILE_PATH, 'wb') as FILE_DESTINATION:
|
|
185
|
+
BUFFER_SIZE = (1024 * 1024 * 2)
|
|
186
|
+
while True:
|
|
187
|
+
DATA_CHUNK = FILE_SOURCE.read(BUFFER_SIZE)
|
|
188
|
+
if not DATA_CHUNK:
|
|
189
|
+
break
|
|
190
|
+
else:
|
|
191
|
+
FILE_DESTINATION.write(DATA_CHUNK)
|
|
192
|
+
COPIED_BYTES += len(DATA_CHUNK)
|
|
193
|
+
COPY_COMPLETE = time.time()
|
|
194
|
+
ELAPSED_SECONDS = float(COPY_COMPLETE - START_COPY)
|
|
195
|
+
BYTES_PER_SECOND = (COPIED_BYTES / ELAPSED_SECONDS)
|
|
196
|
+
ETA_SECONDS = int(f'{(TOTAL_BYTES - COPIED_BYTES) / BYTES_PER_SECOND:.0f}')
|
|
197
|
+
_internal.recursive_copy_progress_bar(COPIED_BYTES, TOTAL_BYTES, ETA_SECONDS)
|
|
198
|
+
return
|
|
199
|
+
else:
|
|
200
|
+
raise NotADirectoryError('"recursive_copy_with_progress()": One or more supplied paths, do not exist')
|
|
201
|
+
else:
|
|
202
|
+
raise FileNotFoundError(f'"recursive_copy_with_progress()": One or more supplied paths, were not found')
|
|
203
|
+
else:
|
|
204
|
+
raise TypeError('"recursive_copy_with_progress()": One or more non-string variables, were supplied')
|
|
205
|
+
else:
|
|
206
|
+
raise EOFError('"recursive_copy_with_progress()": One or more empty variables, were supplied')
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: path2success
|
|
3
|
+
Version: 3.6
|
|
4
|
+
Summary: The "path2success" library, is a multi-OS compatible python library, that includes advanced path-related functions.
|
|
5
|
+
Author: Joel Horensma
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: path,paths,filter,convert bytes,copy,progress bar,ETA
|
|
8
|
+
Requires-Python: >=3.14
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
The **path2success** library, is a multi-OS compatible python library, that includes advanced path-related functions.
|
|
14
|
+
|
|
15
|
+
## **The "is_safely_quoted()" Function:**
|
|
16
|
+
|
|
17
|
+
### **Description:**
|
|
18
|
+
**1.)** Checks if the supplied path, is OS-appropriately quoted and has no extra quotes\
|
|
19
|
+
**2.)** Returns True, if the supplied path is appropriately quoted (Or appropriately not), otherwise returns False
|
|
20
|
+
|
|
21
|
+
### **Example Usage:**
|
|
22
|
+
import path2success\
|
|
23
|
+
PATH = input('Enter a path: ')\
|
|
24
|
+
print(path2success.is_safely_quoted(PATH))\
|
|
25
|
+
input('Press Enter: ')
|
|
26
|
+
|
|
27
|
+
## **The "filter_path()" Function:**
|
|
28
|
+
|
|
29
|
+
### **Description:**
|
|
30
|
+
**1.)** Uses path2success' "appropriate_quotes()" function, to remove any prepended and matching quotes, at the end of the supplied path, as well as, replace any OS-inappropriate quotes, in the supplied path, with OS-appropriate ones\
|
|
31
|
+
**2.)** The "appropriate_quotes()" function, checks if the supplied path contains a space, if it does,\
|
|
32
|
+
the OS-appropriate quotes are added, to the beginning and end of the path, and the OS-appropriately quoted path, is returned to the "filter_path()" function\
|
|
33
|
+
**3.)** Uses path2success' "unquote_path()" function, to remove the beginning and end quotes, added by the "appropriate_quotes()" function (if the supplied path contained a space), then returns the unquoted path, to the "filter_path()" function\
|
|
34
|
+
**4.)** Converts any OS-specific environment variables, in the supplied path, using the "os" module\
|
|
35
|
+
**5.)** Converts any dot-sequences, in the supplied path, and replaces OS-inappropriate slashes, with OS-appropriate slashes, using the "pathlib" module\
|
|
36
|
+
**6.)** Returns a filtered and converted path
|
|
37
|
+
|
|
38
|
+
### **Example Usage:**
|
|
39
|
+
import path2success\
|
|
40
|
+
PATH = input('Enter a path: ')\
|
|
41
|
+
print(path2success.filter_path(PATH))\
|
|
42
|
+
input('Press Enter: ')
|
|
43
|
+
|
|
44
|
+
## **The "appropriate_quotes()" Function:**
|
|
45
|
+
|
|
46
|
+
### **Description:**
|
|
47
|
+
**1.)** Removes any prepended quotes, from the supplied path, as well as matching ones, at the end of the path\
|
|
48
|
+
**2.)** Replaces any OS-inappropriate quotes, with OS-appropriate ones\
|
|
49
|
+
**3.)** Checks if the supplied path contains a space, if it does, the OS-appropriate quotes are added to the beginning and end, of the supplied path\
|
|
50
|
+
**4.)** Returns an appropriately quoted path
|
|
51
|
+
|
|
52
|
+
### **Example Usage:**
|
|
53
|
+
import path2success\
|
|
54
|
+
PATH = input('Enter a path: ')\
|
|
55
|
+
print(path2success.appropriate_quotes(PATH))\
|
|
56
|
+
input('Press Enter: ')
|
|
57
|
+
|
|
58
|
+
## **The "unquote_path()" Function:**
|
|
59
|
+
|
|
60
|
+
### **Description:**
|
|
61
|
+
**1.)** If the first and last characters, in the supplied path, are matching quotes, they are removed\
|
|
62
|
+
**2.)** Returns an unquoted path
|
|
63
|
+
|
|
64
|
+
### **Example Usage:**
|
|
65
|
+
import path2success\
|
|
66
|
+
PATH = input('Enter a path: ')\
|
|
67
|
+
print(path2success.unquote_path(PATH))\
|
|
68
|
+
input('Press Enter: ')
|
|
69
|
+
|
|
70
|
+
## **The "recursive_files_and_bytes_total()" Function:**
|
|
71
|
+
|
|
72
|
+
### **Description:**
|
|
73
|
+
**1.)** Uses path2success' "filter_path()" function, to filter the supplied path\
|
|
74
|
+
**2.)** Recursively scans, for the total number of files and bytes, of data, with the help of the "os" module\
|
|
75
|
+
**3.)** Returns the total number of files and bytes, of data\
|
|
76
|
+
**Note:** path2success' "convert_bytes()" function, can convert the total bytes return value, to kilobytes, megabytes, gigabytes, or even terabytes
|
|
77
|
+
|
|
78
|
+
### **Example Usage:**
|
|
79
|
+
import path2success\
|
|
80
|
+
PATH = input('Enter a path: ')\
|
|
81
|
+
TOTAL_FILES, TOTAL_BYTES = path2success.recursive_files_and_bytes_total(PATH)\
|
|
82
|
+
print(f'Total files: {TOTAL_FILES}')\
|
|
83
|
+
print(f'Total bytes: {TOTAL_BYTES}')\
|
|
84
|
+
input('Press Enter: ')
|
|
85
|
+
|
|
86
|
+
## **The "convert_bytes()" Function:**
|
|
87
|
+
|
|
88
|
+
### **Description:**
|
|
89
|
+
**1.)** Accepts a number of bytes\
|
|
90
|
+
**2.)** Returns the total b, Kb, Mb, Gb, or Tb (Max) value
|
|
91
|
+
|
|
92
|
+
### **Example Usage:**
|
|
93
|
+
import path2success\
|
|
94
|
+
BYTES = input('Enter a number, of bytes: ')\
|
|
95
|
+
CONVERTED_BYTES = path2success.convert_bytes(BYTES)\
|
|
96
|
+
print(f'Converted bytes: {CONVERTED_BYTES}')\
|
|
97
|
+
input('Press Enter: ')
|
|
98
|
+
|
|
99
|
+
## **The "recursive_copy_with_progress()" Function:**
|
|
100
|
+
|
|
101
|
+
### **Description:**
|
|
102
|
+
**1.)** Uses path2success' "filter_path()" function, to filter the supplied source and destination paths\
|
|
103
|
+
**2.)** Calculates and displays the total number of files and bytes, of data, to be copied, from the source path, using path2success' "recursive_files_and_bytes_total()" function and it's internal "convert_bytes()" function, along with the help, of the "os" module\
|
|
104
|
+
**3.)** Creates a new directory, in the destination path, matching the source path's folder name, using the "os" module, if the folder does not already exist in the destination path, however,\
|
|
105
|
+
if the folder does already exist in the destination path, a new directory with a new name is created, in the destination path\
|
|
106
|
+
**4.)** Recursively copies all files and folders within the supplied source path, to the supplied destination path, while displaying a live progress bar and ETA until finished, with the help of the "sys" and "time" modules
|
|
107
|
+
|
|
108
|
+
### **Example Usage:**
|
|
109
|
+
import path2success\
|
|
110
|
+
SOURCE_PATH = input('Enter a source path: ')\
|
|
111
|
+
DESTINATION_PATH = input('Enter a destination path: ')\
|
|
112
|
+
path2success.recursive_copy_with_progress(SOURCE_PATH, DESTINATION_PATH)\
|
|
113
|
+
input('Press Enter: ')
|
|
114
|
+
|
|
115
|
+
### **The "recursive_copy_with_progress()" function, CLI Usage:**
|
|
116
|
+
python -m path2success recursive_copy_with_progress SOURCE_PATH DESTINATION_PATH
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/path2success/__init__.py
|
|
5
|
+
src/path2success/__main__.py
|
|
6
|
+
src/path2success/_internal.py
|
|
7
|
+
src/path2success/main.py
|
|
8
|
+
src/path2success.egg-info/PKG-INFO
|
|
9
|
+
src/path2success.egg-info/SOURCES.txt
|
|
10
|
+
src/path2success.egg-info/dependency_links.txt
|
|
11
|
+
src/path2success.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
path2success
|