Skip to content

Commit 64dd421

Browse files
authored
Merge pull request #39 from Integration-Automation/dev
Dev
2 parents 93e87fb + ce66926 commit 64dd421

File tree

8 files changed

+49
-244
lines changed

8 files changed

+49
-244
lines changed

automation_file/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from automation_file.utils.file_process.get_dir_file_list import get_dir_files_as_list
1919
from automation_file.utils.json.json_file import read_action_json
2020
from automation_file.utils.project.create_project_structure import create_project_dir
21+
from automation_file.remote.download.file import download_file
2122

2223
__all__ = [
2324
"copy_file", "rename_file", "remove_file", "copy_all_file_to_dir", "copy_specify_extension_file",
@@ -27,5 +28,6 @@
2728
"drive_upload_dir_to_folder", "drive_upload_to_folder", "drive_upload_dir_to_drive", "drive_upload_to_drive",
2829
"drive_add_folder", "drive_share_file_to_anyone", "drive_share_file_to_domain", "drive_share_file_to_user",
2930
"drive_delete_file", "drive_download_file", "drive_download_file_from_folder", "execute_action", "execute_files",
30-
"add_command_to_executor", "read_action_json", "get_dir_files_as_list", "create_project_dir"
31+
"add_command_to_executor", "read_action_json", "get_dir_files_as_list", "create_project_dir",
32+
"download_file"
3133
]
File renamed without changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import requests
2+
from tqdm import tqdm
3+
4+
from automation_file.utils.logging.loggin_instance import file_automation_logger
5+
6+
7+
def download_file(file_url: str, file_name: str, chunk_size: int = 1024, timeout: int = 10):
8+
try:
9+
response = requests.get(file_url, stream=True, timeout=10)
10+
response.raise_for_status()
11+
total_size = int(response.headers.get('content-length', 0))
12+
with open(file_name, 'wb') as file:
13+
if total_size > 0:
14+
with tqdm(
15+
total=total_size, unit='B', unit_scale=True, desc=file_name
16+
) as progress:
17+
for chunk in response.iter_content(chunk_size=chunk_size):
18+
if chunk:
19+
file.write(chunk)
20+
progress.update(len(chunk))
21+
else:
22+
for chunk in response.iter_content(chunk_size=chunk_size):
23+
if chunk:
24+
file.write(chunk)
25+
26+
file_automation_logger.info(f"File download is complete. Saved as: {file_name}")
27+
except requests.exceptions.HTTPError as http_err:
28+
file_automation_logger.error(f"HTTP error:{http_err}")
29+
except requests.exceptions.ConnectionError:
30+
file_automation_logger.error("Connection error. Please check your internet connection.")
31+
except requests.exceptions.Timeout:
32+
file_automation_logger.error("Request timed out. The server did not respond.")
33+
except Exception as err:
34+
file_automation_logger.error(f"Error:{err}")
35+

automation_file/utils/executor/action_executor.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from automation_file.utils.json.json_file import read_action_json
2626
from automation_file.utils.logging.loggin_instance import file_automation_logger
2727
from automation_file.utils.package_manager.package_manager_class import package_manager
28-
from automation_file.utils.scheduler.extend_apscheduler import scheduler_manager
2928

3029

3130
class Executor(object):
@@ -72,15 +71,6 @@ def __init__(self):
7271
"FA_execute_action": self.execute_action,
7372
"FA_execute_files": self.execute_files,
7473
"FA_add_package_to_executor": package_manager.add_package_to_executor,
75-
# Scheduler
76-
"FA_scheduler_event_trigger": self.scheduler_event_trigger,
77-
"FA_remove_blocking_scheduler_job": scheduler_manager.remove_blocking_job,
78-
"FA_remove_nonblocking_scheduler_job": scheduler_manager.remove_nonblocking_job,
79-
"FA_start_blocking_scheduler": scheduler_manager.start_block_scheduler,
80-
"FA_start_nonblocking_scheduler": scheduler_manager.start_nonblocking_scheduler,
81-
"FA_start_all_scheduler": scheduler_manager.start_all_scheduler,
82-
"FA_shutdown_blocking_scheduler": scheduler_manager.shutdown_blocking_scheduler,
83-
"FA_shutdown_nonblocking_scheduler": scheduler_manager.shutdown_nonblocking_scheduler,
8474
}
8575
# get all builtin function and add to event dict
8676
for function in getmembers(builtins, isbuiltin):
@@ -145,16 +135,6 @@ def execute_files(self, execute_files_list: list) -> list:
145135
execute_detail_list.append(self.execute_action(read_action_json(file)))
146136
return execute_detail_list
147137

148-
def scheduler_event_trigger(
149-
self, function: str, id: str = None, args: Union[list, tuple] = None,
150-
kwargs: dict = None, scheduler_type: str = "nonblocking", wait_type: str = "secondly",
151-
wait_value: int = 1, **trigger_args: Any) -> None:
152-
if scheduler_type == "nonblocking":
153-
scheduler_event = scheduler_manager.nonblocking_scheduler_event_dict.get(wait_type)
154-
else:
155-
scheduler_event = scheduler_manager.blocking_scheduler_event_dict.get(wait_type)
156-
scheduler_event(self.event_dict.get(function), id, args, kwargs, wait_value, **trigger_args)
157-
158138

159139
executor = Executor()
160140
package_manager.executor = executor

automation_file/utils/scheduler/extend_apscheduler.py

Lines changed: 0 additions & 215 deletions
This file was deleted.

dev.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "automation_file_dev"
9-
version = "0.0.25"
9+
version = "0.0.28"
1010
authors = [
1111
{ name = "JE-Chen", email = "[email protected]" },
1212
]
@@ -18,15 +18,15 @@ dependencies = [
1818
"google-api-python-client",
1919
"google-auth-httplib2",
2020
"google-auth-oauthlib",
21-
"APScheduler"
21+
"requests",
22+
"tqdm"
2223
]
2324
classifiers = [
2425
"Programming Language :: Python :: 3.9",
2526
"Development Status :: 2 - Pre-Alpha",
2627
"Environment :: Win32 (MS Windows)",
2728
"Environment :: MacOS X",
2829
"Environment :: X11 Applications",
29-
"License :: OSI Approved :: MIT License",
3030
"Operating System :: OS Independent"
3131
]
3232

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "automation_file"
9-
version = "0.0.23"
9+
version = "0.0.26"
1010
authors = [
1111
{ name = "JE-Chen", email = "[email protected]" },
1212
]
1313
description = ""
1414
readme = { file = "README.md", content-type = "text/markdown" }
1515
requires-python = ">=3.9"
16-
license = { text = "MIT" }
16+
license-files = ["LICENSE"]
1717
dependencies = [
1818
"google-api-python-client",
1919
"google-auth-httplib2",
2020
"google-auth-oauthlib",
21-
"APScheduler"
21+
"requests",
22+
"tqdm"
2223
]
2324
classifiers = [
2425
"Programming Language :: Python :: 3.9",
2526
"Development Status :: 2 - Pre-Alpha",
2627
"Environment :: Win32 (MS Windows)",
2728
"Environment :: MacOS X",
2829
"Environment :: X11 Applications",
29-
"License :: OSI Approved :: MIT License",
3030
"Operating System :: OS Independent"
3131
]
3232

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ automation_file
22
google-api-python-client
33
google-auth-httplib2
44
google-auth-oauthlib
5-
APScheduler
5+
PySide6
6+
requests
7+
protobuf
8+
tqdm

0 commit comments

Comments
 (0)