Skip to content

Commit a4de745

Browse files
committed
Update dev and stable version and refactor
Update dev and stable version and refactor
1 parent d1962cf commit a4de745

7 files changed

Lines changed: 25 additions & 22 deletions

File tree

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

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: 6 additions & 6 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,13 +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}")
8989

9090

91-
def create_file(file_path: str, content: str):
91+
def create_file(file_path: str, content: str) -> None:
9292
with open(file_path, "w+") as file:
9393
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 drive_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/utils/executor/action_executor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
copy_all_file_to_dir, create_file
88
from file_automation.local.zip.zip_process import zip_dir, zip_file, zip_info, zip_file_info, set_zip_password, \
99
read_zip_file, unzip_file, unzip_all
10+
from file_automation.remote.google_drive.driver_instance import driver_instance
1011
from file_automation.remote.google_drive.delete.delete_manager import drive_delete_file
1112
from file_automation.remote.google_drive.dir.folder_manager import drive_add_folder
1213
from file_automation.remote.google_drive.download.download_file import drive_download_file, \
@@ -50,6 +51,7 @@ def __init__(self):
5051
"read_zip_file": read_zip_file,
5152
"unzip_all": unzip_all,
5253
# Drive
54+
"drive_later_init": driver_instance.later_init,
5355
"drive_search_all_file": drive_search_all_file,
5456
"drive_search_field": drive_search_field,
5557
"drive_search_file_mimetype": drive_search_file_mimetype,

pyproject.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"
9-
version = "0.0.9"
9+
version = "0.0.10"
1010
authors = [
1111
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
1212
]

0 commit comments

Comments
 (0)