add: regen parameter
This commit is contained in:
		
							
								
								
									
										25
									
								
								src/main.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/main.py
									
									
									
									
									
								
							| @ -7,13 +7,15 @@ from path import Path | |||||||
| from picture import Picture | from picture import Picture | ||||||
| from page import Page | from page import Page | ||||||
| from album import Album | from album import Album | ||||||
|  | import argparse | ||||||
| import config | import config | ||||||
|  |  | ||||||
| def argument_parsing(): | def argument_parsing(): | ||||||
|     if (len(sys.argv) < 2): |     parser = argparse.ArgumentParser() | ||||||
|         print("error: missing argument", file=sys.stderr) |     parser.add_argument("site_path", help="the folder of your site MUST BE ALWAYS BEFORT PARAMETERS", type=str) | ||||||
|         exit(1) |     parser.add_argument("-r", '--regen', help="Regenerate (t)thumb (s)small", type=str) | ||||||
|     return sys.argv[1] |     args = parser.parse_args() | ||||||
|  |     return args | ||||||
|  |  | ||||||
| def scan_pages(folders: list[Path]) -> list[Page]: | def scan_pages(folders: list[Path]) -> list[Page]: | ||||||
|     pages: list[Page] = [] |     pages: list[Page] = [] | ||||||
| @ -82,11 +84,22 @@ def gen_bulk(bulk_path: Path): | |||||||
|         shutil.move(os.path.join(album_path.get_absolute_path(), "general.html"), os.path.join(bulk_path.get_absolute_path(), "index.html")) |         shutil.move(os.path.join(album_path.get_absolute_path(), "general.html"), os.path.join(bulk_path.get_absolute_path(), "index.html")) | ||||||
|     shutil.copy2("./src/templates/album.css", bulk_path.get_absolute_path()) |     shutil.copy2("./src/templates/album.css", bulk_path.get_absolute_path()) | ||||||
|  |  | ||||||
|  | def regen(bulk_path: Path, is_thumb: bool, is_small: bool): | ||||||
|  |         for page in scan_pages(bulk_path.get_dirs()): | ||||||
|  |             for picture in page.get_pictures(): | ||||||
|  |                 if is_thumb: | ||||||
|  |                     picture.gen_thumb() | ||||||
|  |                 if is_small: | ||||||
|  |                     picture.gen_small() | ||||||
|  |      | ||||||
|  |  | ||||||
|  |  | ||||||
| def main(): | def main(): | ||||||
|     site_path = Path(argument_parsing()) |     args = argument_parsing() | ||||||
|     gen_bulk(Path(site_path, "bulk")) |     bulk_path: Path = Path(args.site_path, "bulk") | ||||||
|  |     if args.regen is not None: | ||||||
|  |         regen(bulk_path, 't' in args.regen, 's' in args.regen) | ||||||
|  |     gen_bulk(bulk_path) | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user