Few File Utilities
Project description
Few Utility Functions
Few personal utilities functions written in python3 and hosted on PyPI such as open and read conf/ini files and some OS functions.
Install
pip install ddcUtils
Conf File Utils
from ddcUtils import ConfFileUtils
cfu = ConfFileUtils()
File example - file.ini:
[main]
files=5
path="/tmp/test_dir"
port=5432
list=1,2,3,4,5,6
-
GET_ALL_VALUES
- Get all values from an .ini config file structure and returns them as a dictionary
- mixed_values will return all values as an object instead of dict
get_all_values(file_path: str, mixed_values: bool = False) -> dict
-
GET_SECTION_VALUES
- Get all section values from an .ini config file structure and returns them as a dictionary
get_section_values(file_path: str, section: str) -> dict
- Get all section values from an .ini config file structure and returns them as a dictionary
-
GET_VALUE
- Get value from an .ini config file structure and returns it
get_value(file_path: str, section: str, config_name: str) -> str | int | None
- Get value from an .ini config file structure and returns it
-
SET_VALUE
- Set value from an .ini config file structure and returns True or False
set_value(file_path: str, section_name: str, config_name: str, new_value, commas: bool = False) -> bool
- Set value from an .ini config file structure and returns True or False
File Utils
from ddcUtils import FileUtils
fu = FileUtils()
-
SHOW
- Open the given file or directory in explorer or notepad and returns True for success or False for failed access
@staticmethod show(path: str) -> bool
- Open the given file or directory in explorer or notepad and returns True for success or False for failed access
-
LIST_FILES
- List all files in the given directory and returns them in a tuple sorted by creation time in ascending order
@staticmethod list_files(directory: str, starts_with: str | tuple[str, ...] | list[str] = None, ends_with: str | tuple[str, ...] | list[str] = None) -> tuple
- List all files in the given directory and returns them in a tuple sorted by creation time in ascending order
-
GZIP
- Compress the given file and returns the Path for success or None if failed
@staticmethod gzip(input_file_path: str, output_dir: str = None) -> Path | None
- Compress the given file and returns the Path for success or None if failed
-
UNZIP
- Unzips the given file.zip and returns ZipFile for success or None if failed
@staticmethod unzip(file_path: str, out_path: str = None) -> ZipFile | None
- Unzips the given file.zip and returns ZipFile for success or None if failed
-
REMOVE
- Remove the given file or dir and returns True if it was successfully removed
@staticmethod remove(path: str) -> bool
- Remove the given file or dir and returns True if it was successfully removed
-
RENAME
- Rename the given file and returns True if the file was successfully
@staticmethod rename(from_name: str, to_name: str) -> bool
- Rename the given file and returns True if the file was successfully
-
COPY_DIR
- Copy files from src to dst and returns True or False
@staticmethod copy_dir(src, dst, symlinks=False, ignore=None) -> bool
- Copy files from src to dst and returns True or False
-
DOWNLOAD_FILE
- Download file from remote url to local and returns True or False
@staticmethod download_file(remote_file_url, local_file_path) -> bool
- Download file from remote url to local and returns True or False
-
GET_EXE_BINARY_TYPE
- Returns the binary type of the given windows EXE file
@staticmethod get_exe_binary_type(file_path: str) -> str | None
- Returns the binary type of the given windows EXE file
-
IS_OLDER_THAN_X_DAYS
- Check if a file or directory is older than the specified number of days
@staticmethod is_older_than_x_days(path: str, days: int) -> bool
- Check if a file or directory is older than the specified number of days
-
COPY
- Copy a file to another location
@staticmethod copy(src_path, dst_path)
- Copy a file to another location
Object
- This class is used for creating a simple class object
from ddcUtils import Object
obj = Object()
obj.test = "test"
Misc Utils
from ddcUtils import MiscUtils
mu = MiscUtils()
-
CLEAR_SCREEN
- Clears the terminal screen
@staticmethod clear_screen() -> None
- Clears the terminal screen
-
USER_CHOICE
- This function will ask the user to select an option
@staticmethod user_choice() -> input
- This function will ask the user to select an option
-
GET_ACTIVE_BRANCH_NAME
- Returns the name of the active branch if found, else returns None
@staticmethod get_active_branch_name(git_dir: str = ".git") -> str | None:
- Returns the name of the active branch if found, else returns None
-
GET_CURRENT_DATE_TIME
- Returns the current date and time on UTC timezone
@staticmethod get_current_date_time() -> datetime
- Returns the current date and time on UTC timezone
-
CONVERT_DATETIME_TO_STR_LONG
- Converts a datetime object to a long string
- returns: "Mon Jan 01 2024 21:43:04"
@staticmethod convert_datetime_to_str_long(date: datetime) -> str
-
CONVERT_DATETIME_TO_STR_SHORT
- Converts a datetime object to a short string
- returns: "2024-01-01 00:00:00.000000"
@staticmethod convert_datetime_to_str_short(date: datetime) -> str
-
CONVERT_STR_TO_DATETIME_SHORT
- Converts a str to a datetime
- input: "2024-01-01 00:00:00.000000"
@staticmethod convert_str_to_datetime_short(datetime_str: str) -> datetime
-
GET_CURRENT_DATE_TIME_STR_LONG
- Returns the current date and time as string
- returns: "Mon Jan 01 2024 21:47:00"
get_current_date_time_str_long() -> str
OS Utils
from ddcUtils import OsUtils
ou = OsUtils()
-
GET_OS_NAME
- Get OS name
@staticmethod get_os_name() -> str
- Get OS name
-
IS_WINDOWS
- Check if OS is Windows
@staticmethod is_windows() -> bool
- Check if OS is Windows
-
GET_CURRENT_PATH
- Returns the current working directory
@staticmethod get_current_path() -> Path
- Returns the current working directory
-
GET_PICTURES_PATH
- Returns the pictures directory inside the user's home directory
get_pictures_path() -> Path
- Returns the pictures directory inside the user's home directory
-
GET_DOWNLOADS_PATH
- Returns the download directory inside the user's home directory
get_downloads_path() -> Path
- Returns the download directory inside the user's home directory
Source Code
Build
poetry build
Run Tests
poetry run coverage run -m pytest -v
Get Coverage Report
poetry run coverage report
License
Released under the MIT License
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
File details
Details for the file ddcutils-1.0.32.tar.gz
.
File metadata
- Download URL: ddcutils-1.0.32.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86640e2106c16c05c116602a2c348386be465099e9af590ccf49502cf64f089d |
|
MD5 | f7269b64096fdf3bc2d76dbbfaff9979 |
|
BLAKE2b-256 | ff510c4a1e33d0abc6642033fba8cd910b2603c93cf18cd5d3d63ccedb2515dc |
Provenance
The following attestation bundles were made for ddcutils-1.0.32.tar.gz
:
Publisher:
workflow.yml
on ddc/ddcUtils
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
ddcutils-1.0.32.tar.gz
- Subject digest:
86640e2106c16c05c116602a2c348386be465099e9af590ccf49502cf64f089d
- Sigstore transparency entry: 152310940
- Sigstore integration time:
- Predicate type:
File details
Details for the file ddcutils-1.0.32-py3-none-any.whl
.
File metadata
- Download URL: ddcutils-1.0.32-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b5264d3f46800420d3c5f4259de960dcf30d6d9a567f3b1f37388849ac79430 |
|
MD5 | 84954092d4785b335ba26314a9f4d848 |
|
BLAKE2b-256 | e03aef576199fef5613609d9464be36939f9c146a0d63d25058ab683237e9d84 |
Provenance
The following attestation bundles were made for ddcutils-1.0.32-py3-none-any.whl
:
Publisher:
workflow.yml
on ddc/ddcUtils
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
ddcutils-1.0.32-py3-none-any.whl
- Subject digest:
3b5264d3f46800420d3c5f4259de960dcf30d6d9a567f3b1f37388849ac79430
- Sigstore transparency entry: 152310941
- Sigstore integration time:
- Predicate type: