build: use some list comps for sites stuff
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
only serve websites specified on cli
This commit is contained in:
@@ -63,7 +63,7 @@ def parse_arguments() -> argparse.Namespace:
|
||||
parser.add_argument(
|
||||
"--sites",
|
||||
help="What site directories to build",
|
||||
default=list(filter(lambda path: path.is_dir(), Path().glob("?*.??*"))),
|
||||
default=[path for path in Path().glob("?*.??*") if path.is_dir()],
|
||||
type=lambda sites: [Path(site) for site in sites.split(",")],
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -160,4 +160,4 @@ def main() -> None:
|
||||
stage_to_target(working_target, args.target, pool)
|
||||
|
||||
if args.serve:
|
||||
serve_websites(working_target, 2000, 100)
|
||||
serve_websites(working_target, args.sites, 2000, 100)
|
||||
|
||||
@@ -27,12 +27,19 @@ def _run_webserver(path: str, port: int) -> None:
|
||||
httpd.serve_forever()
|
||||
|
||||
|
||||
def serve_websites(serve_dir: Path, base_port: int, increment_number: int) -> None:
|
||||
def serve_websites(
|
||||
serve_dir: Path, sites: list, base_port: int, increment_number: int
|
||||
) -> None:
|
||||
"""
|
||||
Takes a target directory, a base port and a number to increment port by per dir
|
||||
It then serves all directories over http on localhost
|
||||
"""
|
||||
dirs = sorted(filter(lambda path: path.is_dir(), Path(serve_dir).iterdir()))
|
||||
site_names = [site.name for site in sites]
|
||||
dirs = (
|
||||
path
|
||||
for path in Path(serve_dir).iterdir()
|
||||
if (path.is_dir() and (path.name in site_names))
|
||||
)
|
||||
serves = []
|
||||
for index, directory in enumerate(dirs):
|
||||
port = base_port + (increment_number * index)
|
||||
|
||||
Reference in New Issue
Block a user