update builder for autobuild
This commit is contained in:
41
export.py
41
export.py
@@ -8,6 +8,7 @@ from argparse import ArgumentParser
|
||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||
from config import context
|
||||
|
||||
PROJECT_FOLDER = os.path.dirname(__file__)
|
||||
|
||||
def dev(args, output):
|
||||
while True:
|
||||
@@ -23,7 +24,7 @@ def render(args, output, quiet=False):
|
||||
if not quiet:
|
||||
print("copying static folder")
|
||||
try:
|
||||
shutil.copytree(os.path.join(os.getcwd(), 'static'), output)
|
||||
shutil.copytree(os.path.join(PROJECT_FOLDER, 'static'), output)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -32,7 +33,7 @@ def render(args, output, quiet=False):
|
||||
loader=PackageLoader("export", 'templates'),
|
||||
autoescape=select_autoescape(['html'])
|
||||
)
|
||||
templates_folder = os.path.join(os.getcwd(), 'templates')
|
||||
templates_folder = os.path.join(PROJECT_FOLDER, 'templates')
|
||||
for root, dirs, templates in os.walk(templates_folder):
|
||||
if root == os.path.join(templates_folder, 'meta'):
|
||||
continue
|
||||
@@ -58,20 +59,22 @@ def create_folder(container, template_file):
|
||||
os.mkdir(full_path)
|
||||
|
||||
|
||||
parser = ArgumentParser(description="Build website")
|
||||
parser.add_argument('-o', '--output', default='build',
|
||||
help="Output folder or file")
|
||||
parser.add_argument('-f', '--format', default="folder",
|
||||
choices=("gzip", "folder", 'dev'),
|
||||
help="Format output (either gzip, dev or folder)")
|
||||
args = parser.parse_args()
|
||||
output = args.output if args.format != 'gzip' else '_build'
|
||||
render(args, output)
|
||||
# compress
|
||||
if args.format == 'gzip':
|
||||
with tarfile.open(args.output, "w:gz") as tar:
|
||||
tar.add(output, arcname=os.path.basename(output))
|
||||
shutil.rmtree(output)
|
||||
elif args.format == 'dev':
|
||||
dev(args, output)
|
||||
shutil.rmtree(output)
|
||||
if __name__ == '__main__':
|
||||
parser = ArgumentParser(description="Build website")
|
||||
parser.add_argument('-o', '--output', default='build',
|
||||
help="Output folder or file")
|
||||
parser.add_argument('-f', '--format', default="folder",
|
||||
choices=("gzip", "folder", 'dev'),
|
||||
help="Format output (either gzip, dev or folder)")
|
||||
parser.add_argument('-q', '--quiet', default=False, action='store_true')
|
||||
args = parser.parse_args()
|
||||
output = args.output if args.format != 'gzip' else '_build'
|
||||
render(args, output, args.quiet)
|
||||
# compress
|
||||
if args.format == 'gzip':
|
||||
with tarfile.open(args.output, "w:gz") as tar:
|
||||
tar.add(output, arcname=os.path.basename(output))
|
||||
shutil.rmtree(output)
|
||||
elif args.format == 'dev':
|
||||
dev(args, output)
|
||||
shutil.rmtree(output)
|
||||
|
Reference in New Issue
Block a user