From 3ffc96453e3eb57ce1277dc71b28b8d2c38a6b6b Mon Sep 17 00:00:00 2001 From: gabe Date: Sun, 26 Sep 2021 12:32:22 -0500 Subject: [PATCH 1/3] implemented importing exclude globs from a file. --- ASCIIsite.py | 11 +++++- tests/globignore | 1 + tests/result/include/include.txt | 65 ++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tests/globignore create mode 100644 tests/result/include/include.txt diff --git a/ASCIIsite.py b/ASCIIsite.py index 8d5b212..50c9479 100755 --- a/ASCIIsite.py +++ b/ASCIIsite.py @@ -11,8 +11,9 @@ def parse_arguments(): 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', 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.') + parser.add_argument('--exclude-file', type=Path, help='A text file containing glob patterns to exclude, 1 per line.') parser.add_argument('--exclude', nargs='+', help='A list of glob patterns to ignore. Remember to quote them so your shell doesnt escape them!') + 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() #set compress flag @@ -44,7 +45,13 @@ def parse_arguments(): logging.info(f'outputting to {outFile.resolve()}') logging.debug(f'compress is {compress}') - return args.inputDir.resolve(), outFile, compress, args.exclude + with open(args.exclude_file, 'r') as file: + exclude=[glob.strip() for glob in file] + + if args.exclude != None: + exclude.extend(args.exclude) + + return args.inputDir.resolve(), outFile, compress, exclude #Doing it in a tmpDir first, as some distrubutions put temp files on a ramdisk. this should speed up the operation sigificantly. class TmpDir: diff --git a/tests/globignore b/tests/globignore new file mode 100644 index 0000000..0eddfc6 --- /dev/null +++ b/tests/globignore @@ -0,0 +1 @@ +include* diff --git a/tests/result/include/include.txt b/tests/result/include/include.txt new file mode 100644 index 0000000..a7151a2 --- /dev/null +++ b/tests/result/include/include.txt @@ -0,0 +1,65 @@ +== included section + +Fusce maximus nec magna eu ultricies. +Fusce quis tellus vitae arcu facilisis lobortis. +Donec id erat at enim porta placerat in vitae sapien. +Duis justo arcu, hendrerit nec nulla eu, dictum dapibus ipsum. +Sed fermentum id elit eget fringilla. +Suspendisse volutpat imperdiet justo, ut efficitur odio maximus et. +Nunc interdum sollicitudin eros sit amet convallis. +Praesent volutpat tempus metus id tincidunt. +Proin aliquet justo a fermentum consectetur. +Nunc scelerisque, nisi id scelerisque dictum, nibh lectus ultrices nunc, quis ultricies erat velit sit amet urna. +Maecenas orci felis, volutpat at bibendum ut, mattis eu justo. + +=== blocks + +.listing block +---- +example of _listing block_ +with verbatim line break +---- + +.example block +==== +example block +with line break +==== + +.literal block +.... +_literal_ block +with line break +.... + +.pass block +++++ +pass block +with underlined text +++++ + +.quote block +____ +quote block +with line break +____ + +.sidebar block +**** +sidebar block +with line break +**** + +[NOTE] +==== +This is an example of an admonition block. + +Unlike an admonition paragraph, it may contain any AsciiDoc content. +The style can be any one of the admonition labels: + +* NOTE +* TIP +* WARNING +* CAUTION +* IMPORTANT +==== From 08a56839068343b99a73b61af1a68a0cd708519a Mon Sep 17 00:00:00 2001 From: gabe Date: Sun, 26 Sep 2021 12:45:45 -0500 Subject: [PATCH 2/3] updated readme for new feature --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9d81680..464838f 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,17 @@ ASCIISite takes 2 (so far) optional arguments followed by the single mandatory a the -o or --output option simply tells ASCIISite what to name the output file. -the --exclude flag allows you to specify a list of glob patterns. Any file matching these glob patterns will not be copied to the output. -This is helpful for any files that are needed for the compilation of the asciidoc files, but do not need to be in the final site. -The main use case I am aware of is files that are put into an asciidoc document via an include statement. - the -z or --compress flag tells ASCIISite to put the final product in a compressed tar.gz file as its output. This is especially useful if you are running ASCIISite on your personal computer, and will be uploading the tar.gz file to your server. +the --exclude flag allows you to specify a list of glob patterns. Any file matching these glob patterns will not be copied to the output. + +The --exclude-file flag allows you to specify a file containing one glob to exclude per line. Other than inputting from a file, works exactly the same as --exclude. Note that it cannot parse the full spec of .gitignore files, only traditional globs. + +Exclusions are helpful for any files that are needed for the compilation of the asciidoc files, but do not need to be in the final site. +The main use case I am aware of is files that are put into an asciidoc document via an include statement. + + As for how to format the input directory, thats up to you. The directory structure of the input will be mirrored in the structure of the output website. The only real rule you need to follow is that all your links to other pages in the input directory should be relative, so they dont get broken when you move the output directory around. From 6e2bdb0c8d042bb9bff93c9e090d79323d58bad9 Mon Sep 17 00:00:00 2001 From: gabe Date: Mon, 27 Sep 2021 14:52:02 -0500 Subject: [PATCH 3/3] Caught a few errors. --- ASCIIsite.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ASCIIsite.py b/ASCIIsite.py index 50c9479..d0ad22a 100755 --- a/ASCIIsite.py +++ b/ASCIIsite.py @@ -45,11 +45,19 @@ def parse_arguments(): logging.info(f'outputting to {outFile.resolve()}') logging.debug(f'compress is {compress}') - with open(args.exclude_file, 'r') as file: - exclude=[glob.strip() for glob in file] + try: + with open(args.exclude_file, 'r') as file: + exclude=[glob.strip() for glob in file] - if args.exclude != None: - exclude.extend(args.exclude) + if args.exclude != None: + exclude.extend(args.exclude) + except Exception as e: + print(str(e)) + exit() + + if args.inputDir.resolve().exists(): + print(f'Inputdir {args.inputDir.resolve()} does not exist!') + exit() return args.inputDir.resolve(), outFile, compress, exclude