A Python package for UNC path operations
Project description
uncpath-py
A Python package for UNC (Universal Naming Convention) path operations, supporting one-click conversion of Windows/SMB UNC paths to Linux local mount paths.
โจ Features
๐ UNC Path Parsing
- Multi-format Support: Windows UNC (
\\host\share\path), Unix UNC (//host/share/path), SMB protocol (smb://host/share/path) - Smart Parsing: Automatically identify path formats and extract host, share, and path information
- Normalization: Convert to standard format
โ๏ธ Configuration Management
- YAML Support: Use PyYAML to handle configuration files
- Auto Configuration: Automatically create default configuration files on first use
- Mapping Management: Support adding, deleting, and listing mapping relationships
- Configuration Validation: Automatically validate configuration file formats
๐บ๏ธ Path Mapping
- Exact Mapping: Direct mapping from host/share to local paths
- Wildcard Mapping: Support
*wildcards and{host},{share}placeholders - Default Mapping: Use default rules when no mapping is found
- Smart Lookup: Find mapping relationships by priority
๐ป Command Line Tool
- uncd Command: Complete command line interface
- Path Conversion: Direct directory switching or path output
- Configuration Management: Command line configuration of mapping relationships
- Help Information: Complete help and version information
๐ฆ Installation
pip install uncpath-py
๐ Quick Start
1. Initialize Configuration
# Create default configuration file
uncd --init-config
2. Add Mapping Relationships
# Add exact mapping
uncd --add-mapping "192.168.10.172/sambaShare" "/opt/samba"
# Add wildcard mapping
uncd --add-mapping "192.168.*/samba*" "/mnt/smb/{host}/{share}"
3. Use Path Conversion
# Switch to mapped directory
uncd \\192.168.10.172\sambaShare\folder
# Output path only, don't switch directory
uncd --path-only \\192.168.10.172\sambaShare\folder
# Output: /opt/samba\folder
๐ Detailed Usage
Command Line Usage
# Basic usage
uncd <UNC_PATH> # Switch to mapped directory
uncd --path-only <UNC_PATH> # Output path only
# Configuration management
uncd --init-config # Create default configuration file
uncd --list-mappings # List all mapping relationships
uncd --add-mapping KEY VALUE # Add mapping relationship
uncd --remove-mapping KEY # Remove mapping relationship
uncd --validate-config # Validate configuration file
# Help information
uncd --help # Show help information
uncd --version # Show version information
Python API Usage
Basic Functions
from uncpath import is_unc_path, normalize_unc_path
# Check if path is UNC path
is_unc_path(r"\\server\share\file.txt") # True
is_unc_path("//server/share/file.txt") # True
is_unc_path("smb://server/share/file.txt") # True
is_unc_path("C:\\Users\\file.txt") # False
# Normalize UNC path
normalize_unc_path(r"\\server\share\folder\file.txt")
# Returns: "//server/share/folder/file.txt"
Advanced Functions
from uncpath import UNCResolver, ConfigManager, PathMapper
# UNC path parsing
resolver = UNCResolver()
parsed = resolver.parse_unc_path(r"\\192.168.10.172\sambaShare\folder")
print(f"Host: {parsed.host}") # 192.168.10.172
print(f"Share: {parsed.share}") # sambaShare
print(f"Path: {parsed.path}") # \folder
print(f"Protocol: {parsed.protocol}") # windows
# Configuration management
config_manager = ConfigManager()
config_manager.add_mapping("192.168.10.172/sambaShare", "/opt/samba")
# Path mapping
mapper = PathMapper(config_manager)
local_path = mapper.map_to_local(parsed)
print(f"Local path: {local_path}") # /opt/samba\folder
Convenience Functions
from uncpath import resolve_unc_path
# One-step parsing and mapping
local_path = resolve_unc_path(r"\\192.168.10.172\sambaShare\folder")
print(local_path) # /opt/samba\folder
Configuration File Format
Configuration file location: ~/.config/uncpath/config.yaml
version: "1.0"
# Path mapping relationships
mappings:
# Exact mapping
"192.168.10.172/sambaShare": "/opt/samba"
"server1/shared": "/mnt/smb/server1"
# Wildcard mapping
"192.168.*/samba*": "/mnt/smb/{host}/{share}"
"*/shared": "/mnt/shared/{host}"
# Default settings
defaults:
base_path: "/mnt/smb"
auto_create: false
create_mode: "0755"
# Alias settings
aliases:
"samba": "192.168.10.172/sambaShare"
"docs": "server1/shared"
๐ง Supported Path Formats
Windows UNC Format
uncd \\192.168.10.172\sambaShare\folder\file.txt
uncd \\server\share\path
Unix UNC Format
uncd //192.168.10.172/sambaShare/folder/file.txt
uncd //server/share/path
SMB Protocol Format
uncd smb://192.168.10.172/sambaShare/folder/file.txt
uncd smb://server/share/path
๐ Project Structure
uncpath-py/
โโโ src/uncpath/
โ โโโ __init__.py # Main module, contains all APIs
โ โโโ parser.py # UNC path parser
โ โโโ config.py # Configuration manager
โ โโโ mapper.py # Path mapper
โ โโโ cli.py # Command line interface
โ โโโ exceptions.py # Exception definitions
โโโ tests/ # Test files
โโโ doc/ # Documentation directory
โโโ pyproject.toml # Project configuration
๐งช Testing
# Run all tests
python -m pytest tests/ -v
# Run specific tests
python -m pytest tests/test_uncpath.py -v
๐ ๏ธ Development
Install Development Dependencies
pip install -e ".[dev]"
Code Formatting
black src/ tests/
Code Checking
flake8 src/ tests/
Type Checking
mypy src/
๐ Version Roadmap
- v0.1.0 โ Basic UNC path conversion functionality (current version)
- v0.2.0 ๐ Samba auto-discovery functionality
- v0.2.1 ๐ Authentication support and caching mechanism
- v0.2.2 ๐ Advanced scanning strategies and batch operations
๐ค Contributing
Contributions are welcome! Please check CONTRIBUTING.md for detailed information.
๐ License
MIT License - See LICENSE file for details.
๐ Related Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uncpath-0.1.0.tar.gz.
File metadata
- Download URL: uncpath-0.1.0.tar.gz
- Upload date:
- Size: 96.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fc325a7f5d2c22c6d7d54558787035af815fff28e96a264b50050e635c58f9f
|
|
| MD5 |
217ecfd1f5a568ea4f35946d1bc94d9e
|
|
| BLAKE2b-256 |
e5113dbd2a86398239385cc2e6bbb476e749570daa8d6c6997e79141179cad7e
|
File details
Details for the file uncpath-0.1.0-py3-none-any.whl.
File metadata
- Download URL: uncpath-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05a2421c67ca64dab0e23b9fc4a83d94f2aaf83e63d4ee82730dcd532c132871
|
|
| MD5 |
d380afb365f8cdce223de9793bb16b58
|
|
| BLAKE2b-256 |
864d6dd513322d1b740984a2f23547424f2f0d59ddf096ce28c30f30e9a7377d
|