A simple Python library
Project description
โ Python Automation Library with Excel, Web, and SFTP Utilities This library provides reusable utilities for automating Excel, web interactions with Selenium, and secure file transfers with SSH/SFTP. It is designed to save time and effort by abstracting common tasks into simple-to-use functions.
๐ Library Structure Overview bash Copy Edit ๐ฆ automation_utils/ โฃ ๐ init.py โฃ ๐ Utility.py โ Excel + general automation tools โฃ ๐ chrome.py โ Selenium reusable web automation functions โฃ ๐ selenium_certificate.py โ Specialized Selenium logic for certificate selection โฃ ๐ sftp.py โ SSH/SFTP helper functions โ ๐ README.md ๐ง Utility.py (Excel/General Automation) Utility.py contains reusable functions for various automation tasks related to data handling and Excel processing:
Cleaning Data:
str_to_float: Converts string columns to float and cleans data.
col_to_str: Converts columns to string and removes unwanted .0 suffix.
Sanity_Clean_df: Strips whitespace from column names and values in DataFrames.
Excel Formatting:
set_column_width: Sets column widths in an Excel worksheet.
set_header: Applies header formatting and column styles using xlsxwriter.
write_Data_to_Excel: Writes a DataFrame to Excel with optional formatting and summary rows.
Create_Pivot_Table: Creates dynamic Pivot Tables with win32com.
Excel File Management:
create_ZipFile: Creates zip archives from Excel outputs.
CleanFolder: Removes all files within a directory.
convert_Excel_to_csv: Converts an Excel file to CSV.
General Automation:
logFiles: Configures logging for error tracking.
TimeOut: Pauses script execution for specified intervals.
MailTrigger: Sends an email with optional attachments.
๐ chrome.py (Selenium Web Automation) chrome.py contains essential Selenium helper functions that simplify web automation tasks, especially for dynamic pages and interactions:
click_element(driver, locator): Safely clicks an element, handling waits and exceptions.
send_keys(driver, locator, text): Enters text into a field, ensuring it's ready for input.
change_download_directory(driver, path): Dynamically changes the download directory in Chrome at runtime.
extract_text(driver, locator): Extracts and returns visible text from a specified web element.
These methods are robust and include error handling and logging to ensure smooth automation in dynamic web environments.
๐ selenium_certificate.py selenium_certificate.py focuses on automating certificate selection workflows, especially useful for secure logins that require a certificate or token:
select_certificate(driver, cert_name): Automates the selection of a digital certificate from available options (handles popups, frame switching, etc.).
๐ sftp_util.py sftp_util.py provides SSH/SFTP helper functions using the paramiko library for secure file handling and remote server management.
SFTP Functions: connect(self) Establishes an SSH connection to the remote server.
connect_server(self) Connects to the server and prepares the session for file transfers.
put_file(self, local_file_path, remote_file_path) Uploads a file from the local machine to the remote server.
download_file(self, remote_file_path, local_file_path) Downloads a file from the remote server to the local machine.
upload_directory(self, local_directory, remote_directory) Uploads an entire directory from the local machine to the remote server.
download_directory(self, remote_directory, local_directory) Downloads an entire directory from the remote server to the local machine.
create_directory(self, remote_path) Creates a directory on the remote server.
remove_file(self, remote_file_path) Removes a file from the remote server.
rename_file(self, remote_old_path, remote_new_path) Renames a file on the remote server.
rename_folder(self, remote_old_path, remote_new_path) Renames a folder on the remote server.
list_directory(self, remote_file_path) Lists the contents of a remote directory.
list_directory_detailed(self, remote_path) Lists detailed information of files in the remote directory.
details_folder_file(self, path) Retrieves detailed information about files and directories on the remote server.
current_path_details(self) Retrieves the current path details on the remote server.
adjust_remote_path(self, remote_file_path) Adjusts the file path on the remote server for proper file handling.
check_directory(self, directory) Checks if a directory exists on the remote server.
set_cursor_path(self, cursor_path) Sets the cursor path for the current file operation.
Remote Command Execution: execute_command(self, command) Executes a command on the remote server via SSH.
run_bat_file(self, bat_file, arguments=None) Runs a .bat file on the remote server with optional arguments.
run_python_script(self, script_path, arguments=None) Executes a Python script on the remote server.
run_shell_script(self, script_path, arguments=None) Runs a shell script on the remote server.
Admin Functions: start_service(self, service_name) Starts a specified service on the remote server.
stop_service(self, service_name) Stops a specified service on the remote server.
restart_service(self, service_name) Restarts a specified service on the remote server.
kill_process(self, process_name) Terminates a process running on the remote server.
check_service_status(self, service_name) Checks the status of a specified service on the remote server.
check_cpu_usage(self) Retrieves the CPU usage statistics on the remote server.
check_memory_usage(self) Checks the memory usage on the remote server.
check_disk_usage(self) Retrieves disk usage statistics on the remote server.
list_processes(self) Lists all processes running on the remote server.
get_system_uptime(self) Retrieves the system uptime on the remote server.
view_system_events(self) Views the system event logs on the remote server.
File Handling: file_exists(self, remote_file_path) Checks if a specific file exists on the remote server.
get_file_size(self, remote_file_path) Retrieves the size of a file on the remote server.
change_file_permissions(self, remote_file_path, permissions) Changes the permissions of a file on the remote server.
move_directory(self, remote_old_path, remote_new_path) Moves a directory on the remote server.
append_to_remote_file(self, remote_file_path, content) Appends content to a file on the remote server.
SharedDrive_Utilies ๐น download_file_from_smb โ Use to download a single file from an SMB share to the local system.
Great for transferring log files, configs, or backups.
๐น download_worker โ Worker thread to handle multiple file downloads in parallel.
Useful when downloading many files faster using multithreading.
๐น matches_filters โ Apply filters to include/exclude files based on name, size, time, etc.
Helps in automating selective file processing.
๐น download_all_files_from_smb โ Recursively download entire folder contents from SMB with filtering and threading.
Best for bulk downloads with rules (e.g., latest 10 logs).
๐น check_session_directory โ Check if a path is a valid and accessible SMB directory.
Prevents errors by validating directory before use.
๐น download_folder โ Downloads all files from a server folder to local directory.
Useful for backing up or syncing a directory.
๐น filter_file โ Determine if a local file matches given criteria.
Handy in uploading only relevant or new files.
๐น upload_file โ Uploads all files from a local path to an SMB folder using threads.
Great for bulk uploads with optional filtering.
๐น upload_single_file โ Upload one specific file to an SMB path.
Ideal for manual or one-off uploads.
๐น create_directory โ Create a single directory on the SMB share.
Use before upload to ensure target path exists.
๐น remove_file โ Delete a specific file on the SMB server.
Good for clean-up scripts or removing outdated data.
๐น remove_directory โ Remove a directory from SMB, if empty.
Helps in automating cleanup tasks.
๐น rename_file_or_folder โ Rename or move files/folders on the SMB share.
Useful for reorganizing files or applying naming conventions.
๐น path_exists โ Check whether a given path exists on SMB.
Avoids errors by pre-checking before operations.
๐น make_directories โ Create nested directory structure on the SMB share.
Best when mirroring local folder structures remotely.
๐น create_symlink โ Create a symbolic link pointing to another file.
Useful for aliasing or redirecting to latest files.
๐น remove_symlink โ Delete an existing symbolic link on SMB.
Keeps directory structures clean and up to date.
๐น set_xattr โ Set custom metadata attributes on a file.
Great for tagging files with version, owner, or flags.
๐น get_xattr โ Retrieve a specific extended attribute from a file.
Allows reading custom file metadata.
๐น list_xattr โ List all extended attributes for a given file.
Useful for inspecting metadata attached to files.
๐น set_file_time โ Update a file's access and modification timestamps.
Critical for syncing timestamps during backups or audits.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file utilies-0.1.0.3.tar.gz.
File metadata
- Download URL: utilies-0.1.0.3.tar.gz
- Upload date:
- Size: 53.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad2746298590eab4dacb44b270462e866985937f9f4e440e4b0028e4d0063dbc
|
|
| MD5 |
afe0dbce9051c3a28e7b7f57bff3f305
|
|
| BLAKE2b-256 |
1451ce07a524a53941f2ab1ce20d0a2ae108545e2cde4ee975b4484469820f36
|
File details
Details for the file utilies-0.1.0.3-py3-none-any.whl.
File metadata
- Download URL: utilies-0.1.0.3-py3-none-any.whl
- Upload date:
- Size: 53.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5e0de87cb4b38db1f4189d7d7d2abb98b9085a0ffd19c698cb5d0d33a44aeed
|
|
| MD5 |
9c2e9a5c96720be45d7607eb2a472c1d
|
|
| BLAKE2b-256 |
1df96c06aa7401d67bd2b9c0daf726418846c3bb4b84eb1c6820bc4350df93dc
|