diff --git a/dev.toml b/dev.toml index 3e44f94..2b44d63 100644 --- a/dev.toml +++ b/dev.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "automation_file_dev" -version = "0.0.4" +version = "0.0.6" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ] diff --git a/file_automation/__init__.py b/file_automation/__init__.py index e6017f9..67d9eb7 100644 --- a/file_automation/__init__.py +++ b/file_automation/__init__.py @@ -5,10 +5,22 @@ read_zip_file, unzip_file, unzip_all from file_automation.remote.google_drive.driver_instance import driver_instance +from file_automation.remote.google_drive.search.search_drive import \ + search_all_file, search_field, search_file_mimetype +from file_automation.remote.google_drive.upload.upload_to_driver import \ + upload_dir_to_folder, upload_to_folder, upload_dir_to_drive, upload_to_drive +from file_automation.remote.google_drive.dir.folder_manager import add_folder +from file_automation.remote.google_drive.share.share_file import \ + share_file_to_anyone, share_file_to_domain, share_file_to_user +from file_automation.remote.google_drive.delete.delete_manager import delete_file +from file_automation.remote.google_drive.download.download_file import download_file, download_file_from_folder __all__ = [ "copy_file", "rename_file", "remove_file", "copy_all_file_to_dir", "copy_specify_extension_file", "copy_dir", "create_dir", "copy_specify_extension_file", "remove_dir_tree", "zip_dir", "zip_file", "zip_info", "zip_file_info", "set_zip_password", "unzip_file", "read_zip_file", - "unzip_all", "driver_instance", + "unzip_all", "driver_instance", "search_all_file", "search_field", "search_file_mimetype", + "upload_dir_to_folder", "upload_to_folder", "upload_dir_to_drive", "upload_to_drive", + "add_folder", "share_file_to_anyone", "share_file_to_domain", "share_file_to_user", + "delete_file", "download_file", "download_file_from_folder" ] diff --git a/file_automation/local/dir/dir_process.py b/file_automation/local/dir/dir_process.py index 3926702..114771a 100644 --- a/file_automation/local/dir/dir_process.py +++ b/file_automation/local/dir/dir_process.py @@ -1,9 +1,9 @@ -import os import shutil import sys from pathlib import Path from file_automation.utils.exception.exceptions import DirNotExistsException +from file_automation.utils.logging.loggin_instance import file_automation_logger def copy_dir(dir_path: str, target_dir_path: str): @@ -12,10 +12,11 @@ def copy_dir(dir_path: str, target_dir_path: str): if dir_path.is_dir(): try: shutil.copytree(dir_path, target_dir_path, dirs_exist_ok=True) + file_automation_logger.info(f"Copy dir {dir_path}") except shutil.Error as error: - print(repr(error)) + file_automation_logger.error(f"Copy dir {dir_path} failed: {repr(error)}") else: - print(repr(DirNotExistsException), file=sys.stderr) + file_automation_logger.error(f"Copy dir {dir_path} failed: {repr(DirNotExistsException)}") def remove_dir_tree(dir_path: str): @@ -23,8 +24,9 @@ def remove_dir_tree(dir_path: str): if dir_path.is_dir(): try: shutil.rmtree(dir_path) + file_automation_logger.info(f"Remove dir tree {dir_path}") except shutil.Error as error: - print(repr(error)) + file_automation_logger.error(f"Remove dir tree {dir_path} error: {repr(error)}") def rename_dir(origin_dir_path, target_dir: str): @@ -32,12 +34,21 @@ def rename_dir(origin_dir_path, target_dir: str): if origin_dir_path.exists() and origin_dir_path.is_dir(): try: Path.rename(origin_dir_path, target_dir) + file_automation_logger.info( + f"Rename dir origin dir path: {origin_dir_path}, target dir path: {target_dir}") except Exception as error: - print(repr(error)) + file_automation_logger.error( + f"Rename dir error: {repr(error)}, " + f"Rename dir origin dir path: {origin_dir_path}, " + f"target dir path: {target_dir}") else: - print(repr(DirNotExistsException), file=sys.stderr) + file_automation_logger.error( + f"Rename dir error: {repr(DirNotExistsException)}, " + f"Rename dir origin dir path: {origin_dir_path}, " + f"target dir path: {target_dir}") def create_dir(dir_path: str): dir_path = Path(dir_path) dir_path.mkdir(exist_ok=True) + file_automation_logger.info(f"Create dir {dir_path}") diff --git a/file_automation/local/file/file_process.py b/file_automation/local/file/file_process.py index 83e3066..4479fcc 100644 --- a/file_automation/local/file/file_process.py +++ b/file_automation/local/file/file_process.py @@ -3,6 +3,7 @@ from pathlib import Path from file_automation.utils.exception.exceptions import FileNotExistsException, DirNotExistsException +from file_automation.utils.logging.loggin_instance import file_automation_logger def copy_file(file_path: str, target_path: str): @@ -10,10 +11,11 @@ def copy_file(file_path: str, target_path: str): if file_path.is_file() and file_path.exists(): try: shutil.copy2(file_path, target_path) + file_automation_logger.info(f"Copy file origin path: {file_path}, target path : {target_path}") except shutil.Error as error: - print(repr(error)) + file_automation_logger.error(f"Copy file failed: {repr(error)}") else: - print(repr(FileNotExistsException), file=sys.stderr) + file_automation_logger.error(f"Copy file failed: {repr(FileNotExistsException)}") def copy_specify_extension_file(file_dir_path: str, target_extension: str, target_path: str): @@ -21,8 +23,13 @@ def copy_specify_extension_file(file_dir_path: str, target_extension: str, targe if file_dir_path.exists() and file_dir_path.is_dir(): for file in file_dir_path.glob(f"**/*.{target_extension}"): copy_file(str(file), target_path) + file_automation_logger.info( + f"Copy specify extension file on dir" + f"origin dir path: {file_dir_path}, target extension: {target_extension}, " + f"to target path {target_path}") else: - print(repr(DirNotExistsException), file=sys.stderr) + file_automation_logger.error( + f"Copy specify extension file failed: {repr(FileNotExistsException)}") def copy_all_file_to_dir(dir_path: str, target_dir_path: str): @@ -31,8 +38,18 @@ def copy_all_file_to_dir(dir_path: str, target_dir_path: str): if dir_path.is_dir() and target_dir_path.is_dir(): try: shutil.move(str(dir_path), str(target_dir_path)) + file_automation_logger.info( + f"Copy all file to dir, " + f"origin dir: {dir_path}, " + f"target dir: {target_dir_path}" + ) except shutil.Error as error: - print(repr(error), file=sys.stderr) + file_automation_logger.error( + f"Copy all file to dir failed, " + f"origin dir: {dir_path}, " + f"target dir: {target_dir_path}, " + f"error: {repr(error)}" + ) else: print(repr(DirNotExistsException), file=sys.stderr) @@ -49,13 +66,23 @@ def rename_file(origin_file_path, target_name: str, file_extension=None): for file in file_list: file.rename(Path(origin_file_path, target_name)) file_index = file_index + 1 + file_automation_logger.info( + f"Renamed file: origin file path:{origin_file_path}, with new name: {target_name}") except Exception as error: - print(repr(error)) + file_automation_logger.error( + f"Rename file failed, " + f"origin file path: {origin_file_path}, " + f"target name: {target_name}, " + f"file_extension: {file_extension}, " + f"error: {repr(error)}" + ) else: - print(repr(DirNotExistsException), file=sys.stderr) + file_automation_logger.error( + f"Rename file failed, error: {repr(DirNotExistsException)}") def remove_file(file_path: str): file_path = Path(file_path) if file_path.exists() and file_path.is_file(): file_path.unlink(missing_ok=True) + file_automation_logger.info(f"Remove file, file path: {file_path}") diff --git a/file_automation/local/zip/zip_process.py b/file_automation/local/zip/zip_process.py index 112e53a..4e03176 100644 --- a/file_automation/local/zip/zip_process.py +++ b/file_automation/local/zip/zip_process.py @@ -1,14 +1,15 @@ -import sys import zipfile from pathlib import Path from shutil import make_archive from typing import List from file_automation.utils.exception.exceptions import ZIPGetWrongFileException +from file_automation.utils.logging.loggin_instance import file_automation_logger def zip_dir(dir_we_want_to_zip: str, zip_name: str): make_archive(root_dir=dir_we_want_to_zip, base_name=zip_name, format="zip") + file_automation_logger.info(f"Dir to zip: {dir_we_want_to_zip}, zip file name: {zip_name}") def zip_file(zip_file_path: str, file: [str, List[str]]): @@ -16,28 +17,43 @@ def zip_file(zip_file_path: str, file: [str, List[str]]): if isinstance(file, str): file_name = Path(file) current_zip.write(file, file_name.name) + file_automation_logger.info( + f"Write file: {file_name} to zip: {current_zip}" + ) else: if isinstance(file, list): for writeable in file: file_name = Path(writeable) current_zip.write(writeable, file_name.name) + file_automation_logger.info( + f"Write file: {writeable} to zip: {current_zip}" + ) else: - print(repr(ZIPGetWrongFileException), file=sys.stderr) + file_automation_logger.error( + repr(ZIPGetWrongFileException)) current_zip.close() def read_zip_file(zip_file_path: str, file_name: str, password: [str, None] = None): current_zip = zipfile.ZipFile(zip_file_path, mode="r") - data = None with current_zip.open(name=file_name, mode="r", pwd=password, force_zip64=True) as read_file: data = read_file.read() current_zip.close() + file_automation_logger.info( + f"Read zip file: {zip_file_path}" + ) return data def unzip_file(zip_file_path: str, extract_member, extract_path: [str, None] = None, password: [str, None] = None): current_zip = zipfile.ZipFile(zip_file_path, mode="r") current_zip.extract(member=extract_member, path=extract_path, pwd=password) + file_automation_logger.info( + f"Unzip file: {zip_file_path}, " + f"extract member: {extract_member}, " + f"extract path: {extract_path}, " + f"password: {password}" + ) current_zip.close() @@ -46,6 +62,12 @@ def unzip_all( extract_path: [str, None] = None, password: [str, None] = None): current_zip = zipfile.ZipFile(zip_file_path, mode="r") current_zip.extractall(members=extract_member, path=extract_path, pwd=password) + file_automation_logger.info( + f"Unzip file: {zip_file_path}, " + f"extract member: {extract_member}, " + f"extract path: {extract_path}, " + f"password: {password}" + ) current_zip.close() @@ -53,6 +75,9 @@ def zip_info(zip_file_path: str): current_zip = zipfile.ZipFile(zip_file_path, mode="r") info_list = current_zip.infolist() current_zip.close() + file_automation_logger.info( + f"Show zip info: {zip_file_path}" + ) return info_list @@ -60,6 +85,9 @@ def zip_file_info(zip_file_path: str): current_zip = zipfile.ZipFile(zip_file_path, mode="r") name_list = current_zip.namelist() current_zip.close() + file_automation_logger.info( + f"Show zip file info: {zip_file_path}" + ) return name_list @@ -67,3 +95,8 @@ def set_zip_password(zip_file_path: str, password: bytes): current_zip = zipfile.ZipFile(zip_file_path) current_zip.setpassword(pwd=password) current_zip.close() + file_automation_logger.info( + f"Set zip file password, " + f"zip file: {zip_file_path}, " + f"zup password: {password}" + ) diff --git a/file_automation/remote/google_drive/delete/delete_manager.py b/file_automation/remote/google_drive/delete/delete_manager.py index 623f3cd..9206cde 100644 --- a/file_automation/remote/google_drive/delete/delete_manager.py +++ b/file_automation/remote/google_drive/delete/delete_manager.py @@ -1,12 +1,19 @@ +from typing import Union + from googleapiclient.errors import HttpError from file_automation.remote.google_drive.driver_instance import driver_instance +from file_automation.utils.logging.loggin_instance import file_automation_logger -def delete_file(file_id: str): +def delete_file(file_id: str) -> Union[dict, None]: try: file = driver_instance.service.files().delete(fileId=file_id).execute() + file_automation_logger.info(f"Delete drive file: {file_id}") return file except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None diff --git a/file_automation/remote/google_drive/dir/folder_manager.py b/file_automation/remote/google_drive/dir/folder_manager.py index 90a5b20..72e45b7 100644 --- a/file_automation/remote/google_drive/dir/folder_manager.py +++ b/file_automation/remote/google_drive/dir/folder_manager.py @@ -1,9 +1,12 @@ +from typing import Union + from googleapiclient.errors import HttpError from file_automation.remote.google_drive.driver_instance import driver_instance +from file_automation.utils.logging.loggin_instance import file_automation_logger -def add_folder(folder_name: str): +def add_folder(folder_name: str) -> Union[dict, None]: try: file_metadata = { "name": folder_name, @@ -13,7 +16,13 @@ def add_folder(folder_name: str): body=file_metadata, fields="id" ).execute() + file_automation_logger.info( + f"Add drive folder: {folder_name}" + ) return file.get("id") except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None diff --git a/file_automation/remote/google_drive/download/download_file.py b/file_automation/remote/google_drive/download/download_file.py index 1c19395..5e1f389 100644 --- a/file_automation/remote/google_drive/download/download_file.py +++ b/file_automation/remote/google_drive/download/download_file.py @@ -1,12 +1,15 @@ import io +from io import BytesIO +from typing import Union from googleapiclient.errors import HttpError from googleapiclient.http import MediaIoBaseDownload from file_automation.remote.google_drive.driver_instance import driver_instance +from file_automation.utils.logging.loggin_instance import file_automation_logger -def download_file(file_id: str, file_name: str): +def download_file(file_id: str, file_name: str) -> BytesIO: try: request = driver_instance.service.files().get_media(fileId=file_id) file = io.BytesIO() @@ -14,16 +17,24 @@ def download_file(file_id: str, file_name: str): done = False while done is False: status, done = downloader.next_chunk() - print(f"Download {file_name} {int(status.progress() * 100)}%.") + file_automation_logger.info( + f"Download {file_name} {int(status.progress() * 100)}%." + ) except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None with open(file_name, "wb") as output_file: output_file.write(file.getbuffer()) + file_automation_logger.info( + f"Download file: {file_id} with name: {file_name}" + ) return file -def download_file_from_folder(folder_name: str): +def download_file_from_folder(folder_name: str) -> Union[dict, None]: try: files = dict() response = driver_instance.service.files().list( @@ -37,7 +48,13 @@ def download_file_from_folder(folder_name: str): for file in response.get("files", []): download_file(file.get("id"), file.get("name")) files.update({file.get("name"): file.get("id")}) + file_automation_logger.info( + f"Download all file on {folder_name} done." + ) return files except HttpError as error: - print(f"An error occurred: {error}") - return None \ No newline at end of file + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) + return None diff --git a/file_automation/remote/google_drive/driver_instance.py b/file_automation/remote/google_drive/driver_instance.py index 4cf48bd..274c42a 100644 --- a/file_automation/remote/google_drive/driver_instance.py +++ b/file_automation/remote/google_drive/driver_instance.py @@ -6,14 +6,18 @@ from googleapiclient.discovery import build from googleapiclient.errors import HttpError +from file_automation.utils.logging.loggin_instance import file_automation_logger + class GoogleDrive(object): - def __init__(self, token_path: str, credentials_path: str): + def __init__(self): self.google_drive_instance = None self.creds = None self.service = None self.scopes = ["https://www.googleapis.com/auth/drive"] + + def later_init(self, token_path: str, credentials_path: str): token_path = Path(token_path) credentials_path = Path(credentials_path) creds = None @@ -21,6 +25,9 @@ def __init__(self, token_path: str, credentials_path: str): # created automatically when the authorization flow completes for the first # time. if token_path.exists(): + file_automation_logger.info( + f"Token exists try to load." + ) creds = Credentials.from_authorized_user_file(str(token_path), self.scopes) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: @@ -33,11 +40,17 @@ def __init__(self, token_path: str, credentials_path: str): # Save the credentials for the next run with open(str(token_path), 'w') as token: token.write(creds.to_json()) - try: self.service = build('drive', 'v3', credentials=creds) + file_automation_logger.info( + f"Loading service successfully." + ) except HttpError as error: - print(f'An error occurred: {error}') + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) + +driver_instance = GoogleDrive() -driver_instance = GoogleDrive(str(Path(Path.cwd(), "token.json")), str(Path(Path.cwd(), "credentials.json"))) diff --git a/file_automation/remote/google_drive/search/search_drive.py b/file_automation/remote/google_drive/search/search_drive.py index 3c91496..329bc4d 100644 --- a/file_automation/remote/google_drive/search/search_drive.py +++ b/file_automation/remote/google_drive/search/search_drive.py @@ -1,21 +1,30 @@ +from typing import Union + from googleapiclient.errors import HttpError from file_automation.remote.google_drive.driver_instance import driver_instance +from file_automation.utils.logging.loggin_instance import file_automation_logger -def search_all_file(): +def search_all_file() -> Union[dict, None]: try: item = dict() response = driver_instance.service.files().list().execute() for file in response.get("files", []): item.update({file.get("name"): file.get("id")}) + file_automation_logger.info( + f"Search all file on drive" + ) return item except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None -def search_file_mimetype(mime_type: str): +def search_file_mimetype(mime_type: str) -> Union[dict, None]: try: files = dict() page_token = None @@ -30,20 +39,32 @@ def search_file_mimetype(mime_type: str): page_token = response.get('nextPageToken', None) if page_token is None: break + file_automation_logger.info( + f"Search all {mime_type} file on drive" + ) return files except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None -def search_field(field_pattern: str): +def search_field(field_pattern: str) -> Union[dict, None]: try: files = dict() response = driver_instance.service.files().list(fields=field_pattern).execute() for file in response.get("files", []): files.update({file.get("name"): file.get("id")}) + file_automation_logger.info( + f"Search all {field_pattern}" + ) return files except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None diff --git a/file_automation/remote/google_drive/share/share_file.py b/file_automation/remote/google_drive/share/share_file.py index d5b4022..fd49137 100644 --- a/file_automation/remote/google_drive/share/share_file.py +++ b/file_automation/remote/google_drive/share/share_file.py @@ -1,10 +1,13 @@ +from typing import Union + from googleapiclient.errors import HttpError from file_automation.remote.google_drive.driver_instance import driver_instance +from file_automation.utils.logging.loggin_instance import file_automation_logger def share_file_to_user( - file_id: str, user: str, user_role: str = "writer"): + file_id: str, user: str, user_role: str = "writer") -> Union[dict, None]: try: service = driver_instance.service user_permission = { @@ -12,16 +15,24 @@ def share_file_to_user( "role": user_role, "emailAddress": user } + file_automation_logger.info( + f"Share file: {file_id}, " + f"to user: {user}, " + f"with user role: {user_role}" + ) return service.permissions().create( fileId=file_id, body=user_permission, fields='id', ).execute() except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None -def share_file_to_anyone(file_id: str, share_role: str = "reader"): +def share_file_to_anyone(file_id: str, share_role: str = "reader") -> Union[dict, None]: try: service = driver_instance.service user_permission = { @@ -29,17 +40,23 @@ def share_file_to_anyone(file_id: str, share_role: str = "reader"): "value": "anyone", "role": share_role } + file_automation_logger.info( + f"Share file to anyone file: {file_id} with role: {share_role}" + ) return service.permissions().create( fileId=file_id, body=user_permission, fields='id', ).execute() except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None def share_file_to_domain( - file_id: str, domain: str, domain_role: str = "reader"): + file_id: str, domain: str, domain_role: str = "reader") -> Union[dict, None]: try: service = driver_instance.service domain_permission = { @@ -47,10 +64,17 @@ def share_file_to_domain( "role": domain_role, "domain": domain } + file_automation_logger.info( + f"Share file to domain: {domain}, " + f"with domain role: {domain_role}" + ) return service.permissions().create( fileId=file_id, body=domain_permission, fields='id', ).execute() except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None diff --git a/file_automation/remote/google_drive/upload/upload_to_driver.py b/file_automation/remote/google_drive/upload/upload_to_driver.py index 8f99b38..c420449 100644 --- a/file_automation/remote/google_drive/upload/upload_to_driver.py +++ b/file_automation/remote/google_drive/upload/upload_to_driver.py @@ -1,12 +1,14 @@ from pathlib import Path +from typing import List, Union, Optional from googleapiclient.errors import HttpError from googleapiclient.http import MediaFileUpload from file_automation.remote.google_drive.driver_instance import driver_instance +from file_automation.utils.logging.loggin_instance import file_automation_logger -def upload_to_drive(file_path: str, file_name: str = None): +def upload_to_drive(file_path: str, file_name: str = None) -> Union[dict, None]: try: file_path = Path(file_path) if file_path.is_file(): @@ -24,15 +26,24 @@ def upload_to_drive(file_path: str, file_name: str = None): media_body=media, fields="id" ).execute() + file_automation_logger.info( + f"Upload file to drive file: {file_path}, " + f"with name: {file_name}" + ) return file_id else: - raise FileNotFoundError + file_automation_logger.error( + FileNotFoundError + ) except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None -def upload_to_folder(folder_id: str, file_path: str, file_name: str = None): +def upload_to_folder(folder_id: str, file_path: str, file_name: str = None) -> Union[dict, None]: try: file_path = Path(file_path) if file_path.is_file(): @@ -51,15 +62,25 @@ def upload_to_folder(folder_id: str, file_path: str, file_name: str = None): media_body=media, fields="id" ).execute() + file_automation_logger.info( + f"Upload file to folder: {folder_id}," + f"file_path: {file_path}, " + f"with name: {file_name}" + ) return file_id else: - raise FileNotFoundError + file_automation_logger.error( + FileNotFoundError + ) except HttpError as error: - print(f"An error occurred: {error}") + file_automation_logger.error( + f"Delete file failed," + f"error: {error}" + ) return None -def upload_dir_to_drive(dir_path: str): +def upload_dir_to_drive(dir_path: str) -> List[Optional[set]]: dir_path = Path(dir_path) ids = list() if dir_path.is_dir(): @@ -67,12 +88,17 @@ def upload_dir_to_drive(dir_path: str): for path in path_list: if path.is_file(): ids.append(upload_to_drive(str(path.absolute()), path.name)) + file_automation_logger.info( + f"Upload all file on dir: {dir_path} to drive" + ) return ids else: - raise FileNotFoundError + file_automation_logger.error( + FileNotFoundError + ) -def upload_dir_to_folder(folder_id: str, dir_path: str): +def upload_dir_to_folder(folder_id: str, dir_path: str) -> List[Optional[set]]: dir_path = Path(dir_path) ids = list() if dir_path.is_dir(): @@ -80,6 +106,11 @@ def upload_dir_to_folder(folder_id: str, dir_path: str): for path in path_list: if path.is_file(): ids.append(upload_to_folder(folder_id, str(path.absolute()), path.name)) + file_automation_logger.info( + f"Upload all file on dir: {dir_path} to folder: {folder_id}" + ) return ids else: - raise FileNotFoundError + file_automation_logger.error( + FileNotFoundError + ) diff --git a/file_automation/utils/logging/__init__.py b/file_automation/utils/logging/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/file_automation/utils/logging/loggin_instance.py b/file_automation/utils/logging/loggin_instance.py new file mode 100644 index 0000000..cc8746a --- /dev/null +++ b/file_automation/utils/logging/loggin_instance.py @@ -0,0 +1,9 @@ +import logging + +logging.getLogger().setLevel(logging.INFO) +file_automation_logger = logging.getLogger("File Automation") +handler = logging.StreamHandler() +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +handler.setFormatter(formatter) +file_automation_logger.addHandler(handler) +file_automation_logger.setLevel(logging.DEBUG) diff --git a/pyproject.toml b/pyproject.toml index 006e36b..467f09a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "automation_file" -version = "0.0.3" +version = "0.0.5" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ] diff --git a/tests/unit_test/remote/google_drive/quick_test.py b/tests/unit_test/remote/google_drive/quick_test.py index 4c249ae..882a38a 100644 --- a/tests/unit_test/remote/google_drive/quick_test.py +++ b/tests/unit_test/remote/google_drive/quick_test.py @@ -1,5 +1,7 @@ +from pathlib import Path + +from file_automation import driver_instance from file_automation.remote.google_drive.search.search_drive import search_all_file -from file_automation.remote.google_drive.upload.upload_to_driver import upload_dir_to_folder +driver_instance.later_init(str(Path(Path.cwd(), "token.json")), str(Path(Path.cwd(), "credentials.json"))) print(search_all_file()) -print(upload_dir_to_folder(r"1J-m5cHqkXumaHqlHfL90BySEqWsG9zbP", r"C:\Users\JeffreyChen\Desktop\Paper"))