fixed compressed file name detection

This commit is contained in:
gabe 2021-07-15 14:13:00 -05:00
parent 1cdac62383
commit cbb7f9c37a

30
adocStaticSiteGen.py Normal file → Executable file
View file

@ -1,20 +1,20 @@
#! /usr/bin/env python3
#takes directory, converts all .adoc files to html files, copying the resulting html files to an identical directory strucuture, and copies over all non .adoc files unchanged. Optionally outputs as a tar.gz file.
import subprocess, sys, argparse, logging
import subprocess, sys, argparse, logging, tempfile
from pathlib import Path
logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.INFO)
#logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.DEBUG)
#logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.INFO)
logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.DEBUG)
def parse_arguments():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(description='create a website directory structure by converting .adoc files in a directory strucutre to .html files.')
parser.add_argument('inputDir', type=Path, help='The directory of adoc files to be copied and converted.')
parser.add_argument('-o', '--output', type=Path, help='What to name the generated directory or tar file')
parser.add_argument('-z', '--compress', action='store_true')
parser.add_argument('-z', '--compress', action='store_true', help='whether to compress the resulting directory to a tar.gz file. can be usefull for scripting to transfer the site to a remote server.')
args=parser.parse_args()
if args.output != None and args.compress == False:
if args.output != None and not args.compress:
#detect based on whether outFile has a .tar.gz filename.
if args.output.suffixes == ['.tar', '.gz']:
compress = True
@ -24,10 +24,20 @@ def parse_arguments():
compress = args.compress
if args.output == None:
outfile = Path(args.inputDir.parent).joinpath(args.inputdir.stem)
outFile = args.inputDir.with_name(args.inputDir.name+'_compiled')
else:
outfile=args.output
outFile=args.output
logging.info(f'outputting to {outFile}')
if compress and outFile.suffixes != ['.tar', '.gz']:
logging.debug(f'outFile was {outFile}, corrected because compress flag is set.')
outFile = outFile.with_suffix('.tar.gz')
return args.inputDir, outfile, compress
logging.debug(f'inputing from {args.inputDir.resolve()}')
logging.info(f'outputting to {outFile.resolve()}')
logging.debug(f'compress is {compress}')
if args.inputDir.resolve() == outFile.resolve():
raise FileExistsError('output file cannot have the same path as the input file!')
return args.inputDir, outFile, compress
parse_arguments()