globalutil

Documentation

Project Overview

globalutil is a Python library that provides utilities for file system operations, including file analysis, searching, organizing, and more. It’s designed to simplify common file system tasks and provide a unified interface for various file-related operations.

Installation

You can install globalutil using pip:

pip install globalutil

Project Structure

.
├── globalutil/
│   ├── filesystem/
│   │   ├── inspections/
│   │   │   ├── __init__.py
│   │   │   ├── analyzer.py
│   │   │   ├── inspect.py
│   │   │   ├── integrity.py
│   │   │   ├── recent.py
│   │   │   ├── search.py
│   │   │   └── extension_finder.py
│   │   ├── operations/
│   │   │   ├── __init__.py
│   │   │   ├── archive.py
│   │   │   ├── backup.py
│   │   │   ├── manager.py
│   │   │   ├── organizer.py
│   │   │   ├── rename.py
│   │   │   ├── sort.py
│   │   │   ├── file_reader.py
│   │   │   └── code_documentation.py
│   │   └── __init__.py
│   └── __init__.py
├── tests/
│   └── test_gutil_filesystem.py
├── LICENSE
├── README.md
├── pyproject.toml
└── setup.py

Modules

globalutil.filesystem.inspections

This module contains classes for inspecting and analyzing files and directories.

Inspect

The Inspect class provides methods for inspecting directory structures.

Methods:

FileAnalyzer

The FileAnalyzer class offers methods for analyzing files.

Methods:

FileSearch

The FileSearch class provides methods for searching files based on various criteria.

Methods:

FileIntegrity

The FileIntegrity class offers methods for checking file integrity.

Methods:

RecentFiles

The RecentFiles class provides methods for finding recently modified files.

Methods:

ExtensionFinder

The ExtensionFinder class provides methods for finding file extensions in a directory.

Methods:

Constants:

globalutil.filesystem.operations

This module contains classes for performing various file system operations.

Sort

The Sort class provides methods for sorting and copying files.

Methods:

FileOrganizer

The FileOrganizer class offers methods for organizing files.

Methods:

DirectoryManager

The DirectoryManager class provides methods for managing directories.

Methods:

FileBackup

The FileBackup class offers methods for backing up files.

Methods:

FileArchive

The FileArchive class provides methods for archiving files.

Methods:

FileRename

The FileRename class offers methods for renaming files.

Methods:

FileReader

The FileReader class offers methods for reading files with specific extensions.

Methods:

CodeDocumentation

The CodeDocumentation class provides methods for generating documentation for code files.

Methods:

Usage Examples

Copying specific file types to a single folder

from globalutil.filesystem import Inspect, Sort

# Generate the copy structure
structure = Inspect.generate_copy_structure("./", "./temp")

# Copy all .py files to the temp folder
Sort.copy_structure(structure, patterns=["*.py"])

Generating a tree structure of your project

from globalutil.filesystem import Inspect

# Generate the directory tree
tree = Inspect.get_directory_tree(".")

# Save the tree structure to a file
with open("tree.txt", "w") as f:
    f.write(tree)

Finding File Extensions and Reading Files

from globalutil.filesystem import ExtensionFinder
from globalutil.filesystem.operations import FileReader

# Find extensions in a directory
extensions = ExtensionFinder.find_extensions("/path/to/your/project")
coding_extensions = extensions.get('coding', set())
config_extensions = extensions.get('config', set())

print("Coding extensions:", coding_extensions)
print("Config extensions:", config_extensions)

# Read files with specific extensions
allowed_extensions = set.union(ExtensionFinder.CODING_EXTENSIONS, ExtensionFinder.CONFIG_EXTENSIONS)
reader = FileReader(allowed_extensions=allowed_extensions)

all_file_contents = reader.read_files_in_directory("/path/to/your/project")
for file_path, content in all_file_contents.items():
    print(f"File: {file_path}")
    print(content[:100])  # Print first 100 characters of each file
    print("---")

Generating Code Documentation

from globalutil.filesystem.operations import CodeDocumentation

code_doc = CodeDocumentation()
generated_file = code_doc.generate_entire_folder_txt(
    root_directory='/path/to/your/project',
    output_file='/path/to/output/entire_code.txt',
    file_extensions={".py", ".sh"}
)
print(f"Generated documentation file: {generated_file}")

Testing

The project includes a comprehensive test suite in the tests/ directory. You can run the tests using pytest:

pytest tests/

License

This project is licensed under the MIT License. See the LICENSE file for details.