OS Helper Documentation

OS Helper is a Python library designed to simplify common programming tasks. Part of the AI Helpers collection, it includes tools for file handling, system operations, folder management, string manipulation, and more, with robust cross-platform support.

[🕸️ AI Helpers](https://harchaoui.org/warith/ai-helpers)

OS Helper Logo

Overview

This module provides a collection of utility functions optimized for: - Cross-platform compatibility (Windows, Linux, macOS, Unix). - File handling: creation, deletion, movement, and validation. - System operations: process management, OS detection, and command execution. - String manipulation: ASCII-safe conversions and hashing utilities. - Folder management: recursive searches, path handling, and zipping utilities.

Authors: - Warith Harchaoui - Mohamed Chelali - Bachir Zerroug

Dependencies:

The library relies on the following Python packages and standard modules:

  • contextlib, glob, hashlib, json, logging, os, pathlib, requests

  • shutil, subprocess, tempfile, numpy, yaml, validators, zipfile, dotenv

Installation

To install OS Helper, use the following pip command:

pip install --force-reinstall --no-cache-dir git+https://github.com/warith-harchaoui/os-helper.git@v1.0.0

Usage

Here’s how to use OS Helper to streamline your tasks:

  1. Set verbosity and check the OS type:

    import os_helper as osh
    
    osh.verbosity(3)
    if osh.unix():
        osh.info("Running on a Unix-based system.")
    else:
        osh.error("Not running on Unix.")
    
  2. File and directory operations:

    osh.make_directory("new_folder")
    if osh.file_exists("example.txt"):
        osh.copyfile("example.txt", "new_folder/example_copy.txt")
    
  3. String manipulation and hashing:

    safe_string = osh.asciistring("Café-Con-Leche!", replacement_char="_")
    file_hash = osh.hashfile("example.txt")
    
  4. Folder management:

    osh.zip_folder("my_folder", "my_folder_backup.zip")
    
  5. System command execution:

    cmd_output = osh.system("echo 'Hello, OS Helper!'")
    print(cmd_output["out"])
    

Table of Contents

Contents:

Get Started

Explore the Usage Guide or jump straight into the API Reference to unlock the full potential of OS Helper.