From 2bad7f2cb3751bef362e5c4856fcb5720006520c Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Wed, 29 Nov 2017 22:07:57 +0100 Subject: [PATCH] Removed dirname, because why? --- cms/generate.py | 3 ++- cms/staticfiles.py | 43 ++++++++++++++++++++++--------------------- cms/test.py | 20 -------------------- 3 files changed, 24 insertions(+), 42 deletions(-) delete mode 100644 cms/test.py diff --git a/cms/generate.py b/cms/generate.py index e724eb2..b27ffe1 100644 --- a/cms/generate.py +++ b/cms/generate.py @@ -44,7 +44,8 @@ def main(): print("Usage: %s" % sys.argv[0]) sys.exit(-1) - output_dir = os.path.dirname(os.path.abspath(sys.argv[1])) + output_dir = os.path.abspath(sys.argv[1]) + if not os.path.exists(output_dir): os.mkdir(output_dir) diff --git a/cms/staticfiles.py b/cms/staticfiles.py index 4c16c88..a658772 100644 --- a/cms/staticfiles.py +++ b/cms/staticfiles.py @@ -5,6 +5,7 @@ import shutil # Mostly copypasta from https://github.com/LongHairedHacker/verdandi/blob/master/mixins/fileassetsmixin.py + def copy_file(source_path, dest_path): print("Copying %s to %s" % (source_path, dest_path)) @@ -16,28 +17,28 @@ def copy_file(source_path, dest_path): def copy_dir(source_path, dest_path): - # /foo/bar /rofl -> contents of bar go to rofl/bar - # /foo/bar/ /rofl -> contests of bar got to rofl/ - # Trailing slash on destination should have no effect + # /foo/bar /rofl -> contents of bar go to rofl/bar + # /foo/bar/ /rofl -> contests of bar got to rofl/ + # Trailing slash on destination should have no effect - # Will be '' in case of a trailing slash: /foo/bar/ else bar - source_base = os.path.basename(source_path) - # /rofl will become /rofl/ if base is '' otherwise it will become /rofl/bar - dest_path = os.path.join(dest_path, source_base) + # Will be '' in case of a trailing slash: /foo/bar/ else bar + source_base = os.path.basename(source_path) + # /rofl will become /rofl/ if base is '' otherwise it will become /rofl/bar + dest_path = os.path.join(dest_path, source_base) - if not os.path.exists(dest_path): - os.makedirs(dest_path) + if not os.path.exists(dest_path): + os.makedirs(dest_path) - # Discover the whole tree and copy each file individually - for source_dir, _, files in os.walk(source_path): - rel_path = os.path.relpath(source_dir, source_path) - # Purely cosmetical for debug output - if rel_path == '.': - dest_dir = dest_path - else: - dest_dir = os.path.join(dest_path, rel_path) + # Discover the whole tree and copy each file individually + for source_dir, _, files in os.walk(source_path): + rel_path = os.path.relpath(source_dir, source_path) + # Purely cosmetical for debug output + if rel_path == '.': + dest_dir = dest_path + else: + dest_dir = os.path.join(dest_path, rel_path) - for source_file in files: - file_source_path = os.path.join(source_dir, source_file) - file_dest_path = os.path.join(dest_dir, source_file) - copy_file(file_source_path, file_dest_path) + for source_file in files: + file_source_path = os.path.join(source_dir, source_file) + file_dest_path = os.path.join(dest_dir, source_file) + copy_file(file_source_path, file_dest_path) diff --git a/cms/test.py b/cms/test.py deleted file mode 100644 index 055ecec..0000000 --- a/cms/test.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 - -import requests -import mwparserfromhell -import pypandoc - -def main(): - resp = requests.get("https://events.ccc.de/congress/2017/wiki/index.php?title=Assembly:CSOC&action=raw") - - wikicode = mwparserfromhell.parse(resp.text) - properties = {str(param.name) : param.value for param in wikicode.filter_templates()[0].params} - - - print(properties) - - output = pypandoc.convert_text(resp.text, 'html', format='mediawiki') - print(output) - -if __name__ == '__main__': - main()