From 17d07239f0fe5e1c190d06fcb70cdf3b0f875cc3 Mon Sep 17 00:00:00 2001 From: Marco Rossi Date: Sun, 20 Aug 2017 17:37:49 +0200 Subject: [PATCH] Add custom archive directory as configuration option. --- archive.py | 9 +++++---- config.py | 1 + fetch.py | 3 ++- index.py | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/archive.py b/archive.py index 57b858ef..9e85a645 100755 --- a/archive.py +++ b/archive.py @@ -13,6 +13,7 @@ from index import dump_index from fetch import dump_website from config import ( ARCHIVE_PERMISSIONS, + ARCHIVE_DIR, ANSI, check_dependencies, ) @@ -46,11 +47,11 @@ def create_archive(export_file, service=None, resume=None): print('[X] No links found in {}, is it a {} export file?'.format(export_file, service)) raise SystemExit(1) - if not os.path.exists(service): - os.makedirs(service) + if not os.path.exists(os.path.join(ARCHIVE_DIR, service)): + os.makedirs(os.path.join(ARCHIVE_DIR, service)) - if not os.path.exists(os.path.join(service, 'archive')): - os.makedirs(os.path.join(service, 'archive')) + if not os.path.exists(os.path.join(ARCHIVE_DIR, service, 'archive')): + os.makedirs(os.path.join(ARCHIVE_DIR, service, 'archive')) dump_index(links, service) check_dependencies() diff --git a/config.py b/config.py index 8ee92e41..f9849662 100644 --- a/config.py +++ b/config.py @@ -26,6 +26,7 @@ FETCH_FAVICON = os.getenv('FETCH_FAVICON', 'True' SUBMIT_ARCHIVE_DOT_ORG = os.getenv('SUBMIT_ARCHIVE_DOT_ORG', 'True' ).lower() == 'true' RESOLUTION = os.getenv('RESOLUTION', '1440,900' ) ARCHIVE_PERMISSIONS = os.getenv('ARCHIVE_PERMISSIONS', '755' ) +ARCHIVE_DIR = os.getenv('ARCHIVE_DIR', '') CHROME_BINARY = os.getenv('CHROME_BINARY', 'chromium-browser' ) # change to google-chrome browser if using google-chrome WGET_BINARY = os.getenv('WGET_BINARY', 'wget' ) WGET_USER_AGENT = os.getenv('WGET_USER_AGENT', None) diff --git a/fetch.py b/fetch.py index fb2e123b..1b944aa2 100644 --- a/fetch.py +++ b/fetch.py @@ -7,6 +7,7 @@ from subprocess import run, PIPE, DEVNULL from parse import derived_link_info from config import ( ARCHIVE_PERMISSIONS, + ARCHIVE_DIR, CHROME_BINARY, FETCH_WGET, FETCH_WGET_REQUISITES, @@ -261,7 +262,7 @@ def dump_website(link, service, overwrite=False, permissions=ARCHIVE_PERMISSIONS print('[{green}+{reset}] [{timestamp} ({time})] "{title}": {blue}{base_url}{reset}'.format(**link, **ANSI)) - out_dir = os.path.join(service, 'archive', link['timestamp']) + out_dir = os.path.join(ARCHIVE_DIR, service, 'archive', link['timestamp']) if not os.path.exists(out_dir): os.makedirs(out_dir) diff --git a/index.py b/index.py index 442f8a98..1a8dda33 100644 --- a/index.py +++ b/index.py @@ -7,6 +7,7 @@ from config import ( INDEX_TEMPLATE, INDEX_ROW_TEMPLATE, ARCHIVE_PERMISSIONS, + ARCHIVE_DIR, ANSI, chmod_file, ) @@ -33,10 +34,10 @@ def dump_index(links, service): 'rows': article_rows, } - with open(os.path.join(service, 'index.html'), 'w', encoding='utf-8') as f: + with open(os.path.join(ARCHIVE_DIR, service, 'index.html'), 'w', encoding='utf-8') as f: f.write(Template(index_html).substitute(**template_vars)) - chmod_file(service, permissions=ARCHIVE_PERMISSIONS) + chmod_file(os.path.join(ARCHIVE_DIR, service), permissions=ARCHIVE_PERMISSIONS) print('[+] [{}] Created archive index with {}{}{} links.'.format( datetime.now().strftime('%Y-%m-%d %H:%M:%S'),