Skip to content

Commit 3c65bb5

Browse files
authored
Merge pull request #41 from Integration-Automation/dev
Dev
2 parents b4e9a57 + 87e2524 commit 3c65bb5

File tree

25 files changed

+956
-443
lines changed

25 files changed

+956
-443
lines changed

.github/workflows/file_automation_dev_python3_12.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: FileAutomation Dev Python3.9
1+
name: FileAutomation Dev Python3.12
22

33
on:
44
push:

.github/workflows/file_automation_stable_python3_12.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: FileAutomation Stable Python3.9
1+
name: FileAutomation Stable Python3.12
22

33
on:
44
push:

README.md

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,90 @@
1-
### FileAutomation
1+
# FileAutomation
22

3-
### Documentation
3+
This project provides a modular framework for file automation and Google Drive integration.
4+
It supports local file and directory operations, ZIP archive handling,
5+
Google Drive CRUD (create, search, upload, download, delete, share),
6+
and remote execution through a TCP Socket Server.
47

5-
* TODO
8+
# Features
9+
## Local File and Directory Operations
10+
- Create, delete, copy, and rename files
11+
- Create, delete, and copy directories
12+
- Recursively search for files by extension
613

7-
---
8-
> Project Kanban \
9-
> https://github.com/orgs/Integration-Automation/projects/2/views/1
10-
> * FileAutomation is used to manager files and dirs.
11-
> * Easily file automation.
12-
> * Automatically backup.
13-
> * Automatically download from Google Drive.
14-
> * Automatically upload to Google Drive.
15-
> * Automatically zip and unzip file.
16-
> * Automatically manager specify file.
17-
> * OS Independent.
18-
> * Remote automation support.
19-
> * Project & Template support.
20-
> * Detailed log file.
21-
> * Scheduler.
14+
## ZIP Archive Handling
15+
- Create ZIP archives
16+
- Extract single files or entire archives
17+
- Set ZIP archive passwords
18+
- Read archive information
19+
20+
## Google Drive Integration
21+
- Upload: single files, entire directories, to root or specific folders
22+
- Download: single files or entire folders
23+
- Search: by name, MIME type, or custom fields
24+
- Delete: remove files from Drive
25+
- Share: with specific users, domains, or via public link
26+
- Folder Management: create new folders in Drive
27+
28+
## Automation Executors
29+
- Executor: central manager for all executable functions, supports action lists
30+
- CallbackExecutor: supports callback functions for flexible workflows
31+
- PackageManager: dynamically loads packages and registers functions into executors
32+
33+
# JSON Configuration
34+
- Read and write JSON-based action lists
35+
- Define automation workflows in JSON format
36+
37+
# TCP Socket Server
38+
- Start a TCP server to receive JSON commands and execute corresponding actions
39+
- Supports remote control and returns execution results
40+
41+
## Installation and Requirements
42+
43+
- Requirements
44+
- Python 3.9+
45+
- Google API Client
46+
- Google Drive API enabled and credentials.json downloaded
2247

2348

2449
## install
2550
> pip install automation_file
2651
27-
## Requires
28-
> python 3.9 or later
52+
# Usage
53+
54+
1. Initialize Google Drive
55+
```python
56+
from automation_file.remote.google_drive.driver_instance import driver_instance
57+
58+
driver_instance.later_init("token.json", "credentials.json")
59+
```
60+
61+
2. Upload a File
62+
```python
63+
from automation_file.remote.google_drive.upload.upload_to_driver import drive_upload_to_drive
64+
65+
drive_upload_to_drive("example.txt")
66+
```
67+
68+
3. Search Files
69+
```python
70+
from automation_file.remote.google_drive.search.search_drive import drive_search_all_file
71+
72+
files = drive_search_all_file()
73+
print(files)
74+
```
75+
76+
4. Start TCP Server
77+
```python
78+
from automation_file.utils.socket_server.file_automation_socket_server import start_autocontrol_socket_server
79+
80+
server = start_autocontrol_socket_server("localhost", 9943)
81+
```
2982

30-
### Architecture Diagram
31-
![architecture_diagram](architecture_diagram/FileAutomation.drawio.png)
83+
# Example JSON Action
84+
```json
85+
[
86+
["FA_create_file", {"file_path": "test.txt"}],
87+
["FA_drive_upload_to_drive", {"file_path": "test.txt"}],
88+
["FA_drive_search_all_file"]
89+
]
90+
```
Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,113 @@
11
import shutil
22
from pathlib import Path
33

4+
# 匯入自訂例外與日誌工具
5+
# Import custom exception and logging utility
46
from automation_file.utils.exception.exceptions import DirNotExistsException
57
from automation_file.utils.logging.loggin_instance import file_automation_logger
68

79

810
def copy_dir(dir_path: str, target_dir_path: str) -> bool:
911
"""
10-
Copy dir to target path (path need as dir path)
11-
:param dir_path: which dir do we want to copy (str path)
12-
:param target_dir_path: copy dir to this path
13-
:return: True if success else False
12+
複製資料夾到目標路徑
13+
Copy directory to target path
14+
:param dir_path: 要複製的資料夾路徑 (str)
15+
Directory path to copy (str)
16+
:param target_dir_path: 複製到的目標資料夾路徑 (str)
17+
Target directory path (str)
18+
:return: 成功回傳 True,失敗回傳 False
19+
Return True if success, else False
1420
"""
15-
dir_path = Path(dir_path)
21+
dir_path = Path(dir_path) # 轉換為 Path 物件 / Convert to Path object
1622
target_dir_path = Path(target_dir_path)
17-
if dir_path.is_dir():
23+
if dir_path.is_dir(): # 確認來源是否為資料夾 / Check if source is a directory
1824
try:
25+
# 複製整個資料夾,若目標已存在則允許覆蓋
26+
# Copy entire directory, allow overwrite if target exists
1927
shutil.copytree(dir_path, target_dir_path, dirs_exist_ok=True)
2028
file_automation_logger.info(f"Copy dir {dir_path}")
2129
return True
2230
except shutil.Error as error:
31+
# 複製失敗時記錄錯誤
32+
# Log error if copy fails
2333
file_automation_logger.error(f"Copy dir {dir_path} failed: {repr(error)}")
2434
else:
35+
# 若來源資料夾不存在,記錄錯誤
36+
# Log error if source directory does not exist
2537
file_automation_logger.error(f"Copy dir {dir_path} failed: {repr(DirNotExistsException)}")
2638
return False
39+
return False
2740

2841

2942
def remove_dir_tree(dir_path: str) -> bool:
3043
"""
31-
:param dir_path: which dir do we want to remove (str path)
32-
:return: True if success else False
44+
刪除整個資料夾樹
45+
Remove entire directory tree
46+
:param dir_path: 要刪除的資料夾路徑 (str)
47+
Directory path to remove (str)
48+
:return: 成功回傳 True,失敗回傳 False
49+
Return True if success, else False
3350
"""
3451
dir_path = Path(dir_path)
35-
if dir_path.is_dir():
52+
if dir_path.is_dir(): # 確認是否為資料夾 / Check if directory exists
3653
try:
37-
shutil.rmtree(dir_path)
54+
shutil.rmtree(dir_path) # 遞迴刪除資料夾 / Recursively delete directory
3855
file_automation_logger.info(f"Remove dir tree {dir_path}")
3956
return True
4057
except shutil.Error as error:
4158
file_automation_logger.error(f"Remove dir tree {dir_path} error: {repr(error)}")
4259
return False
60+
return False
4361

4462

4563
def rename_dir(origin_dir_path, target_dir: str) -> bool:
4664
"""
47-
:param origin_dir_path: which dir do we want to rename (str path)
48-
:param target_dir: target name as str full path
49-
:return: True if success else False
65+
重新命名資料夾
66+
Rename directory
67+
:param origin_dir_path: 原始資料夾路徑 (str)
68+
Original directory path (str)
69+
:param target_dir: 新的完整路徑 (str)
70+
Target directory path (str)
71+
:return: 成功回傳 True,失敗回傳 False
72+
Return True if success, else False
5073
"""
5174
origin_dir_path = Path(origin_dir_path)
5275
if origin_dir_path.exists() and origin_dir_path.is_dir():
5376
try:
77+
# 使用 Path.rename 重新命名資料夾
78+
# Rename directory using Path.rename
5479
Path.rename(origin_dir_path, target_dir)
5580
file_automation_logger.info(
5681
f"Rename dir origin dir path: {origin_dir_path}, target dir path: {target_dir}")
5782
return True
5883
except Exception as error:
84+
# 捕捉所有例外並記錄
85+
# Catch all exceptions and log
5986
file_automation_logger.error(
6087
f"Rename dir error: {repr(error)}, "
6188
f"Rename dir origin dir path: {origin_dir_path}, "
6289
f"target dir path: {target_dir}")
6390
else:
91+
# 若來源資料夾不存在,記錄錯誤
92+
# Log error if source directory does not exist
6493
file_automation_logger.error(
6594
f"Rename dir error: {repr(DirNotExistsException)}, "
6695
f"Rename dir origin dir path: {origin_dir_path}, "
6796
f"target dir path: {target_dir}")
6897
return False
98+
return False
6999

70100

71101
def create_dir(dir_path: str) -> None:
72102
"""
73-
:param dir_path: create dir on dir_path
103+
建立資料夾
104+
Create directory
105+
:param dir_path: 要建立的資料夾路徑 (str)
106+
Directory path to create (str)
74107
:return: None
75108
"""
76109
dir_path = Path(dir_path)
110+
# 若資料夾已存在則不會報錯
111+
# Create directory, no error if already exists
77112
dir_path.mkdir(exist_ok=True)
78-
file_automation_logger.info(f"Create dir {dir_path}")
113+
file_automation_logger.info(f"Create dir {dir_path}")

0 commit comments

Comments
 (0)