dazzle-filekit 0.1.0__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.
- dazzle_filekit-0.1.0/LICENSE +21 -0
- dazzle_filekit-0.1.0/PKG-INFO +242 -0
- dazzle_filekit-0.1.0/README.md +201 -0
- dazzle_filekit-0.1.0/dazzle_filekit/__init__.py +164 -0
- dazzle_filekit-0.1.0/dazzle_filekit/operations.py +670 -0
- dazzle_filekit-0.1.0/dazzle_filekit/paths.py +503 -0
- dazzle_filekit-0.1.0/dazzle_filekit/platform/__init__.py +99 -0
- dazzle_filekit-0.1.0/dazzle_filekit/platform/unix.py +35 -0
- dazzle_filekit-0.1.0/dazzle_filekit/platform/windows.py +48 -0
- dazzle_filekit-0.1.0/dazzle_filekit/utils/__init__.py +46 -0
- dazzle_filekit-0.1.0/dazzle_filekit/utils/compat.py +212 -0
- dazzle_filekit-0.1.0/dazzle_filekit/utils/logger.py +199 -0
- dazzle_filekit-0.1.0/dazzle_filekit/utils/validation.py +293 -0
- dazzle_filekit-0.1.0/dazzle_filekit/verification.py +440 -0
- dazzle_filekit-0.1.0/dazzle_filekit.egg-info/PKG-INFO +242 -0
- dazzle_filekit-0.1.0/dazzle_filekit.egg-info/SOURCES.txt +21 -0
- dazzle_filekit-0.1.0/dazzle_filekit.egg-info/dependency_links.txt +1 -0
- dazzle_filekit-0.1.0/dazzle_filekit.egg-info/requires.txt +12 -0
- dazzle_filekit-0.1.0/dazzle_filekit.egg-info/top_level.txt +1 -0
- dazzle_filekit-0.1.0/pyproject.toml +67 -0
- dazzle_filekit-0.1.0/setup.cfg +4 -0
- dazzle_filekit-0.1.0/setup.py +23 -0
- dazzle_filekit-0.1.0/tests/test_smoke.py +59 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dustin Darcy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dazzle-filekit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cross-platform file operations toolkit with path handling, verification, and metadata preservation
|
|
5
|
+
Author: Dustin
|
|
6
|
+
Author-email: Dustin Darcy <6962246+djdarcy@users.noreply.github.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/DazzleLib/dazzle-filekit
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/DazzleLib/dazzle-filekit/issues
|
|
10
|
+
Project-URL: Source, https://github.com/DazzleLib/dazzle-filekit
|
|
11
|
+
Project-URL: Documentation, https://github.com/DazzleLib/dazzle-filekit#readme
|
|
12
|
+
Keywords: file,operations,path,verification,hash,metadata,cross-platform
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
23
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
24
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Topic :: System :: Filesystems
|
|
27
|
+
Requires-Python: >=3.6
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: pathlib; python_version < "3.4"
|
|
31
|
+
Provides-Extra: unctools
|
|
32
|
+
Requires-Dist: unctools>=0.1.0; extra == "unctools"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: flake8>=3.8.0; extra == "dev"
|
|
37
|
+
Requires-Dist: black>=20.8b1; extra == "dev"
|
|
38
|
+
Dynamic: author
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
|
|
42
|
+
# dazzle-filekit
|
|
43
|
+
|
|
44
|
+
[](https://badge.fury.io/py/dazzle-filekit)
|
|
45
|
+
[](https://pypi.org/project/dazzle-filekit/)
|
|
46
|
+
[](https://opensource.org/licenses/MIT)
|
|
47
|
+
|
|
48
|
+
**Cross-platform file operations toolkit with path handling, verification, and metadata preservation**
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
- **Path Operations**: Cross-platform path handling, normalization, and manipulation
|
|
53
|
+
- **File Operations**: Copy, move, and manage files with metadata preservation
|
|
54
|
+
- **File Verification**: Calculate and verify file hashes (MD5, SHA1, SHA256, SHA512)
|
|
55
|
+
- **Platform Support**: Windows, Linux, and macOS with platform-specific optimizations
|
|
56
|
+
- **UNC Path Support**: Optional integration with `unctools` for Windows UNC path handling
|
|
57
|
+
- **Metadata Preservation**: Preserve timestamps, permissions, and file attributes
|
|
58
|
+
|
|
59
|
+
## Why dazzle-filekit?
|
|
60
|
+
|
|
61
|
+
While Python's standard library (`shutil`, `pathlib`, `os`) provides basic file operations, dazzle-filekit offers:
|
|
62
|
+
|
|
63
|
+
- **Metadata Preservation**: Automatic preservation of timestamps, permissions, and extended attributes across platforms
|
|
64
|
+
- **Hash Verification**: Built-in file verification with multiple hash algorithms (MD5, SHA1, SHA256, SHA512)
|
|
65
|
+
- **Cross-Platform Path Handling**: Unified API for handling Windows UNC paths, network drives, and Unix paths
|
|
66
|
+
- **Batch Operations**: Process entire directory trees with pattern matching and filtering
|
|
67
|
+
- **Safe Operations**: Built-in conflict resolution, unique path generation, and error handling
|
|
68
|
+
- **Directory Comparison**: Compare directory contents and verify file integrity across locations
|
|
69
|
+
|
|
70
|
+
dazzle-filekit was designed for applications requiring reliable file operations with verification, such as backup tools, file synchronization, and data preservation systems (like the [preserve](https://github.com/djdarcy/preserve) project).
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install dazzle-filekit
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Optional Dependencies
|
|
79
|
+
|
|
80
|
+
For Windows UNC path support:
|
|
81
|
+
```bash
|
|
82
|
+
pip install dazzle-filekit[unctools]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
For development:
|
|
86
|
+
```bash
|
|
87
|
+
pip install dazzle-filekit[dev]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Quick Start
|
|
91
|
+
|
|
92
|
+
### Path Operations
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from dazzle_filekit import normalize_path, find_files, is_unc_path
|
|
96
|
+
|
|
97
|
+
# Normalize paths (returns Path object)
|
|
98
|
+
path = normalize_path("/some/path/../file.txt")
|
|
99
|
+
print(path) # PosixPath('/some/file.txt') or WindowsPath('C:/some/file.txt')
|
|
100
|
+
|
|
101
|
+
# Find files with patterns (returns list of path strings)
|
|
102
|
+
files = find_files("/directory", patterns=["*.py", "*.txt"])
|
|
103
|
+
|
|
104
|
+
# Check UNC paths
|
|
105
|
+
if is_unc_path(r"\\server\share"):
|
|
106
|
+
print("This is a UNC path")
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### File Operations
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from dazzle_filekit import copy_file, collect_file_metadata
|
|
113
|
+
|
|
114
|
+
# Copy file with metadata preservation
|
|
115
|
+
success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
|
|
116
|
+
|
|
117
|
+
# Collect file metadata
|
|
118
|
+
metadata = collect_file_metadata("file.txt")
|
|
119
|
+
print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### File Verification
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from dazzle_filekit import calculate_file_hash, verify_file_hash
|
|
126
|
+
|
|
127
|
+
# Calculate hash
|
|
128
|
+
hash_value = calculate_file_hash("file.txt", algorithm="sha256")
|
|
129
|
+
|
|
130
|
+
# Verify hash
|
|
131
|
+
is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## API Reference
|
|
135
|
+
|
|
136
|
+
### Path Functions
|
|
137
|
+
|
|
138
|
+
- `normalize_path(path)` - Normalize path to canonical form
|
|
139
|
+
- `is_same_file(path1, path2)` - Check if paths refer to same file
|
|
140
|
+
- `split_drive_letter(path)` - Split drive letter from path (Windows)
|
|
141
|
+
- `is_unc_path(path)` - Check if path is UNC format
|
|
142
|
+
- `get_relative_path(path, base)` - Get relative path from base
|
|
143
|
+
- `find_files(directory, patterns, exclude)` - Find files matching patterns
|
|
144
|
+
- `get_path_type(path)` - Detect path type (unc, network, subst, local)
|
|
145
|
+
|
|
146
|
+
### File Operations
|
|
147
|
+
|
|
148
|
+
- `copy_file(src, dst, preserve_metadata)` - Copy file with options
|
|
149
|
+
- `move_file(src, dst, preserve_metadata)` - Move file with options
|
|
150
|
+
- `collect_file_metadata(path)` - Collect file metadata
|
|
151
|
+
- `apply_file_metadata(path, metadata)` - Apply metadata to file
|
|
152
|
+
- `create_directory_structure(path)` - Create directory tree
|
|
153
|
+
- `remove_file(path)` - Remove file safely
|
|
154
|
+
- `remove_directory(path, recursive)` - Remove directory
|
|
155
|
+
|
|
156
|
+
### Verification Functions
|
|
157
|
+
|
|
158
|
+
- `calculate_file_hash(path, algorithm)` - Calculate file hash
|
|
159
|
+
- `verify_file_hash(path, expected_hash, algorithm)` - Verify hash
|
|
160
|
+
- `calculate_directory_hashes(directory, algorithm)` - Hash all files in directory
|
|
161
|
+
- `save_hashes_to_file(hashes, output_file)` - Save hashes to file
|
|
162
|
+
- `load_hashes_from_file(hash_file)` - Load hashes from file
|
|
163
|
+
- `compare_directories(dir1, dir2)` - Compare directory contents
|
|
164
|
+
- `verify_copied_files(src_dir, dst_dir)` - Verify copy operation
|
|
165
|
+
|
|
166
|
+
## Platform Support
|
|
167
|
+
|
|
168
|
+
### Windows
|
|
169
|
+
- Full UNC path support (with `unctools`)
|
|
170
|
+
- Network drive detection
|
|
171
|
+
- NTFS metadata preservation
|
|
172
|
+
- Long path support (>260 characters)
|
|
173
|
+
|
|
174
|
+
### Linux/Unix
|
|
175
|
+
- POSIX permissions preservation
|
|
176
|
+
- Symlink handling
|
|
177
|
+
- Extended attributes
|
|
178
|
+
|
|
179
|
+
### macOS
|
|
180
|
+
- HFS+ and APFS support
|
|
181
|
+
- Extended attributes
|
|
182
|
+
- Resource forks (where applicable)
|
|
183
|
+
|
|
184
|
+
## Configuration
|
|
185
|
+
|
|
186
|
+
### Logging
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from dazzle_filekit import configure_logging, enable_verbose_logging
|
|
190
|
+
import logging
|
|
191
|
+
|
|
192
|
+
# Configure logging level
|
|
193
|
+
configure_logging(level=logging.DEBUG, log_file="dazzle-filekit.log")
|
|
194
|
+
|
|
195
|
+
# Or enable verbose logging
|
|
196
|
+
enable_verbose_logging()
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Development
|
|
200
|
+
|
|
201
|
+
### Setup Development Environment
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
git clone https://github.com/DazzleLib/dazzle-filekit.git
|
|
205
|
+
cd dazzle-filekit/local
|
|
206
|
+
pip install -e ".[dev]"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Run Tests
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
pytest tests/ -v --cov=dazzle_filekit
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Code Formatting
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
black dazzle_filekit tests
|
|
219
|
+
flake8 dazzle_filekit tests
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Contributing
|
|
223
|
+
|
|
224
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
225
|
+
|
|
226
|
+
Like the project?
|
|
227
|
+
|
|
228
|
+
[](https://www.buymeacoffee.com/djdarcy)
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
233
|
+
|
|
234
|
+
## Part of DazzleLib
|
|
235
|
+
|
|
236
|
+
dazzle-filekit is part of the [DazzleLib](https://github.com/DazzleLib) ecosystem of Python file manipulation tools.
|
|
237
|
+
|
|
238
|
+
### Related Projects
|
|
239
|
+
|
|
240
|
+
- [UNCtools](https://github.com/DazzleLib/UNCtools) - Windows UNC path utilities
|
|
241
|
+
- [dazzle-tree-lib](https://github.com/DazzleLib/dazzle-tree-lib) - Tree structure utilities
|
|
242
|
+
- [preserve](https://github.com/djdarcy/preserve) - File preservation tool using dazzle-filekit
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# dazzle-filekit
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/dazzle-filekit)
|
|
4
|
+
[](https://pypi.org/project/dazzle-filekit/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**Cross-platform file operations toolkit with path handling, verification, and metadata preservation**
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Path Operations**: Cross-platform path handling, normalization, and manipulation
|
|
12
|
+
- **File Operations**: Copy, move, and manage files with metadata preservation
|
|
13
|
+
- **File Verification**: Calculate and verify file hashes (MD5, SHA1, SHA256, SHA512)
|
|
14
|
+
- **Platform Support**: Windows, Linux, and macOS with platform-specific optimizations
|
|
15
|
+
- **UNC Path Support**: Optional integration with `unctools` for Windows UNC path handling
|
|
16
|
+
- **Metadata Preservation**: Preserve timestamps, permissions, and file attributes
|
|
17
|
+
|
|
18
|
+
## Why dazzle-filekit?
|
|
19
|
+
|
|
20
|
+
While Python's standard library (`shutil`, `pathlib`, `os`) provides basic file operations, dazzle-filekit offers:
|
|
21
|
+
|
|
22
|
+
- **Metadata Preservation**: Automatic preservation of timestamps, permissions, and extended attributes across platforms
|
|
23
|
+
- **Hash Verification**: Built-in file verification with multiple hash algorithms (MD5, SHA1, SHA256, SHA512)
|
|
24
|
+
- **Cross-Platform Path Handling**: Unified API for handling Windows UNC paths, network drives, and Unix paths
|
|
25
|
+
- **Batch Operations**: Process entire directory trees with pattern matching and filtering
|
|
26
|
+
- **Safe Operations**: Built-in conflict resolution, unique path generation, and error handling
|
|
27
|
+
- **Directory Comparison**: Compare directory contents and verify file integrity across locations
|
|
28
|
+
|
|
29
|
+
dazzle-filekit was designed for applications requiring reliable file operations with verification, such as backup tools, file synchronization, and data preservation systems (like the [preserve](https://github.com/djdarcy/preserve) project).
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install dazzle-filekit
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Optional Dependencies
|
|
38
|
+
|
|
39
|
+
For Windows UNC path support:
|
|
40
|
+
```bash
|
|
41
|
+
pip install dazzle-filekit[unctools]
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For development:
|
|
45
|
+
```bash
|
|
46
|
+
pip install dazzle-filekit[dev]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
### Path Operations
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from dazzle_filekit import normalize_path, find_files, is_unc_path
|
|
55
|
+
|
|
56
|
+
# Normalize paths (returns Path object)
|
|
57
|
+
path = normalize_path("/some/path/../file.txt")
|
|
58
|
+
print(path) # PosixPath('/some/file.txt') or WindowsPath('C:/some/file.txt')
|
|
59
|
+
|
|
60
|
+
# Find files with patterns (returns list of path strings)
|
|
61
|
+
files = find_files("/directory", patterns=["*.py", "*.txt"])
|
|
62
|
+
|
|
63
|
+
# Check UNC paths
|
|
64
|
+
if is_unc_path(r"\\server\share"):
|
|
65
|
+
print("This is a UNC path")
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### File Operations
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from dazzle_filekit import copy_file, collect_file_metadata
|
|
72
|
+
|
|
73
|
+
# Copy file with metadata preservation
|
|
74
|
+
success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
|
|
75
|
+
|
|
76
|
+
# Collect file metadata
|
|
77
|
+
metadata = collect_file_metadata("file.txt")
|
|
78
|
+
print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### File Verification
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from dazzle_filekit import calculate_file_hash, verify_file_hash
|
|
85
|
+
|
|
86
|
+
# Calculate hash
|
|
87
|
+
hash_value = calculate_file_hash("file.txt", algorithm="sha256")
|
|
88
|
+
|
|
89
|
+
# Verify hash
|
|
90
|
+
is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
### Path Functions
|
|
96
|
+
|
|
97
|
+
- `normalize_path(path)` - Normalize path to canonical form
|
|
98
|
+
- `is_same_file(path1, path2)` - Check if paths refer to same file
|
|
99
|
+
- `split_drive_letter(path)` - Split drive letter from path (Windows)
|
|
100
|
+
- `is_unc_path(path)` - Check if path is UNC format
|
|
101
|
+
- `get_relative_path(path, base)` - Get relative path from base
|
|
102
|
+
- `find_files(directory, patterns, exclude)` - Find files matching patterns
|
|
103
|
+
- `get_path_type(path)` - Detect path type (unc, network, subst, local)
|
|
104
|
+
|
|
105
|
+
### File Operations
|
|
106
|
+
|
|
107
|
+
- `copy_file(src, dst, preserve_metadata)` - Copy file with options
|
|
108
|
+
- `move_file(src, dst, preserve_metadata)` - Move file with options
|
|
109
|
+
- `collect_file_metadata(path)` - Collect file metadata
|
|
110
|
+
- `apply_file_metadata(path, metadata)` - Apply metadata to file
|
|
111
|
+
- `create_directory_structure(path)` - Create directory tree
|
|
112
|
+
- `remove_file(path)` - Remove file safely
|
|
113
|
+
- `remove_directory(path, recursive)` - Remove directory
|
|
114
|
+
|
|
115
|
+
### Verification Functions
|
|
116
|
+
|
|
117
|
+
- `calculate_file_hash(path, algorithm)` - Calculate file hash
|
|
118
|
+
- `verify_file_hash(path, expected_hash, algorithm)` - Verify hash
|
|
119
|
+
- `calculate_directory_hashes(directory, algorithm)` - Hash all files in directory
|
|
120
|
+
- `save_hashes_to_file(hashes, output_file)` - Save hashes to file
|
|
121
|
+
- `load_hashes_from_file(hash_file)` - Load hashes from file
|
|
122
|
+
- `compare_directories(dir1, dir2)` - Compare directory contents
|
|
123
|
+
- `verify_copied_files(src_dir, dst_dir)` - Verify copy operation
|
|
124
|
+
|
|
125
|
+
## Platform Support
|
|
126
|
+
|
|
127
|
+
### Windows
|
|
128
|
+
- Full UNC path support (with `unctools`)
|
|
129
|
+
- Network drive detection
|
|
130
|
+
- NTFS metadata preservation
|
|
131
|
+
- Long path support (>260 characters)
|
|
132
|
+
|
|
133
|
+
### Linux/Unix
|
|
134
|
+
- POSIX permissions preservation
|
|
135
|
+
- Symlink handling
|
|
136
|
+
- Extended attributes
|
|
137
|
+
|
|
138
|
+
### macOS
|
|
139
|
+
- HFS+ and APFS support
|
|
140
|
+
- Extended attributes
|
|
141
|
+
- Resource forks (where applicable)
|
|
142
|
+
|
|
143
|
+
## Configuration
|
|
144
|
+
|
|
145
|
+
### Logging
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from dazzle_filekit import configure_logging, enable_verbose_logging
|
|
149
|
+
import logging
|
|
150
|
+
|
|
151
|
+
# Configure logging level
|
|
152
|
+
configure_logging(level=logging.DEBUG, log_file="dazzle-filekit.log")
|
|
153
|
+
|
|
154
|
+
# Or enable verbose logging
|
|
155
|
+
enable_verbose_logging()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Development
|
|
159
|
+
|
|
160
|
+
### Setup Development Environment
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
git clone https://github.com/DazzleLib/dazzle-filekit.git
|
|
164
|
+
cd dazzle-filekit/local
|
|
165
|
+
pip install -e ".[dev]"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Run Tests
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
pytest tests/ -v --cov=dazzle_filekit
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Code Formatting
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
black dazzle_filekit tests
|
|
178
|
+
flake8 dazzle_filekit tests
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Contributing
|
|
182
|
+
|
|
183
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
184
|
+
|
|
185
|
+
Like the project?
|
|
186
|
+
|
|
187
|
+
[](https://www.buymeacoffee.com/djdarcy)
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
192
|
+
|
|
193
|
+
## Part of DazzleLib
|
|
194
|
+
|
|
195
|
+
dazzle-filekit is part of the [DazzleLib](https://github.com/DazzleLib) ecosystem of Python file manipulation tools.
|
|
196
|
+
|
|
197
|
+
### Related Projects
|
|
198
|
+
|
|
199
|
+
- [UNCtools](https://github.com/DazzleLib/UNCtools) - Windows UNC path utilities
|
|
200
|
+
- [dazzle-tree-lib](https://github.com/DazzleLib/dazzle-tree-lib) - Tree structure utilities
|
|
201
|
+
- [preserve](https://github.com/djdarcy/preserve) - File preservation tool using dazzle-filekit
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""
|
|
2
|
+
dazzle_filekit - A general-purpose file manipulation library.
|
|
3
|
+
|
|
4
|
+
This package provides utilities for file operations, path handling, and verification
|
|
5
|
+
across different platforms, with a focus on preserving file metadata.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
import logging
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
# Setup package-level logging
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
logger.setLevel(logging.INFO)
|
|
16
|
+
|
|
17
|
+
# Create console handler if not already present
|
|
18
|
+
if not logger.handlers:
|
|
19
|
+
console_handler = logging.StreamHandler()
|
|
20
|
+
console_handler.setFormatter(
|
|
21
|
+
logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
22
|
+
)
|
|
23
|
+
logger.addHandler(console_handler)
|
|
24
|
+
|
|
25
|
+
# Import core functionality
|
|
26
|
+
from .paths import (
|
|
27
|
+
normalize_path,
|
|
28
|
+
is_same_file,
|
|
29
|
+
split_drive_letter,
|
|
30
|
+
is_unc_path,
|
|
31
|
+
get_relative_path,
|
|
32
|
+
create_dest_path,
|
|
33
|
+
find_files,
|
|
34
|
+
find_regex_files,
|
|
35
|
+
collect_files_from_include_file,
|
|
36
|
+
create_parent_dirs,
|
|
37
|
+
ensure_unique_path,
|
|
38
|
+
get_path_type
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
from .operations import (
|
|
42
|
+
copy_file,
|
|
43
|
+
move_file,
|
|
44
|
+
collect_file_metadata,
|
|
45
|
+
apply_file_metadata,
|
|
46
|
+
copy_files_with_path,
|
|
47
|
+
move_files_with_path,
|
|
48
|
+
create_directory_structure,
|
|
49
|
+
remove_file,
|
|
50
|
+
remove_directory
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
from .verification import (
|
|
54
|
+
calculate_file_hash,
|
|
55
|
+
verify_file_hash,
|
|
56
|
+
verify_files_with_manifest,
|
|
57
|
+
calculate_directory_hashes,
|
|
58
|
+
save_hashes_to_file,
|
|
59
|
+
load_hashes_from_file,
|
|
60
|
+
compare_directories,
|
|
61
|
+
verify_copied_files
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
__version__ = '0.1.0'
|
|
65
|
+
|
|
66
|
+
def configure_logging(level=logging.INFO, log_file=None):
|
|
67
|
+
"""
|
|
68
|
+
Configure logging for dazzle_filekit.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
level: Logging level
|
|
72
|
+
log_file: Optional path to log file
|
|
73
|
+
"""
|
|
74
|
+
logger.setLevel(level)
|
|
75
|
+
|
|
76
|
+
# Clear existing handlers
|
|
77
|
+
for handler in logger.handlers[:]:
|
|
78
|
+
logger.removeHandler(handler)
|
|
79
|
+
|
|
80
|
+
# Add console handler
|
|
81
|
+
console_handler = logging.StreamHandler()
|
|
82
|
+
console_handler.setFormatter(
|
|
83
|
+
logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
84
|
+
)
|
|
85
|
+
logger.addHandler(console_handler)
|
|
86
|
+
|
|
87
|
+
# Add file handler if specified
|
|
88
|
+
if log_file:
|
|
89
|
+
file_handler = logging.FileHandler(log_file)
|
|
90
|
+
file_handler.setFormatter(
|
|
91
|
+
logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
92
|
+
)
|
|
93
|
+
logger.addHandler(file_handler)
|
|
94
|
+
|
|
95
|
+
logger.debug(f"Logging configured with level {level}")
|
|
96
|
+
|
|
97
|
+
def enable_verbose_logging():
|
|
98
|
+
"""Enable verbose (debug) logging."""
|
|
99
|
+
configure_logging(logging.DEBUG)
|
|
100
|
+
|
|
101
|
+
# Platform-specific functions can be imported conditionally
|
|
102
|
+
if sys.platform == 'win32':
|
|
103
|
+
pass
|
|
104
|
+
# Windows-specific functions
|
|
105
|
+
# try:
|
|
106
|
+
# from .platform.windows import (
|
|
107
|
+
# Import Windows-specific functions when implemented
|
|
108
|
+
# )
|
|
109
|
+
# except ImportError:
|
|
110
|
+
# logger.debug("Windows-specific functions not available")
|
|
111
|
+
else:
|
|
112
|
+
pass
|
|
113
|
+
# Unix-specific functions
|
|
114
|
+
# try:
|
|
115
|
+
# from .platform.unix import (
|
|
116
|
+
# Import Unix-specific functions when implemented
|
|
117
|
+
# )
|
|
118
|
+
# except ImportError:
|
|
119
|
+
# logger.debug("Unix-specific functions not available")
|
|
120
|
+
|
|
121
|
+
# __all__ defines the public API
|
|
122
|
+
__all__ = [
|
|
123
|
+
# Version
|
|
124
|
+
'__version__',
|
|
125
|
+
|
|
126
|
+
# Logging functions
|
|
127
|
+
'configure_logging',
|
|
128
|
+
'enable_verbose_logging',
|
|
129
|
+
|
|
130
|
+
# Path functions
|
|
131
|
+
'normalize_path',
|
|
132
|
+
'is_same_file',
|
|
133
|
+
'split_drive_letter',
|
|
134
|
+
'is_unc_path',
|
|
135
|
+
'get_relative_path',
|
|
136
|
+
'create_dest_path',
|
|
137
|
+
'find_files',
|
|
138
|
+
'find_regex_files',
|
|
139
|
+
'collect_files_from_include_file',
|
|
140
|
+
'create_parent_dirs',
|
|
141
|
+
'ensure_unique_path',
|
|
142
|
+
'get_path_type',
|
|
143
|
+
|
|
144
|
+
# Operation functions
|
|
145
|
+
'copy_file',
|
|
146
|
+
'move_file',
|
|
147
|
+
'collect_file_metadata',
|
|
148
|
+
'apply_file_metadata',
|
|
149
|
+
'copy_files_with_path',
|
|
150
|
+
'move_files_with_path',
|
|
151
|
+
'create_directory_structure',
|
|
152
|
+
'remove_file',
|
|
153
|
+
'remove_directory',
|
|
154
|
+
|
|
155
|
+
# Verification functions
|
|
156
|
+
'calculate_file_hash',
|
|
157
|
+
'verify_file_hash',
|
|
158
|
+
'verify_files_with_manifest',
|
|
159
|
+
'calculate_directory_hashes',
|
|
160
|
+
'save_hashes_to_file',
|
|
161
|
+
'load_hashes_from_file',
|
|
162
|
+
'compare_directories',
|
|
163
|
+
'verify_copied_files'
|
|
164
|
+
]
|