Add output_path argument

This commit is contained in:
Adrian Vollmer 2022-10-04 17:47:38 +02:00
parent ae8864c946
commit a6e63be6ee
3 changed files with 16 additions and 7 deletions

View File

@ -3,7 +3,10 @@ def main():
args = parse_args()
from .embed import embed_assets
embed_assets(args.path)
embed_assets(
args.input_path,
output_path=args.output_path,
)
if __name__ == "__main__":

View File

@ -26,8 +26,13 @@ parser.add_argument(
)
parser.add_argument(
'path',
help='path to the root HTML file',
'input_path',
help='input path to the root HTML file',
)
parser.add_argument(
'-o', '--output-path',
help='output path to resulting HTML file',
)

View File

@ -29,7 +29,7 @@ SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__))
logger = logging.getLogger(__name__)
def embed_assets(index_file):
def embed_assets(index_file, output_path=None):
init_files = {}
for filename in [
@ -46,7 +46,8 @@ def embed_assets(index_file):
base_dir = os.path.dirname(index_file)
base_name = os.path.basename(index_file)
new_base_name = 'SELF_CONTAINED_' + base_name
result_file = os.path.join(base_dir, new_base_name)
if not output_path:
output_path = os.path.join(base_dir, new_base_name)
file_tree = load_filetree(
base_dir,
@ -85,10 +86,10 @@ def embed_assets(index_file):
global_context=global_context,
)
with open(result_file, 'w') as fp:
with open(output_path, 'w') as fp:
fp.write(result)
return result_file
return output_path
def prepare_file(filename, before, after):