2017-07-04 10:38:07 +00:00
|
|
|
import os
|
2017-07-04 10:48:12 +00:00
|
|
|
import sys
|
2017-07-05 21:33:51 +00:00
|
|
|
import shutil
|
2017-07-04 10:48:12 +00:00
|
|
|
|
2017-10-18 22:38:17 +00:00
|
|
|
from subprocess import run, PIPE
|
2017-07-04 10:38:07 +00:00
|
|
|
|
2017-10-23 09:57:34 +00:00
|
|
|
# ******************************************************************************
|
|
|
|
# * TO SET YOUR CONFIGURATION, EDIT THE VALUES BELOW, or use the 'env' command *
|
|
|
|
# * e.g. *
|
|
|
|
# * env USE_COLOR=True CHROME_BINARY=google-chrome ./archive.py export.html *
|
|
|
|
# ******************************************************************************
|
2017-07-05 21:33:51 +00:00
|
|
|
|
2017-10-18 22:38:17 +00:00
|
|
|
IS_TTY = sys.stdout.isatty()
|
2019-01-12 03:38:50 +00:00
|
|
|
ONLY_NEW = os.getenv('ONLY_NEW', 'False' ).lower() == 'true'
|
2017-07-05 21:33:51 +00:00
|
|
|
USE_COLOR = os.getenv('USE_COLOR', str(IS_TTY) ).lower() == 'true'
|
|
|
|
SHOW_PROGRESS = os.getenv('SHOW_PROGRESS', str(IS_TTY) ).lower() == 'true'
|
2019-01-12 03:38:50 +00:00
|
|
|
OUTPUT_PERMISSIONS = os.getenv('OUTPUT_PERMISSIONS', '755' )
|
|
|
|
MEDIA_TIMEOUT = int(os.getenv('MEDIA_TIMEOUT', '3600'))
|
|
|
|
TIMEOUT = int(os.getenv('TIMEOUT', '60'))
|
|
|
|
|
2017-07-04 10:38:07 +00:00
|
|
|
FETCH_WGET = os.getenv('FETCH_WGET', 'True' ).lower() == 'true'
|
|
|
|
FETCH_WGET_REQUISITES = os.getenv('FETCH_WGET_REQUISITES', 'True' ).lower() == 'true'
|
|
|
|
FETCH_PDF = os.getenv('FETCH_PDF', 'True' ).lower() == 'true'
|
|
|
|
FETCH_SCREENSHOT = os.getenv('FETCH_SCREENSHOT', 'True' ).lower() == 'true'
|
2018-06-10 22:45:41 +00:00
|
|
|
FETCH_DOM = os.getenv('FETCH_DOM', 'True' ).lower() == 'true'
|
2019-01-13 01:19:17 +00:00
|
|
|
FETCH_WARC = os.getenv('FETCH_WARC', 'False' ).lower() == 'true'
|
2019-01-11 10:18:49 +00:00
|
|
|
FETCH_GIT = os.getenv('FETCH_GIT', 'True' ).lower() == 'true'
|
2019-01-11 11:33:35 +00:00
|
|
|
FETCH_MEDIA = os.getenv('FETCH_MEDIA', 'False' ).lower() == 'true'
|
2017-07-04 10:38:07 +00:00
|
|
|
FETCH_FAVICON = os.getenv('FETCH_FAVICON', 'True' ).lower() == 'true'
|
|
|
|
SUBMIT_ARCHIVE_DOT_ORG = os.getenv('SUBMIT_ARCHIVE_DOT_ORG', 'True' ).lower() == 'true'
|
2019-01-12 03:38:50 +00:00
|
|
|
|
2019-01-12 03:48:09 +00:00
|
|
|
CHECK_SSL_VALIDITY = os.getenv('CHECK_SSL_VALIDITY', 'True' ).lower() == 'true'
|
2019-01-12 03:38:50 +00:00
|
|
|
RESOLUTION = os.getenv('RESOLUTION', '1440,2000' )
|
|
|
|
GIT_DOMAINS = os.getenv('GIT_DOMAINS', 'github.com,bitbucket.org,gitlab.com').split(',')
|
2018-12-20 13:13:50 +00:00
|
|
|
WGET_USER_AGENT = os.getenv('WGET_USER_AGENT', 'ArchiveBox')
|
2017-10-30 09:01:59 +00:00
|
|
|
CHROME_USER_DATA_DIR = os.getenv('CHROME_USER_DATA_DIR', None)
|
2019-01-12 03:38:50 +00:00
|
|
|
|
|
|
|
CHROME_BINARY = os.getenv('CHROME_BINARY', None) # change to google-chrome browser if using google-chrome
|
|
|
|
WGET_BINARY = os.getenv('WGET_BINARY', 'wget' )
|
2018-04-17 13:14:01 +00:00
|
|
|
FOOTER_INFO = os.getenv('FOOTER_INFO', 'Content is hosted for personal archiving purposes only. Contact server owner for any takedown requests.',)
|
2017-07-04 10:38:07 +00:00
|
|
|
|
2018-06-11 00:52:15 +00:00
|
|
|
### Paths
|
|
|
|
REPO_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
|
2018-06-11 01:12:55 +00:00
|
|
|
|
2018-09-22 00:41:11 +00:00
|
|
|
OUTPUT_DIR = os.getenv('OUTPUT_DIR', os.path.join(REPO_DIR, 'output'))
|
2018-06-11 01:26:11 +00:00
|
|
|
ARCHIVE_DIR = os.path.join(OUTPUT_DIR, 'archive')
|
2018-06-11 01:12:55 +00:00
|
|
|
SOURCES_DIR = os.path.join(OUTPUT_DIR, 'sources')
|
|
|
|
|
2019-01-01 01:53:01 +00:00
|
|
|
PYTHON_PATH = os.path.join(REPO_DIR, 'archivebox')
|
2018-06-11 01:12:55 +00:00
|
|
|
TEMPLATES_DIR = os.path.join(PYTHON_PATH, 'templates')
|
2017-10-23 09:57:34 +00:00
|
|
|
|
|
|
|
# ******************************************************************************
|
|
|
|
# ********************** Do not edit below this point **************************
|
|
|
|
# ******************************************************************************
|
2017-10-18 22:38:17 +00:00
|
|
|
|
2018-10-14 02:12:26 +00:00
|
|
|
CHROME_SANDBOX = os.getenv('CHROME_SANDBOX', 'True' ).lower() == 'true'
|
|
|
|
|
2019-01-11 09:34:08 +00:00
|
|
|
if not CHROME_BINARY:
|
|
|
|
common_chrome_executable_names = (
|
|
|
|
'chromium-browser',
|
|
|
|
'chromium',
|
|
|
|
'google-chrome',
|
|
|
|
'google-chrome-beta',
|
|
|
|
'google-chrome-canary',
|
|
|
|
'google-chrome-dev',
|
|
|
|
)
|
|
|
|
for name in common_chrome_executable_names:
|
|
|
|
full_path_exists = shutil.which(name)
|
|
|
|
if full_path_exists:
|
|
|
|
CHROME_BINARY = name
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
CHROME_BINARY = 'chromium-browser'
|
|
|
|
|
|
|
|
# print('[i] Using Chrome binary: {}'.format(shutil.which(CHROME_BINARY) or CHROME_BINARY))
|
|
|
|
|
2017-10-23 09:57:34 +00:00
|
|
|
### Terminal Configuration
|
2017-07-05 21:33:51 +00:00
|
|
|
TERM_WIDTH = shutil.get_terminal_size((100, 10)).columns
|
|
|
|
ANSI = {
|
|
|
|
'reset': '\033[00;00m',
|
|
|
|
'lightblue': '\033[01;30m',
|
|
|
|
'lightyellow': '\033[01;33m',
|
|
|
|
'lightred': '\033[01;35m',
|
|
|
|
'red': '\033[01;31m',
|
|
|
|
'green': '\033[01;32m',
|
|
|
|
'blue': '\033[01;34m',
|
|
|
|
'white': '\033[01;37m',
|
|
|
|
'black': '\033[01;30m',
|
|
|
|
}
|
|
|
|
if not USE_COLOR:
|
|
|
|
# dont show colors if USE_COLOR is False
|
|
|
|
ANSI = {k: '' for k in ANSI.keys()}
|
|
|
|
|
2017-10-23 09:57:34 +00:00
|
|
|
### Confirm Environment Setup
|
2017-10-18 22:38:17 +00:00
|
|
|
try:
|
2018-06-11 00:52:15 +00:00
|
|
|
GIT_SHA = run(["git", "rev-list", "-1", "HEAD", "./"], stdout=PIPE, cwd=REPO_DIR).stdout.strip().decode()
|
2017-10-18 22:38:17 +00:00
|
|
|
except Exception:
|
2018-06-11 02:02:33 +00:00
|
|
|
GIT_SHA = 'unknown'
|
2019-01-11 09:34:08 +00:00
|
|
|
print('[!] Warning, you need git installed for code version to be saved with archive json!')
|
|
|
|
|
2017-10-18 22:38:17 +00:00
|
|
|
|
2019-01-11 09:34:08 +00:00
|
|
|
if sys.stdout.encoding.upper() not in ('UTF-8', 'UTF8'):
|
2017-07-06 21:44:04 +00:00
|
|
|
print('[X] Your system is running python3 scripts with a bad locale setting: {} (it should be UTF-8).'.format(sys.stdout.encoding))
|
2018-10-14 02:12:31 +00:00
|
|
|
print(' To fix it, add the line "export PYTHONIOENCODING=UTF-8" to your ~/.bashrc file (without quotes)')
|
2017-07-06 21:44:04 +00:00
|
|
|
print('')
|
|
|
|
print(' Confirm that it\'s fixed by opening a new shell and running:')
|
|
|
|
print(' python3 -c "import sys; print(sys.stdout.encoding)" # should output UTF-8')
|
|
|
|
print('')
|
|
|
|
print(' Alternatively, run this script with:')
|
2018-10-14 02:12:31 +00:00
|
|
|
print(' env PYTHONIOENCODING=UTF-8 ./archive.py export.html')
|