Skip to main content

A Python package for UNC path operations

Project description

uncpath-py

CI/CD Pipeline PyPI version License: MIT

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uncpath-0.1.0.tar.gz (96.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uncpath-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

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

Hashes for uncpath-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0fc325a7f5d2c22c6d7d54558787035af815fff28e96a264b50050e635c58f9f
MD5 217ecfd1f5a568ea4f35946d1bc94d9e
BLAKE2b-256 e5113dbd2a86398239385cc2e6bbb476e749570daa8d6c6997e79141179cad7e

See more details on using hashes here.

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

Hashes for uncpath-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05a2421c67ca64dab0e23b9fc4a83d94f2aaf83e63d4ee82730dcd532c132871
MD5 d380afb365f8cdce223de9793bb16b58
BLAKE2b-256 864d6dd513322d1b740984a2f23547424f2f0d59ddf096ce28c30f30e9a7377d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page