Skip to content
Merged

Dev #39

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion automation_file/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from automation_file.utils.file_process.get_dir_file_list import get_dir_files_as_list
from automation_file.utils.json.json_file import read_action_json
from automation_file.utils.project.create_project_structure import create_project_dir
from automation_file.remote.download.file import download_file

__all__ = [
"copy_file", "rename_file", "remove_file", "copy_all_file_to_dir", "copy_specify_extension_file",
Expand All @@ -27,5 +28,6 @@
"drive_upload_dir_to_folder", "drive_upload_to_folder", "drive_upload_dir_to_drive", "drive_upload_to_drive",
"drive_add_folder", "drive_share_file_to_anyone", "drive_share_file_to_domain", "drive_share_file_to_user",
"drive_delete_file", "drive_download_file", "drive_download_file_from_folder", "execute_action", "execute_files",
"add_command_to_executor", "read_action_json", "get_dir_files_as_list", "create_project_dir"
"add_command_to_executor", "read_action_json", "get_dir_files_as_list", "create_project_dir",
"download_file"
]
35 changes: 35 additions & 0 deletions automation_file/remote/download/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import requests
from tqdm import tqdm

from automation_file.utils.logging.loggin_instance import file_automation_logger


def download_file(file_url: str, file_name: str, chunk_size: int = 1024, timeout: int = 10):
try:
response = requests.get(file_url, stream=True, timeout=10)
response.raise_for_status()
total_size = int(response.headers.get('content-length', 0))
with open(file_name, 'wb') as file:
if total_size > 0:
with tqdm(
total=total_size, unit='B', unit_scale=True, desc=file_name
) as progress:
for chunk in response.iter_content(chunk_size=chunk_size):
if chunk:
file.write(chunk)
progress.update(len(chunk))
else:
for chunk in response.iter_content(chunk_size=chunk_size):
if chunk:
file.write(chunk)

file_automation_logger.info(f"File download is complete. Saved as: {file_name}")
except requests.exceptions.HTTPError as http_err:
file_automation_logger.error(f"HTTP error:{http_err}")
except requests.exceptions.ConnectionError:
file_automation_logger.error("Connection error. Please check your internet connection.")
except requests.exceptions.Timeout:
file_automation_logger.error("Request timed out. The server did not respond.")
except Exception as err:
file_automation_logger.error(f"Error:{err}")

20 changes: 0 additions & 20 deletions automation_file/utils/executor/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from automation_file.utils.json.json_file import read_action_json
from automation_file.utils.logging.loggin_instance import file_automation_logger
from automation_file.utils.package_manager.package_manager_class import package_manager
from automation_file.utils.scheduler.extend_apscheduler import scheduler_manager


class Executor(object):
Expand Down Expand Up @@ -72,15 +71,6 @@ def __init__(self):
"FA_execute_action": self.execute_action,
"FA_execute_files": self.execute_files,
"FA_add_package_to_executor": package_manager.add_package_to_executor,
# Scheduler
"FA_scheduler_event_trigger": self.scheduler_event_trigger,
"FA_remove_blocking_scheduler_job": scheduler_manager.remove_blocking_job,
"FA_remove_nonblocking_scheduler_job": scheduler_manager.remove_nonblocking_job,
"FA_start_blocking_scheduler": scheduler_manager.start_block_scheduler,
"FA_start_nonblocking_scheduler": scheduler_manager.start_nonblocking_scheduler,
"FA_start_all_scheduler": scheduler_manager.start_all_scheduler,
"FA_shutdown_blocking_scheduler": scheduler_manager.shutdown_blocking_scheduler,
"FA_shutdown_nonblocking_scheduler": scheduler_manager.shutdown_nonblocking_scheduler,
}
# get all builtin function and add to event dict
for function in getmembers(builtins, isbuiltin):
Expand Down Expand Up @@ -145,16 +135,6 @@ def execute_files(self, execute_files_list: list) -> list:
execute_detail_list.append(self.execute_action(read_action_json(file)))
return execute_detail_list

def scheduler_event_trigger(
self, function: str, id: str = None, args: Union[list, tuple] = None,
kwargs: dict = None, scheduler_type: str = "nonblocking", wait_type: str = "secondly",
wait_value: int = 1, **trigger_args: Any) -> None:
if scheduler_type == "nonblocking":
scheduler_event = scheduler_manager.nonblocking_scheduler_event_dict.get(wait_type)
else:
scheduler_event = scheduler_manager.blocking_scheduler_event_dict.get(wait_type)
scheduler_event(self.event_dict.get(function), id, args, kwargs, wait_value, **trigger_args)


executor = Executor()
package_manager.executor = executor
Expand Down
215 changes: 0 additions & 215 deletions automation_file/utils/scheduler/extend_apscheduler.py

This file was deleted.

6 changes: 3 additions & 3 deletions dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "automation_file_dev"
version = "0.0.25"
version = "0.0.28"
authors = [
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
]
Expand All @@ -18,15 +18,15 @@ dependencies = [
"google-api-python-client",
"google-auth-httplib2",
"google-auth-oauthlib",
"APScheduler"
"requests",
"tqdm"
]
classifiers = [
"Programming Language :: Python :: 3.9",
"Development Status :: 2 - Pre-Alpha",
"Environment :: Win32 (MS Windows)",
"Environment :: MacOS X",
"Environment :: X11 Applications",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
]

Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ build-backend = "setuptools.build_meta"

[project]
name = "automation_file"
version = "0.0.23"
version = "0.0.26"
authors = [
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
]
description = ""
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.9"
license = { text = "MIT" }
license-files = ["LICENSE"]
dependencies = [
"google-api-python-client",
"google-auth-httplib2",
"google-auth-oauthlib",
"APScheduler"
"requests",
"tqdm"
]
classifiers = [
"Programming Language :: Python :: 3.9",
"Development Status :: 2 - Pre-Alpha",
"Environment :: Win32 (MS Windows)",
"Environment :: MacOS X",
"Environment :: X11 Applications",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
]

Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ automation_file
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
APScheduler
PySide6
requests
protobuf
tqdm