Skip to content

Commit

Permalink
Add image folder config
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkjin99 committed Feb 25, 2024
1 parent 478bb07 commit faf7ca2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
Empty file added obs3dian/__init__.py
Empty file.
19 changes: 14 additions & 5 deletions obs3dian/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,18 @@ def config():
output_path = default_input("Output Path", "./output")
output_path = _convert_path_absoulte(Path(output_path), False)

image_folder_path = default_input(
"Image Folder Path",
"./assets",
)
image_folder_path = _convert_path_absoulte(Path(image_folder_path), True)

json_data = {
"profile_name": profile_name,
"bucket_name": bucket_name,
"is_bucket_public": is_bucket_public,
"output_folder_path": output_path.name,
"output_folder_path": str(output_path),
"image_folder_path": str(image_folder_path),
}

app_dir_path = Path(APP_DIR_PATH) # create app setting folder
Expand Down Expand Up @@ -155,11 +162,13 @@ def run(user_input_path: Path):
output_folder_path = _convert_path_absoulte(Path(configs["output_folder_path"]))
s3 = S3(configs["profile_name"], configs["bucket_name"])

runner = create_obs3dian_runner(s3, output_folder_path) # create main function
runner = create_obs3dian_runner(
s3, Path(configs["image_folder_path"]), output_folder_path
) # create main function

if user_input_path.is_dir():
markdown_file_paths = [
file_path for file_path in user_input_path.rglob("**/*.md")
markdown_path for markdown_path in user_input_path.rglob("**/*.md")
] # get all .md file under input dir
else:
markdown_file_paths = [user_input_path]
Expand Down Expand Up @@ -189,5 +198,5 @@ def run(user_input_path: Path):
typer.echo(f"Images successfully uploaded to S3\n")


# if __name__ == "__main__":
# app()
if __name__ == "__main__":
app()
10 changes: 7 additions & 3 deletions obs3dian/src/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import concurrent.futures
from pathlib import Path

from src.markdown import generate_local_paths, write_md_file
from src.markdown import generate_local_image_paths, write_md_file
from src.s3 import S3

from typing import Generator, Callable, List, Tuple
Expand Down Expand Up @@ -41,7 +41,9 @@ def put_images_in_md(
return put_image_paths


def create_obs3dian_runner(s3: S3, output_folder_path: Path) -> Callable:
def create_obs3dian_runner(
s3: S3, image_folder_path: Path, output_folder_path: Path
) -> Callable:
"""
Create runner fucntion object
S3 controller and ouput_folder_path would not change before config
Expand All @@ -61,7 +63,9 @@ def run(markdown_file_path: Path) -> None:
Args:
markdown_file_path (Path): mark down file path
"""
image_path_generator: Generator = generate_local_paths(markdown_file_path)
image_path_generator: Generator = generate_local_image_paths(
image_folder_path, markdown_file_path
)
markdown_file_name = markdown_file_path.stem

put_image_paths = put_images_in_md(s3, markdown_file_name, image_path_generator)
Expand Down
7 changes: 4 additions & 3 deletions obs3dian/src/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ def _get_image_names(markdown_file_path: Path) -> List[str]:
return image_names


def generate_local_paths(markdown_file_path: Path) -> Generator[Path, None, None]:
current_path = Path.cwd()
def generate_local_image_paths(
image_folder_path: Path, markdown_file_path: Path
) -> Generator[Path, None, None]:
image_names: list[str] = _get_image_names(markdown_file_path)
image_name_set = set(image_names)
suffixes = set((".png", ".jpg", ".jpeg", ".gif"))
for file_path in current_path.rglob("**/*"): # 모든 디렉토리 탐사
for file_path in image_folder_path.rglob("**/*"): # 모든 디렉토리 탐사
if (
file_path.suffix in suffixes and file_path.name in image_name_set
): # 파일 이름이 존재한다면
Expand Down

0 comments on commit faf7ca2

Please sign in to comment.