# File Utilities
Few File Utilities and some OS Functions
[![License](https://img.shields.io/github/license/ddc/ddcUtils.svg)](https://github.com/ddc/ddcUtils/blob/master/LICENSE)
[![Python](https://img.shields.io/badge/Python-3.12+-blue.svg)](https://www.python.org)
[![PyPi](https://img.shields.io/pypi/v/ddcUtils.svg)](https://pypi.python.org/pypi/ddcUtils)
[![PyPI Downloads](https://static.pepy.tech/badge/ddcUtils)](https://pepy.tech/projects/ddcUtils)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A//actions-badge.atrox.dev/ddc/ddcUtils/badge?ref=main&label=build&logo=none)](https://actions-badge.atrox.dev/ddc/ddcUtils/goto?ref=main)
# Install
```shell
pip install ddcUtils
```
# Conf File Utils
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
```python
from ddcUtils import ConfFileUtils
cfu = ConfFileUtils()
cfu.get_all_values(file_path, mixed_values=False)
```
+ GET_SECTION_VALUES
+ Get all section values from an .ini config file structure and returns them as a dictionary
```python
from ddcUtils import ConfFileUtils
cfu = ConfFileUtils()
cfu.get_section_values(file_path, section)
```
+ GET_VALUE
+ Get value from an .ini config file structure and returns it
```python
from ddcUtils import ConfFileUtils
cfu = ConfFileUtils()
cfu.get_value(file_path, section, config_name)
```
+ SET_VALUE
+ Set value from an .ini config file structure and returns True or False
```python
from ddcUtils import ConfFileUtils
cfu = ConfFileUtils()
cfu.set_value(file_path, section_name, config_name, new_value, commas=False)
```
# File Utils
+ OPEN
+ Open the given file or directory in explorer or notepad and returns True for success or False for failed access
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.open(path)
```
+ LIST_FILES
+ List all files in the given directory and returns them in a tuple sorted by creation time in ascending order
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.list_files(directory, starts_with, ends_with)
```
+ GZIP
+ Compress the given file and returns the Path for success or None if failed
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.gzip(input_file_path, output_dir=None)
```
+ UNZIP
+ Unzips the given file.zip and returns ZipFile for success or None if failed
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.unzip(file_path, out_pathNone)
```
+ REMOVE
+ Remove the given file or dir and returns True if it was successfully removed
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.remove(path)
```
+ RENAME
+ Rename the given file and returns True if the file was successfully
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.rename(from_name, to_name)
```
+ COPY_DIR
+ Copy files from src to dst and returns True or False
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.copy_dir(src, dst, symlinks=False, ignore=None)
```
+ DOWNLOAD_FILE
+ Download file from remote url to local and returns True or False
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.download_file(remote_file_url, local_file_path)
```
+ GET_EXE_BINARY_TYPE
+ Returns the binary type of the given windows EXE file
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.get_exe_binary_type(file_path)
```
+ IS_OLDER_THAN_X_DAYS
+ Check if a file or directory is older than the specified number of days
```python
from ddcUtils import FileUtils
fu = FileUtils()
fu.is_older_than_x_days(path, days)
```
+ COPY
+ Copy a file to another location
```python
from ddcUtils import FileUtils
fu = FileUtils()
copy(src_path, dst_path)
```
# Object
+ This class is used for creating a simple class object
```python
from ddcUtils import Object
obj = Object()
obj.test = "test"
```
# Misc Utils
+ CLEAR_SCREEN
+ Clears the terminal screen
```python
from ddcUtils import MiscUtils
mu = MiscUtils()
mu.clear_screen()
```
+ USER_CHOICE
+ This function will ask the user to select an option
```python
from ddcUtils import MiscUtils
mu = MiscUtils()
mu.user_choice()
```
+ GET_ACTIVE_BRANCH_NAME
+ Returns the name of the active branch if found, else returns None
```python
from ddcUtils import MiscUtils
mu = MiscUtils()
mu.get_active_branch_name(git_dir=".git")
```
+ GET_CURRENT_DATE_TIME
+ Returns the current date and time on UTC timezone
```python
from ddcUtils import MiscUtils
mu = MiscUtils()
mu.get_current_date_time()
```
+ CONVERT_DATETIME_TO_STR_LONG
+ Converts a datetime object to a long string
+ returns: "Mon Jan 01 2024 21:43:04"
```python
from ddcUtils import MiscUtils
mu = MiscUtils()
mu.convert_datetime_to_str_long(date)
```
+ CONVERT_DATETIME_TO_STR_SHORT
+ Converts a datetime object to a short string
+ returns: "2024-01-01 00:00:00.000000"
```python
from ddcUtils import MiscUtils
mu = MiscUtils()
mu.convert_datetime_to_str_short(date)
```
+ CONVERT_STR_TO_DATETIME_SHORT
+ Converts a str to a datetime
+ input: "2024-01-01 00:00:00.000000"
```python
from ddcUtils import MiscUtils
mu = MiscUtils()
mu.convert_str_to_datetime_short(datetime_str)
```
+ GET_CURRENT_DATE_TIME_STR_LONG
+ Returns the current date and time as string
+ returns: "Mon Jan 01 2024 21:47:00"
```python
from ddcUtils import MiscUtils
mu = MiscUtils()
mu.get_current_date_time_str_long()
```
# OS Utils
+ GET_OS_NAME
+ Get OS name
```python
from ddcUtils import OsUtils
ou = OsUtils()
get_os_name()
```
+ IS_WINDOWS
+ Check if OS is Windows
```python
from ddcUtils import OsUtils
ou = OsUtils()
is_windows()
```
+ GET_CURRENT_PATH
+ Returns the current working directory
```python
from ddcUtils import OsUtils
ou = OsUtils()
get_current_path()
```
+ GET_PICTURES_PATH
+ Returns the pictures directory inside the user's home directory
```python
from ddcUtils import OsUtils
ou = OsUtils()
get_pictures_path()
```
+ GET_DOWNLOADS_PATH
+ Returns the download directory inside the user's home directory
```python
from ddcUtils import OsUtils
ou = OsUtils()
get_downloads_path()
```
# Source Code
### Build
```shell
poetry build -f wheel
```
# Run Tests and Get Coverage Report using Poe
```shell
poetry update --with test
poe tests
```
# License
Released under the [MIT License](LICENSE)
# Buy me a cup of coffee
+ [GitHub Sponsor](https://github.com/sponsors/ddc)
+ [ko-fi](https://ko-fi.com/ddcsta)
+ [Paypal](https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ)
Raw data
{
"_id": null,
"home_page": "https://pypi.org/project/ddcUtils",
"name": "ddcUtils",
"maintainer": "Daniel Costa",
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "python3, python-3, python, tools, utility, utilities, utils, utility-library, utils-library, utilities-library",
"author": "Daniel Costa",
"author_email": "danieldcsta@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f0/d9/e6e5c5723d7d93cd15a01fcd96dac5186651dc5121516e866b26e67cfcd8/ddcutils-1.0.36.tar.gz",
"platform": null,
"description": "# File Utilities\nFew File Utilities and some OS Functions\n\n[![License](https://img.shields.io/github/license/ddc/ddcUtils.svg)](https://github.com/ddc/ddcUtils/blob/master/LICENSE)\n[![Python](https://img.shields.io/badge/Python-3.12+-blue.svg)](https://www.python.org)\n[![PyPi](https://img.shields.io/pypi/v/ddcUtils.svg)](https://pypi.python.org/pypi/ddcUtils)\n[![PyPI Downloads](https://static.pepy.tech/badge/ddcUtils)](https://pepy.tech/projects/ddcUtils)\n[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A//actions-badge.atrox.dev/ddc/ddcUtils/badge?ref=main&label=build&logo=none)](https://actions-badge.atrox.dev/ddc/ddcUtils/goto?ref=main)\n\n\n# Install\n```shell\npip install ddcUtils\n```\n\n\n# Conf File Utils\n\nFile example - file.ini:\n\n [main]\n files=5\n path=\"/tmp/test_dir\"\n port=5432\n list=1,2,3,4,5,6\n\n\n+ GET_ALL_VALUES\n + Get all values from an .ini config file structure and returns them as a dictionary\n + mixed_values will return all values as an object instead of dict\n```python\nfrom ddcUtils import ConfFileUtils\ncfu = ConfFileUtils()\ncfu.get_all_values(file_path, mixed_values=False)\n```\n\n\n\n+ GET_SECTION_VALUES\n + Get all section values from an .ini config file structure and returns them as a dictionary\n```python\nfrom ddcUtils import ConfFileUtils\ncfu = ConfFileUtils()\ncfu.get_section_values(file_path, section)\n```\n\n\n\n+ GET_VALUE\n + Get value from an .ini config file structure and returns it\n```python\nfrom ddcUtils import ConfFileUtils\ncfu = ConfFileUtils()\ncfu.get_value(file_path, section, config_name)\n```\n\n\n\n+ SET_VALUE\n + Set value from an .ini config file structure and returns True or False\n```python\nfrom ddcUtils import ConfFileUtils\ncfu = ConfFileUtils()\ncfu.set_value(file_path, section_name, config_name, new_value, commas=False)\n```\n\n\n# File Utils\n\n+ OPEN\n + Open the given file or directory in explorer or notepad and returns True for success or False for failed access\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.open(path)\n```\n\n\n\n+ LIST_FILES\n + List all files in the given directory and returns them in a tuple sorted by creation time in ascending order\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.list_files(directory, starts_with, ends_with)\n```\n\n\n\n+ GZIP\n + Compress the given file and returns the Path for success or None if failed\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.gzip(input_file_path, output_dir=None)\n```\n\n\n\n+ UNZIP\n + Unzips the given file.zip and returns ZipFile for success or None if failed\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.unzip(file_path, out_pathNone)\n```\n\n\n\n+ REMOVE\n + Remove the given file or dir and returns True if it was successfully removed\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.remove(path)\n```\n\n\n\n+ RENAME\n + Rename the given file and returns True if the file was successfully\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.rename(from_name, to_name)\n```\n\n\n\n+ COPY_DIR\n + Copy files from src to dst and returns True or False\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.copy_dir(src, dst, symlinks=False, ignore=None)\n```\n\n\n\n+ DOWNLOAD_FILE\n + Download file from remote url to local and returns True or False\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.download_file(remote_file_url, local_file_path)\n```\n\n\n\n+ GET_EXE_BINARY_TYPE\n + Returns the binary type of the given windows EXE file\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.get_exe_binary_type(file_path)\n```\n\n\n\n+ IS_OLDER_THAN_X_DAYS\n + Check if a file or directory is older than the specified number of days\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\nfu.is_older_than_x_days(path, days)\n```\n\n\n\n+ COPY\n + Copy a file to another location\n```python\nfrom ddcUtils import FileUtils\nfu = FileUtils()\ncopy(src_path, dst_path)\n```\n\n\n\n# Object\n+ This class is used for creating a simple class object\n ```python\nfrom ddcUtils import Object\nobj = Object()\nobj.test = \"test\"\n``` \n\n\n# Misc Utils\n\n+ CLEAR_SCREEN\n + Clears the terminal screen\n```python\nfrom ddcUtils import MiscUtils\nmu = MiscUtils()\nmu.clear_screen()\n```\n\n\n\n+ USER_CHOICE\n + This function will ask the user to select an option\n```python\nfrom ddcUtils import MiscUtils\nmu = MiscUtils()\nmu.user_choice()\n```\n\n\n\n+ GET_ACTIVE_BRANCH_NAME\n + Returns the name of the active branch if found, else returns None\n```python\nfrom ddcUtils import MiscUtils\nmu = MiscUtils()\nmu.get_active_branch_name(git_dir=\".git\")\n```\n\n\n\n+ GET_CURRENT_DATE_TIME\n + Returns the current date and time on UTC timezone\n```python\nfrom ddcUtils import MiscUtils\nmu = MiscUtils()\nmu.get_current_date_time()\n```\n\n\n\n+ CONVERT_DATETIME_TO_STR_LONG\n + Converts a datetime object to a long string\n + returns: \"Mon Jan 01 2024 21:43:04\"\n```python\nfrom ddcUtils import MiscUtils\nmu = MiscUtils()\nmu.convert_datetime_to_str_long(date)\n```\n\n\n\n+ CONVERT_DATETIME_TO_STR_SHORT\n + Converts a datetime object to a short string\n + returns: \"2024-01-01 00:00:00.000000\"\n```python\nfrom ddcUtils import MiscUtils\nmu = MiscUtils()\nmu.convert_datetime_to_str_short(date)\n```\n\n\n\n+ CONVERT_STR_TO_DATETIME_SHORT\n + Converts a str to a datetime\n + input: \"2024-01-01 00:00:00.000000\"\n```python\nfrom ddcUtils import MiscUtils\nmu = MiscUtils()\nmu.convert_str_to_datetime_short(datetime_str)\n```\n\n\n\n+ GET_CURRENT_DATE_TIME_STR_LONG\n + Returns the current date and time as string\n + returns: \"Mon Jan 01 2024 21:47:00\"\n```python\nfrom ddcUtils import MiscUtils\nmu = MiscUtils()\nmu.get_current_date_time_str_long()\n```\n\n\n# OS Utils\n\n+ GET_OS_NAME\n + Get OS name\n```python\nfrom ddcUtils import OsUtils\nou = OsUtils()\nget_os_name()\n```\n\n\n\n+ IS_WINDOWS\n + Check if OS is Windows\n```python\nfrom ddcUtils import OsUtils\nou = OsUtils()\nis_windows()\n```\n\n\n\n+ GET_CURRENT_PATH\n + Returns the current working directory\n```python\nfrom ddcUtils import OsUtils\nou = OsUtils()\nget_current_path()\n```\n\n\n\n+ GET_PICTURES_PATH\n + Returns the pictures directory inside the user's home directory\n```python\nfrom ddcUtils import OsUtils\nou = OsUtils()\nget_pictures_path()\n```\n\n\n\n+ GET_DOWNLOADS_PATH\n + Returns the download directory inside the user's home directory\n```python\nfrom ddcUtils import OsUtils\nou = OsUtils()\nget_downloads_path()\n```\n\n\n# Source Code\n### Build\n```shell\npoetry build -f wheel\n```\n\n\n\n# Run Tests and Get Coverage Report using Poe\n```shell\npoetry update --with test\npoe tests\n```\n\n\n\n# License\nReleased under the [MIT License](LICENSE)\n\n\n\n# Buy me a cup of coffee\n+ [GitHub Sponsor](https://github.com/sponsors/ddc)\n+ [ko-fi](https://ko-fi.com/ddcsta)\n+ [Paypal](https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ)\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Few File Utilities and some OS Functions",
"version": "1.0.36",
"project_urls": {
"Homepage": "https://pypi.org/project/ddcUtils",
"Repository": "https://github.com/ddc/ddcUtils"
},
"split_keywords": [
"python3",
" python-3",
" python",
" tools",
" utility",
" utilities",
" utils",
" utility-library",
" utils-library",
" utilities-library"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2873a01e11f6f50a5be0343a4e3efd21d856287e7bc59d8a0b1a88ead751e266",
"md5": "5970f26e12b0ad4bfcc9b394af153952",
"sha256": "0cdaccb6162abbe9d0cf0151c6e9401091a7c426a50a3d0c9f4b3674c9a936d5"
},
"downloads": -1,
"filename": "ddcutils-1.0.36-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5970f26e12b0ad4bfcc9b394af153952",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 10785,
"upload_time": "2024-11-30T17:39:06",
"upload_time_iso_8601": "2024-11-30T17:39:06.420139Z",
"url": "https://files.pythonhosted.org/packages/28/73/a01e11f6f50a5be0343a4e3efd21d856287e7bc59d8a0b1a88ead751e266/ddcutils-1.0.36-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f0d9e6e5c5723d7d93cd15a01fcd96dac5186651dc5121516e866b26e67cfcd8",
"md5": "0c1b238b400e3e18d2fe39704151e952",
"sha256": "d6eb4ad01b15cfb44f08a3e381d416722b83460904ca891bc8e48ea53c02be7b"
},
"downloads": -1,
"filename": "ddcutils-1.0.36.tar.gz",
"has_sig": false,
"md5_digest": "0c1b238b400e3e18d2fe39704151e952",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 9777,
"upload_time": "2024-11-30T17:39:15",
"upload_time_iso_8601": "2024-11-30T17:39:15.937575Z",
"url": "https://files.pythonhosted.org/packages/f0/d9/e6e5c5723d7d93cd15a01fcd96dac5186651dc5121516e866b26e67cfcd8/ddcutils-1.0.36.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-30 17:39:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ddc",
"github_project": "ddcUtils",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ddcutils"
}