dazzle-filekit 0.2.0__tar.gz → 0.2.1__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.2.0 → dazzle_filekit-0.2.1}/PKG-INFO +10 -3
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/README.md +9 -2
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/__init__.py +4 -2
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/operations.py +141 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit.egg-info/PKG-INFO +10 -3
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit.egg-info/SOURCES.txt +1 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/pyproject.toml +1 -1
- dazzle_filekit-0.2.1/tests/test_auto_naming.py +115 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/LICENSE +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/paths.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/platform/__init__.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/platform/unix.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/platform/windows.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/utils/__init__.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/utils/compat.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/utils/disk.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/utils/logger.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/utils/validation.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit/verification.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit.egg-info/dependency_links.txt +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit.egg-info/requires.txt +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/dazzle_filekit.egg-info/top_level.txt +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/setup.cfg +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/setup.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/tests/test_compat.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/tests/test_disk.py +0 -0
- {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.1}/tests/test_smoke.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dazzle-filekit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Cross-platform file operations toolkit with path handling, verification, and metadata preservation
|
|
5
5
|
Author: Dustin
|
|
6
6
|
Author-email: Dustin Darcy <6962246+djdarcy@users.noreply.github.com>
|
|
@@ -41,7 +41,7 @@ Dynamic: requires-python
|
|
|
41
41
|
|
|
42
42
|
# dazzle-filekit
|
|
43
43
|
|
|
44
|
-
[](https://pypi.org/project/dazzle-filekit/)
|
|
45
45
|
[](https://www.python.org/downloads/)
|
|
46
46
|
[](https://opensource.org/licenses/MIT)
|
|
47
47
|
[](docs/platform-support.md)
|
|
@@ -129,7 +129,7 @@ if is_unc_path(r"\\server\share"):
|
|
|
129
129
|
### File Operations
|
|
130
130
|
|
|
131
131
|
```python
|
|
132
|
-
from dazzle_filekit import copy_file, collect_file_metadata
|
|
132
|
+
from dazzle_filekit import copy_file, collect_file_metadata, create_symlink
|
|
133
133
|
|
|
134
134
|
# Copy file with metadata preservation
|
|
135
135
|
success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
|
|
@@ -137,6 +137,12 @@ success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
|
|
|
137
137
|
# Collect file metadata
|
|
138
138
|
metadata = collect_file_metadata("file.txt")
|
|
139
139
|
print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")
|
|
140
|
+
|
|
141
|
+
# Create symbolic link (cross-platform)
|
|
142
|
+
success = create_symlink("/path/to/target", "/path/to/link")
|
|
143
|
+
|
|
144
|
+
# Force replace existing link
|
|
145
|
+
success = create_symlink("/new/target", "/path/to/link", force=True)
|
|
140
146
|
```
|
|
141
147
|
|
|
142
148
|
### Disk Space Checking
|
|
@@ -201,6 +207,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
|
|
|
201
207
|
- `create_directory_structure(path)` - Create directory tree
|
|
202
208
|
- `remove_file(path)` - Remove file safely
|
|
203
209
|
- `remove_directory(path, recursive)` - Remove directory
|
|
210
|
+
- `create_symlink(target, link, force)` - Create symbolic link with cross-platform support
|
|
204
211
|
|
|
205
212
|
### Disk Space Functions
|
|
206
213
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dazzle-filekit
|
|
2
2
|
|
|
3
|
-
[](https://pypi.org/project/dazzle-filekit/)
|
|
4
4
|
[](https://www.python.org/downloads/)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](docs/platform-support.md)
|
|
@@ -88,7 +88,7 @@ if is_unc_path(r"\\server\share"):
|
|
|
88
88
|
### File Operations
|
|
89
89
|
|
|
90
90
|
```python
|
|
91
|
-
from dazzle_filekit import copy_file, collect_file_metadata
|
|
91
|
+
from dazzle_filekit import copy_file, collect_file_metadata, create_symlink
|
|
92
92
|
|
|
93
93
|
# Copy file with metadata preservation
|
|
94
94
|
success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
|
|
@@ -96,6 +96,12 @@ success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
|
|
|
96
96
|
# Collect file metadata
|
|
97
97
|
metadata = collect_file_metadata("file.txt")
|
|
98
98
|
print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")
|
|
99
|
+
|
|
100
|
+
# Create symbolic link (cross-platform)
|
|
101
|
+
success = create_symlink("/path/to/target", "/path/to/link")
|
|
102
|
+
|
|
103
|
+
# Force replace existing link
|
|
104
|
+
success = create_symlink("/new/target", "/path/to/link", force=True)
|
|
99
105
|
```
|
|
100
106
|
|
|
101
107
|
### Disk Space Checking
|
|
@@ -160,6 +166,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
|
|
|
160
166
|
- `create_directory_structure(path)` - Create directory tree
|
|
161
167
|
- `remove_file(path)` - Remove file safely
|
|
162
168
|
- `remove_directory(path, recursive)` - Remove directory
|
|
169
|
+
- `create_symlink(target, link, force)` - Create symbolic link with cross-platform support
|
|
163
170
|
|
|
164
171
|
### Disk Space Functions
|
|
165
172
|
|
|
@@ -63,7 +63,8 @@ from .operations import (
|
|
|
63
63
|
move_files_with_path,
|
|
64
64
|
create_directory_structure,
|
|
65
65
|
remove_file,
|
|
66
|
-
remove_directory
|
|
66
|
+
remove_directory,
|
|
67
|
+
create_symlink
|
|
67
68
|
)
|
|
68
69
|
|
|
69
70
|
from .verification import (
|
|
@@ -77,7 +78,7 @@ from .verification import (
|
|
|
77
78
|
verify_copied_files
|
|
78
79
|
)
|
|
79
80
|
|
|
80
|
-
__version__ = '0.2.
|
|
81
|
+
__version__ = '0.2.1'
|
|
81
82
|
|
|
82
83
|
def configure_logging(level=logging.INFO, log_file=None):
|
|
83
84
|
"""
|
|
@@ -181,6 +182,7 @@ __all__ = [
|
|
|
181
182
|
'create_directory_structure',
|
|
182
183
|
'remove_file',
|
|
183
184
|
'remove_directory',
|
|
185
|
+
'create_symlink',
|
|
184
186
|
|
|
185
187
|
# Verification functions
|
|
186
188
|
'calculate_file_hash',
|
|
@@ -668,3 +668,144 @@ def remove_directory(path: Union[str, Path], recursive: bool = False, force: boo
|
|
|
668
668
|
else:
|
|
669
669
|
logger.error(f"Error removing directory {path}: {e}")
|
|
670
670
|
return False
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
def create_symlink(
|
|
674
|
+
target: Union[str, Path],
|
|
675
|
+
link: Union[str, Path],
|
|
676
|
+
force: bool = False,
|
|
677
|
+
target_is_directory: Optional[bool] = None
|
|
678
|
+
) -> bool:
|
|
679
|
+
"""
|
|
680
|
+
Create a symbolic link with cross-platform handling.
|
|
681
|
+
|
|
682
|
+
On Unix systems, uses os.symlink directly.
|
|
683
|
+
On Windows, attempts multiple methods:
|
|
684
|
+
1. os.symlink (requires Developer Mode or admin on Windows 10+)
|
|
685
|
+
2. dazzlelink library if available (handles elevation gracefully)
|
|
686
|
+
3. mklink command as fallback
|
|
687
|
+
|
|
688
|
+
Args:
|
|
689
|
+
target: The target path the symlink will point to
|
|
690
|
+
link: The path where the symlink will be created
|
|
691
|
+
force: If True, remove existing file/symlink at link path first
|
|
692
|
+
target_is_directory: Whether target is a directory (auto-detected if None)
|
|
693
|
+
|
|
694
|
+
Returns:
|
|
695
|
+
True if symlink was created successfully, False otherwise
|
|
696
|
+
|
|
697
|
+
Example:
|
|
698
|
+
>>> create_symlink('/path/to/file.txt', '/path/to/link.txt')
|
|
699
|
+
True
|
|
700
|
+
>>> create_symlink('C:\\data\\folder', 'C:\\links\\folder_link', target_is_directory=True)
|
|
701
|
+
True
|
|
702
|
+
"""
|
|
703
|
+
target_path = Path(target)
|
|
704
|
+
link_path = Path(link)
|
|
705
|
+
|
|
706
|
+
# Handle existing link
|
|
707
|
+
if link_path.exists() or link_path.is_symlink():
|
|
708
|
+
if not force:
|
|
709
|
+
logger.warning(f"Link path already exists: {link_path}")
|
|
710
|
+
return False
|
|
711
|
+
try:
|
|
712
|
+
if link_path.is_dir() and not link_path.is_symlink():
|
|
713
|
+
shutil.rmtree(link_path)
|
|
714
|
+
else:
|
|
715
|
+
link_path.unlink()
|
|
716
|
+
logger.debug(f"Removed existing path: {link_path}")
|
|
717
|
+
except Exception as e:
|
|
718
|
+
logger.error(f"Failed to remove existing path {link_path}: {e}")
|
|
719
|
+
return False
|
|
720
|
+
|
|
721
|
+
# Create parent directories if needed
|
|
722
|
+
try:
|
|
723
|
+
link_path.parent.mkdir(parents=True, exist_ok=True)
|
|
724
|
+
except Exception as e:
|
|
725
|
+
logger.error(f"Failed to create parent directories for {link_path}: {e}")
|
|
726
|
+
return False
|
|
727
|
+
|
|
728
|
+
# Auto-detect if target is a directory
|
|
729
|
+
if target_is_directory is None:
|
|
730
|
+
target_is_directory = target_path.is_dir()
|
|
731
|
+
|
|
732
|
+
# Try to create symlink
|
|
733
|
+
if platform.system() != 'Windows':
|
|
734
|
+
# Unix: straightforward symlink
|
|
735
|
+
try:
|
|
736
|
+
os.symlink(target_path, link_path)
|
|
737
|
+
logger.debug(f"Created symlink: {link_path} -> {target_path}")
|
|
738
|
+
return True
|
|
739
|
+
except Exception as e:
|
|
740
|
+
logger.error(f"Failed to create symlink on Unix: {e}")
|
|
741
|
+
return False
|
|
742
|
+
|
|
743
|
+
# Windows: try multiple methods
|
|
744
|
+
return _create_windows_symlink(target_path, link_path, target_is_directory)
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def _create_windows_symlink(target: Path, link: Path, is_directory: bool) -> bool:
|
|
748
|
+
"""
|
|
749
|
+
Create a symbolic link on Windows using multiple fallback methods.
|
|
750
|
+
|
|
751
|
+
Args:
|
|
752
|
+
target: Target path
|
|
753
|
+
link: Link path to create
|
|
754
|
+
is_directory: Whether target is a directory
|
|
755
|
+
|
|
756
|
+
Returns:
|
|
757
|
+
True if successful, False otherwise
|
|
758
|
+
"""
|
|
759
|
+
# Method 1: Try os.symlink (works with Developer Mode enabled)
|
|
760
|
+
try:
|
|
761
|
+
os.symlink(target, link, target_is_directory=is_directory)
|
|
762
|
+
logger.debug(f"Created Windows symlink using os.symlink: {link} -> {target}")
|
|
763
|
+
return True
|
|
764
|
+
except OSError as e:
|
|
765
|
+
# Error 1314 = "A required privilege is not held by the client"
|
|
766
|
+
if getattr(e, 'winerror', 0) == 1314:
|
|
767
|
+
logger.debug("os.symlink failed (Developer Mode not enabled), trying alternatives")
|
|
768
|
+
else:
|
|
769
|
+
logger.warning(f"os.symlink failed: {e}")
|
|
770
|
+
|
|
771
|
+
# Method 2: Try dazzlelink if available
|
|
772
|
+
try:
|
|
773
|
+
from dazzlelink.operations import create_windows_symlink as dazzle_create_symlink
|
|
774
|
+
result = dazzle_create_symlink(str(target), str(link), is_directory)
|
|
775
|
+
if result:
|
|
776
|
+
logger.debug(f"Created Windows symlink using dazzlelink: {link} -> {target}")
|
|
777
|
+
return True
|
|
778
|
+
except ImportError:
|
|
779
|
+
logger.debug("dazzlelink not available, trying mklink fallback")
|
|
780
|
+
except Exception as e:
|
|
781
|
+
logger.warning(f"dazzlelink symlink creation failed: {e}")
|
|
782
|
+
|
|
783
|
+
# Method 3: Try mklink command (may require elevation)
|
|
784
|
+
try:
|
|
785
|
+
import subprocess
|
|
786
|
+
dir_flag = '/D ' if is_directory else ''
|
|
787
|
+
cmd = f'mklink {dir_flag}"{link}" "{target}"'
|
|
788
|
+
|
|
789
|
+
result = subprocess.run(
|
|
790
|
+
['cmd', '/c', cmd],
|
|
791
|
+
text=True,
|
|
792
|
+
capture_output=True,
|
|
793
|
+
check=False
|
|
794
|
+
)
|
|
795
|
+
|
|
796
|
+
if result.returncode == 0:
|
|
797
|
+
logger.debug(f"Created Windows symlink using mklink: {link} -> {target}")
|
|
798
|
+
return True
|
|
799
|
+
else:
|
|
800
|
+
logger.warning(f"mklink failed: {result.stderr.strip()}")
|
|
801
|
+
except Exception as e:
|
|
802
|
+
logger.warning(f"mklink command failed: {e}")
|
|
803
|
+
|
|
804
|
+
# All methods failed
|
|
805
|
+
logger.error(
|
|
806
|
+
f"Failed to create symlink on Windows. This typically requires either:\n"
|
|
807
|
+
f" 1. Developer Mode enabled (Settings > Update & Security > For developers)\n"
|
|
808
|
+
f" 2. Running as Administrator\n"
|
|
809
|
+
f" 3. Install dazzlelink: pip install dazzlelink"
|
|
810
|
+
)
|
|
811
|
+
return False
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dazzle-filekit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Cross-platform file operations toolkit with path handling, verification, and metadata preservation
|
|
5
5
|
Author: Dustin
|
|
6
6
|
Author-email: Dustin Darcy <6962246+djdarcy@users.noreply.github.com>
|
|
@@ -41,7 +41,7 @@ Dynamic: requires-python
|
|
|
41
41
|
|
|
42
42
|
# dazzle-filekit
|
|
43
43
|
|
|
44
|
-
[](https://pypi.org/project/dazzle-filekit/)
|
|
45
45
|
[](https://www.python.org/downloads/)
|
|
46
46
|
[](https://opensource.org/licenses/MIT)
|
|
47
47
|
[](docs/platform-support.md)
|
|
@@ -129,7 +129,7 @@ if is_unc_path(r"\\server\share"):
|
|
|
129
129
|
### File Operations
|
|
130
130
|
|
|
131
131
|
```python
|
|
132
|
-
from dazzle_filekit import copy_file, collect_file_metadata
|
|
132
|
+
from dazzle_filekit import copy_file, collect_file_metadata, create_symlink
|
|
133
133
|
|
|
134
134
|
# Copy file with metadata preservation
|
|
135
135
|
success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
|
|
@@ -137,6 +137,12 @@ success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
|
|
|
137
137
|
# Collect file metadata
|
|
138
138
|
metadata = collect_file_metadata("file.txt")
|
|
139
139
|
print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")
|
|
140
|
+
|
|
141
|
+
# Create symbolic link (cross-platform)
|
|
142
|
+
success = create_symlink("/path/to/target", "/path/to/link")
|
|
143
|
+
|
|
144
|
+
# Force replace existing link
|
|
145
|
+
success = create_symlink("/new/target", "/path/to/link", force=True)
|
|
140
146
|
```
|
|
141
147
|
|
|
142
148
|
### Disk Space Checking
|
|
@@ -201,6 +207,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
|
|
|
201
207
|
- `create_directory_structure(path)` - Create directory tree
|
|
202
208
|
- `remove_file(path)` - Remove file safely
|
|
203
209
|
- `remove_directory(path, recursive)` - Remove directory
|
|
210
|
+
- `create_symlink(target, link, force)` - Create symbolic link with cross-platform support
|
|
204
211
|
|
|
205
212
|
### Disk Space Functions
|
|
206
213
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "dazzle-filekit"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Cross-platform file operations toolkit with path handling, verification, and metadata preservation"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Test the auto-naming logic."""
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
# Mock the dependencies
|
|
5
|
+
class MockPath:
|
|
6
|
+
def __init__(self, path_str):
|
|
7
|
+
self._path = path_str.replace('\\', '/')
|
|
8
|
+
self._parts = tuple(p for p in self._path.split('/') if p)
|
|
9
|
+
|
|
10
|
+
@property
|
|
11
|
+
def name(self):
|
|
12
|
+
return self._parts[-1] if self._parts else ''
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def parts(self):
|
|
16
|
+
return self._parts
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def parent(self):
|
|
20
|
+
if len(self._parts) <= 1:
|
|
21
|
+
return self
|
|
22
|
+
return MockPath('/'.join(self._parts[:-1]))
|
|
23
|
+
|
|
24
|
+
def __eq__(self, other):
|
|
25
|
+
return self._path == other._path if isinstance(other, MockPath) else False
|
|
26
|
+
|
|
27
|
+
def __str__(self):
|
|
28
|
+
return self._path
|
|
29
|
+
|
|
30
|
+
def normalize_cross_platform_path(p):
|
|
31
|
+
return MockPath(p)
|
|
32
|
+
|
|
33
|
+
def debug_log(msg):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
GENERIC_FOLDER_NAMES = {
|
|
37
|
+
'home', 'user', 'users', 'code', 'projects', 'project', 'work',
|
|
38
|
+
'dev', 'development', 'src', 'source', 'app', 'apps', 'local',
|
|
39
|
+
'current', 'main', 'master', 'opt', 'var', 'tmp', 'temp',
|
|
40
|
+
'desktop', 'documents', 'downloads', 'repos', 'repository',
|
|
41
|
+
'github', 'gitlab', 'bitbucket', 'workspace', 'workspaces',
|
|
42
|
+
}
|
|
43
|
+
DRIVE_LETTERS = {'c', 'd', 'e', 'f', 'g', 'h', 'z'}
|
|
44
|
+
|
|
45
|
+
def _sanitize_folder_name(name):
|
|
46
|
+
sanitized = re.sub(r'[^a-zA-Z0-9_-]', '-', name.lower())
|
|
47
|
+
sanitized = re.sub(r'-+', '-', sanitized)
|
|
48
|
+
return sanitized.strip('-')
|
|
49
|
+
|
|
50
|
+
def derive_session_name_from_cwd(cwd):
|
|
51
|
+
"""Strategy: non-generic folder -> use it; otherwise -> path from nearest non-generic ancestor (with drive letter)"""
|
|
52
|
+
if not cwd:
|
|
53
|
+
return None
|
|
54
|
+
path = normalize_cross_platform_path(cwd)
|
|
55
|
+
|
|
56
|
+
# Use path.parts to get all components including drive letter
|
|
57
|
+
try:
|
|
58
|
+
all_parts = path.parts
|
|
59
|
+
except AttributeError:
|
|
60
|
+
path_str = str(path).replace('\\', '/')
|
|
61
|
+
all_parts = [p for p in path_str.split('/') if p]
|
|
62
|
+
|
|
63
|
+
# Collect last 4 meaningful parts with metadata
|
|
64
|
+
parts = [] # (sanitized, raw, is_drive)
|
|
65
|
+
for part in all_parts[-4:]:
|
|
66
|
+
raw = part.rstrip(':\\/')
|
|
67
|
+
sanitized = _sanitize_folder_name(raw)
|
|
68
|
+
if sanitized:
|
|
69
|
+
is_drive = sanitized in DRIVE_LETTERS
|
|
70
|
+
parts.append((sanitized, raw.lower(), is_drive))
|
|
71
|
+
|
|
72
|
+
if not parts:
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
# Strategy 1: Non-generic current folder (not drive) -> use it alone
|
|
76
|
+
current_name, current_raw, current_is_drive = parts[-1]
|
|
77
|
+
if current_raw not in GENERIC_FOLDER_NAMES and not current_is_drive and len(current_name) >= 3:
|
|
78
|
+
return current_name[:50]
|
|
79
|
+
|
|
80
|
+
# Strategy 2: Find nearest non-generic ancestor (not drive), use path from there
|
|
81
|
+
start_idx = 0
|
|
82
|
+
for i in range(len(parts) - 2, -1, -1):
|
|
83
|
+
_, raw, is_drive = parts[i]
|
|
84
|
+
if raw not in GENERIC_FOLDER_NAMES and not is_drive:
|
|
85
|
+
start_idx = i
|
|
86
|
+
break
|
|
87
|
+
|
|
88
|
+
path_parts = [s for s, r, d in parts[start_idx:] if len(s) >= 1]
|
|
89
|
+
if path_parts:
|
|
90
|
+
path_name = '--'.join(path_parts)
|
|
91
|
+
if len(path_name) > 50:
|
|
92
|
+
path_name = path_name[:50].rsplit('--', 1)[0]
|
|
93
|
+
return path_name
|
|
94
|
+
return None
|
|
95
|
+
|
|
96
|
+
if __name__ == '__main__':
|
|
97
|
+
# Test cases - (path, expected_name)
|
|
98
|
+
test_cases = [
|
|
99
|
+
(r'C:\code\claude-code-task-manager', 'claude-code-task-manager'), # Non-generic folder
|
|
100
|
+
(r'C:\code', 'c--code'), # Generic + drive -> include drive
|
|
101
|
+
(r'C:\code\local', 'c--code--local'), # All generic -> include drive
|
|
102
|
+
(r'C:\code\my-project\local', 'my-project--local'), # Has non-generic parent
|
|
103
|
+
(r'C:\Users\Extreme\Documents', 'extreme--documents'), # Has non-generic parent
|
|
104
|
+
('/home/dev/projects/my-app', 'my-app'), # Non-generic folder
|
|
105
|
+
('/opt/STAGING/current', 'staging--current'), # Has non-generic parent
|
|
106
|
+
(r'Z:\code\project', 'z--code--project'), # All generic on Z drive
|
|
107
|
+
(r'Z:\code', 'z--code'), # Generic on Z drive
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
print("Path -> Auto-generated Name")
|
|
111
|
+
print("-" * 70)
|
|
112
|
+
for path, expected in test_cases:
|
|
113
|
+
result = derive_session_name_from_cwd(path)
|
|
114
|
+
status = "OK" if result == expected else f"FAIL (expected: {expected})"
|
|
115
|
+
print(f'{path:45} -> {result:20} {status}')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|