From 5cace76020aa5b1850d855ea2eb0b64cce2ff243 Mon Sep 17 00:00:00 2001 From: gabe Date: Tue, 10 Aug 2021 15:17:04 -0500 Subject: [PATCH] added first pass of compress and output. --- adocStaticSiteGen.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/adocStaticSiteGen.py b/adocStaticSiteGen.py index a4708eb..c7110d2 100755 --- a/adocStaticSiteGen.py +++ b/adocStaticSiteGen.py @@ -1,7 +1,7 @@ #! /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, tempfile, tarfile +import subprocess, sys, argparse, logging, tempfile, shutil from pathlib import Path #logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.INFO) @@ -45,16 +45,25 @@ class TmpDir: def __init__(self, srcDir): logging.debug('making tmp file') self.tmpDir = tempfile.TemporaryDirectory() + self.path = self.tmpDir.name+'/data/' self.ignorePattern = shutil.ignore_patterns('*.adoc', '.git', '.gitignore') - shutil.copytree(srcDir, self.tmpDir, ignore = self.ignorePattern, symlinks=False) + shutil.copytree(srcDir, self.path, ignore = self.ignorePattern, symlinks=False) def copy_self_to(self, destDir): - shutil.copytree(self.tmpDir, destDir, symlinks=False) + shutil.copytree(self.path, destDir, symlinks=False) def compress_and_copy_self_to(self, destPath): - tarFile = shutil.make_archive(Path(destPath).resolve(), 'gztar', self.tmpDir) + #shutil.make_archive wants destPath to be without file extentions for some godforsaken reason. + destPath = Path(destPath.with_name(destPath.name.split('.')[0])).resolve() + logging.debug(f'outputting to {destPath}') + tarFile = shutil.make_archive(destPath, 'gztar', self.path) def cleanup(self): - tmpDir.cleanup() + self.tmpDir.cleanup() -parse_arguments() +inputDir, outFile, compress = parse_arguments() +tmpdir = TmpDir(inputDir) +print(tmpdir.path) +breakpoint() +tmpdir.compress_and_copy_self_to(outFile) +tmpdir.cleanup()