Skip to content

Commit f6dc607

Browse files
authored
Merge pull request #17 from Integration-Automation/dev
Dev
2 parents aa9dcef + a4de745 commit f6dc607

27 files changed

Lines changed: 406 additions & 113 deletions

dev.toml

Lines changed: 1 addition & 1 deletion
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.9"
9+
version = "0.0.11"
1010
authors = [
1111
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
1212
]

file_automation/__init__.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@
66

77
from file_automation.remote.google_drive.driver_instance import driver_instance
88
from file_automation.remote.google_drive.search.search_drive import \
9-
search_all_file, search_field, search_file_mimetype
9+
drive_search_all_file, drive_search_field, drive_search_file_mimetype
1010
from file_automation.remote.google_drive.upload.upload_to_driver import \
11-
upload_dir_to_folder, upload_to_folder, upload_dir_to_drive, upload_to_drive
12-
from file_automation.remote.google_drive.dir.folder_manager import add_folder
11+
drive_upload_dir_to_folder, drive_upload_to_folder, drive_upload_dir_to_drive, drive_upload_to_drive
12+
from file_automation.remote.google_drive.dir.folder_manager import drive_add_folder
1313
from file_automation.remote.google_drive.share.share_file import \
14-
share_file_to_anyone, share_file_to_domain, share_file_to_user
15-
from file_automation.remote.google_drive.delete.delete_manager import delete_file
16-
from file_automation.remote.google_drive.download.download_file import download_file, download_file_from_folder
17-
14+
drive_share_file_to_anyone, drive_share_file_to_domain, drive_share_file_to_user
15+
from file_automation.remote.google_drive.delete.delete_manager import drive_delete_file
16+
from file_automation.remote.google_drive.download.download_file import drive_download_file, drive_download_file_from_folder
17+
from file_automation.utils.executor.action_executor import execute_action, execute_files, add_command_to_executor
18+
from file_automation.utils.json.json_file import read_action_json
19+
from file_automation.utils.file_process.get_dir_file_list import get_dir_files_as_list
1820
__all__ = [
1921
"copy_file", "rename_file", "remove_file", "copy_all_file_to_dir", "copy_specify_extension_file",
2022
"copy_dir", "create_dir", "remove_dir_tree", "zip_dir", "zip_file", "zip_info",
2123
"zip_file_info", "set_zip_password", "unzip_file", "read_zip_file",
22-
"unzip_all", "driver_instance", "search_all_file", "search_field", "search_file_mimetype",
23-
"upload_dir_to_folder", "upload_to_folder", "upload_dir_to_drive", "upload_to_drive",
24-
"add_folder", "share_file_to_anyone", "share_file_to_domain", "share_file_to_user",
25-
"delete_file", "download_file", "download_file_from_folder"
24+
"unzip_all", "driver_instance", "drive_search_all_file", "drive_search_field", "drive_search_file_mimetype",
25+
"drive_upload_dir_to_folder", "drive_upload_to_folder", "drive_upload_dir_to_drive", "drive_upload_to_drive",
26+
"drive_add_folder", "drive_share_file_to_anyone", "drive_share_file_to_domain", "drive_share_file_to_user",
27+
"drive_delete_file", "drive_download_file", "drive_download_file_from_folder", "execute_action", "execute_files",
28+
"add_command_to_executor", "read_action_json", "get_dir_files_as_list"
2629
]

file_automation/local/dir/dir_process.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from file_automation.utils.logging.loggin_instance import file_automation_logger
77

88

9-
def copy_dir(dir_path: str, target_dir_path: str):
9+
def copy_dir(dir_path: str, target_dir_path: str) -> None:
1010
dir_path = Path(dir_path)
1111
target_dir_path = Path(target_dir_path)
1212
if dir_path.is_dir():
@@ -19,7 +19,7 @@ def copy_dir(dir_path: str, target_dir_path: str):
1919
file_automation_logger.error(f"Copy dir {dir_path} failed: {repr(DirNotExistsException)}")
2020

2121

22-
def remove_dir_tree(dir_path: str):
22+
def remove_dir_tree(dir_path: str) -> None:
2323
dir_path = Path(dir_path)
2424
if dir_path.is_dir():
2525
try:
@@ -29,7 +29,7 @@ def remove_dir_tree(dir_path: str):
2929
file_automation_logger.error(f"Remove dir tree {dir_path} error: {repr(error)}")
3030

3131

32-
def rename_dir(origin_dir_path, target_dir: str):
32+
def rename_dir(origin_dir_path, target_dir: str) -> None:
3333
origin_dir_path = Path(origin_dir_path)
3434
if origin_dir_path.exists() and origin_dir_path.is_dir():
3535
try:
@@ -48,7 +48,7 @@ def rename_dir(origin_dir_path, target_dir: str):
4848
f"target dir path: {target_dir}")
4949

5050

51-
def create_dir(dir_path: str):
51+
def create_dir(dir_path: str) -> None:
5252
dir_path = Path(dir_path)
5353
dir_path.mkdir(exist_ok=True)
5454
file_automation_logger.info(f"Create dir {dir_path}")

file_automation/local/file/file_process.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from file_automation.utils.logging.loggin_instance import file_automation_logger
77

88

9-
def copy_file(file_path: str, target_path: str):
9+
def copy_file(file_path: str, target_path: str) -> None:
1010
file_path = Path(file_path)
1111
if file_path.is_file() and file_path.exists():
1212
try:
@@ -18,7 +18,7 @@ def copy_file(file_path: str, target_path: str):
1818
file_automation_logger.error(f"Copy file failed: {repr(FileNotExistsException)}")
1919

2020

21-
def copy_specify_extension_file(file_dir_path: str, target_extension: str, target_path: str):
21+
def copy_specify_extension_file(file_dir_path: str, target_extension: str, target_path: str) -> None:
2222
file_dir_path = Path(file_dir_path)
2323
if file_dir_path.exists() and file_dir_path.is_dir():
2424
for file in file_dir_path.glob(f"**/*.{target_extension}"):
@@ -32,7 +32,7 @@ def copy_specify_extension_file(file_dir_path: str, target_extension: str, targe
3232
f"Copy specify extension file failed: {repr(FileNotExistsException)}")
3333

3434

35-
def copy_all_file_to_dir(dir_path: str, target_dir_path: str):
35+
def copy_all_file_to_dir(dir_path: str, target_dir_path: str) -> None:
3636
dir_path = Path(dir_path)
3737
target_dir_path = Path(target_dir_path)
3838
if dir_path.is_dir() and target_dir_path.is_dir():
@@ -54,7 +54,7 @@ def copy_all_file_to_dir(dir_path: str, target_dir_path: str):
5454
print(repr(DirNotExistsException), file=sys.stderr)
5555

5656

57-
def rename_file(origin_file_path, target_name: str, file_extension=None):
57+
def rename_file(origin_file_path, target_name: str, file_extension=None) -> None:
5858
origin_file_path = Path(origin_file_path)
5959
if origin_file_path.exists() and origin_file_path.is_dir():
6060
if file_extension is None:
@@ -81,8 +81,13 @@ def rename_file(origin_file_path, target_name: str, file_extension=None):
8181
f"Rename file failed, error: {repr(DirNotExistsException)}")
8282

8383

84-
def remove_file(file_path: str):
84+
def remove_file(file_path: str) -> None:
8585
file_path = Path(file_path)
8686
if file_path.exists() and file_path.is_file():
8787
file_path.unlink(missing_ok=True)
8888
file_automation_logger.info(f"Remove file, file path: {file_path}")
89+
90+
91+
def create_file(file_path: str, content: str) -> None:
92+
with open(file_path, "w+") as file:
93+
file.write(content)

file_automation/local/zip/zip_process.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from file_automation.utils.logging.loggin_instance import file_automation_logger
88

99

10-
def zip_dir(dir_we_want_to_zip: str, zip_name: str):
10+
def zip_dir(dir_we_want_to_zip: str, zip_name: str) -> None:
1111
make_archive(root_dir=dir_we_want_to_zip, base_name=zip_name, format="zip")
1212
file_automation_logger.info(f"Dir to zip: {dir_we_want_to_zip}, zip file name: {zip_name}")
1313

1414

15-
def zip_file(zip_file_path: str, file: [str, List[str]]):
15+
def zip_file(zip_file_path: str, file: [str, List[str]]) -> None:
1616
current_zip = zipfile.ZipFile(zip_file_path, mode="w")
1717
if isinstance(file, str):
1818
file_name = Path(file)
@@ -34,7 +34,7 @@ def zip_file(zip_file_path: str, file: [str, List[str]]):
3434
current_zip.close()
3535

3636

37-
def read_zip_file(zip_file_path: str, file_name: str, password: [str, None] = None):
37+
def read_zip_file(zip_file_path: str, file_name: str, password: [str, None] = None) -> None:
3838
current_zip = zipfile.ZipFile(zip_file_path, mode="r")
3939
with current_zip.open(name=file_name, mode="r", pwd=password, force_zip64=True) as read_file:
4040
data = read_file.read()
@@ -45,7 +45,8 @@ def read_zip_file(zip_file_path: str, file_name: str, password: [str, None] = No
4545
return data
4646

4747

48-
def unzip_file(zip_file_path: str, extract_member, extract_path: [str, None] = None, password: [str, None] = None):
48+
def unzip_file(
49+
zip_file_path: str, extract_member, extract_path: [str, None] = None, password: [str, None] = None) -> None:
4950
current_zip = zipfile.ZipFile(zip_file_path, mode="r")
5051
current_zip.extract(member=extract_member, path=extract_path, pwd=password)
5152
file_automation_logger.info(
@@ -59,7 +60,7 @@ def unzip_file(zip_file_path: str, extract_member, extract_path: [str, None] = N
5960

6061
def unzip_all(
6162
zip_file_path: str, extract_member: [str, None] = None,
62-
extract_path: [str, None] = None, password: [str, None] = None):
63+
extract_path: [str, None] = None, password: [str, None] = None) -> None:
6364
current_zip = zipfile.ZipFile(zip_file_path, mode="r")
6465
current_zip.extractall(members=extract_member, path=extract_path, pwd=password)
6566
file_automation_logger.info(
@@ -71,7 +72,7 @@ def unzip_all(
7172
current_zip.close()
7273

7374

74-
def zip_info(zip_file_path: str):
75+
def zip_info(zip_file_path: str) -> None:
7576
current_zip = zipfile.ZipFile(zip_file_path, mode="r")
7677
info_list = current_zip.infolist()
7778
current_zip.close()
@@ -81,7 +82,7 @@ def zip_info(zip_file_path: str):
8182
return info_list
8283

8384

84-
def zip_file_info(zip_file_path: str):
85+
def zip_file_info(zip_file_path: str) -> None:
8586
current_zip = zipfile.ZipFile(zip_file_path, mode="r")
8687
name_list = current_zip.namelist()
8788
current_zip.close()
@@ -91,7 +92,7 @@ def zip_file_info(zip_file_path: str):
9192
return name_list
9293

9394

94-
def set_zip_password(zip_file_path: str, password: bytes):
95+
def set_zip_password(zip_file_path: str, password: bytes) -> None:
9596
current_zip = zipfile.ZipFile(zip_file_path)
9697
current_zip.setpassword(pwd=password)
9798
current_zip.close()

file_automation/remote/google_drive/delete/delete_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import Union
1+
from typing import Union, Dict
22

33
from googleapiclient.errors import HttpError
44

55
from file_automation.remote.google_drive.driver_instance import driver_instance
66
from file_automation.utils.logging.loggin_instance import file_automation_logger
77

88

9-
def delete_file(file_id: str) -> Union[dict, None]:
9+
def drive_delete_file(file_id: str) -> Union[Dict[str, str], None]:
1010
try:
1111
file = driver_instance.service.files().delete(fileId=file_id).execute()
1212
file_automation_logger.info(f"Delete drive file: {file_id}")

file_automation/remote/google_drive/dir/folder_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from file_automation.utils.logging.loggin_instance import file_automation_logger
77

88

9-
def add_folder(folder_name: str) -> Union[dict, None]:
9+
def drive_add_folder(folder_name: str) -> Union[dict, None]:
1010
try:
1111
file_metadata = {
1212
"name": folder_name,

file_automation/remote/google_drive/download/download_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from file_automation.utils.logging.loggin_instance import file_automation_logger
1010

1111

12-
def download_file(file_id: str, file_name: str) -> BytesIO:
12+
def drive_download_file(file_id: str, file_name: str) -> BytesIO:
1313
try:
1414
request = driver_instance.service.files().get_media(fileId=file_id)
1515
file = io.BytesIO()
@@ -34,7 +34,7 @@ def download_file(file_id: str, file_name: str) -> BytesIO:
3434
return file
3535

3636

37-
def download_file_from_folder(folder_name: str) -> Union[dict, None]:
37+
def drive_download_file_from_folder(folder_name: str) -> Union[dict, None]:
3838
try:
3939
files = dict()
4040
response = driver_instance.service.files().list(
@@ -46,7 +46,7 @@ def download_file_from_folder(folder_name: str) -> Union[dict, None]:
4646
q=f"'{folder_id}' in parents"
4747
).execute()
4848
for file in response.get("files", []):
49-
download_file(file.get("id"), file.get("name"))
49+
drive_download_file(file.get("id"), file.get("name"))
5050
files.update({file.get("name"): file.get("id")})
5151
file_automation_logger.info(
5252
f"Download all file on {folder_name} done."

file_automation/remote/google_drive/search/search_drive.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from file_automation.utils.logging.loggin_instance import file_automation_logger
77

88

9-
def search_all_file() -> Union[dict, None]:
9+
def drive_search_all_file() -> Union[dict, None]:
1010
try:
1111
item = dict()
1212
response = driver_instance.service.files().list().execute()
@@ -24,7 +24,7 @@ def search_all_file() -> Union[dict, None]:
2424
return None
2525

2626

27-
def search_file_mimetype(mime_type: str) -> Union[dict, None]:
27+
def drive_search_file_mimetype(mime_type: str) -> Union[dict, None]:
2828
try:
2929
files = dict()
3030
page_token = None
@@ -51,7 +51,7 @@ def search_file_mimetype(mime_type: str) -> Union[dict, None]:
5151
return None
5252

5353

54-
def search_field(field_pattern: str) -> Union[dict, None]:
54+
def drive_search_field(field_pattern: str) -> Union[dict, None]:
5555
try:
5656
files = dict()
5757
response = driver_instance.service.files().list(fields=field_pattern).execute()

file_automation/remote/google_drive/share/share_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from file_automation.utils.logging.loggin_instance import file_automation_logger
77

88

9-
def share_file_to_user(
9+
def drive_share_file_to_user(
1010
file_id: str, user: str, user_role: str = "writer") -> Union[dict, None]:
1111
try:
1212
service = driver_instance.service
@@ -32,7 +32,7 @@ def share_file_to_user(
3232
return None
3333

3434

35-
def share_file_to_anyone(file_id: str, share_role: str = "reader") -> Union[dict, None]:
35+
def drive_share_file_to_anyone(file_id: str, share_role: str = "reader") -> Union[dict, None]:
3636
try:
3737
service = driver_instance.service
3838
user_permission = {
@@ -55,7 +55,7 @@ def share_file_to_anyone(file_id: str, share_role: str = "reader") -> Union[dict
5555
return None
5656

5757

58-
def share_file_to_domain(
58+
def drive_share_file_to_domain(
5959
file_id: str, domain: str, domain_role: str = "reader") -> Union[dict, None]:
6060
try:
6161
service = driver_instance.service

0 commit comments

Comments
 (0)