config.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import os
  2. import sys
  3. import shutil
  4. from subprocess import run, PIPE
  5. # ******************************************************************************
  6. # * TO SET YOUR CONFIGURATION, EDIT THE VALUES BELOW, or use the 'env' command *
  7. # * e.g. *
  8. # * env USE_COLOR=True CHROME_BINARY=google-chrome ./archive.py export.html *
  9. # ******************************************************************************
  10. IS_TTY = sys.stdout.isatty()
  11. USE_COLOR = os.getenv('USE_COLOR', str(IS_TTY) ).lower() == 'true'
  12. SHOW_PROGRESS = os.getenv('SHOW_PROGRESS', str(IS_TTY) ).lower() == 'true'
  13. ONLY_NEW = os.getenv('ONLY_NEW', 'False' ).lower() == 'true'
  14. FETCH_WGET = os.getenv('FETCH_WGET', 'True' ).lower() == 'true'
  15. FETCH_WGET_REQUISITES = os.getenv('FETCH_WGET_REQUISITES', 'True' ).lower() == 'true'
  16. FETCH_AUDIO = os.getenv('FETCH_AUDIO', 'False' ).lower() == 'true'
  17. FETCH_VIDEO = os.getenv('FETCH_VIDEO', 'False' ).lower() == 'true'
  18. FETCH_PDF = os.getenv('FETCH_PDF', 'True' ).lower() == 'true'
  19. FETCH_SCREENSHOT = os.getenv('FETCH_SCREENSHOT', 'True' ).lower() == 'true'
  20. FETCH_DOM = os.getenv('FETCH_DOM', 'True' ).lower() == 'true'
  21. FETCH_GIT = os.getenv('FETCH_GIT', 'True' ).lower() == 'true'
  22. FETCH_FAVICON = os.getenv('FETCH_FAVICON', 'True' ).lower() == 'true'
  23. SUBMIT_ARCHIVE_DOT_ORG = os.getenv('SUBMIT_ARCHIVE_DOT_ORG', 'True' ).lower() == 'true'
  24. RESOLUTION = os.getenv('RESOLUTION', '1440,1200' )
  25. CHECK_SSL_VALIDITY = os.getenv('CHECK_SSL_VALIDITY', 'True' ).lower() == 'true'
  26. OUTPUT_PERMISSIONS = os.getenv('OUTPUT_PERMISSIONS', '755' )
  27. CHROME_BINARY = os.getenv('CHROME_BINARY', None) # change to google-chrome browser if using google-chrome
  28. WGET_BINARY = os.getenv('WGET_BINARY', 'wget' )
  29. WGET_USER_AGENT = os.getenv('WGET_USER_AGENT', 'ArchiveBox')
  30. CHROME_USER_DATA_DIR = os.getenv('CHROME_USER_DATA_DIR', None)
  31. TIMEOUT = int(os.getenv('TIMEOUT', '60'))
  32. FOOTER_INFO = os.getenv('FOOTER_INFO', 'Content is hosted for personal archiving purposes only. Contact server owner for any takedown requests.',)
  33. ### Paths
  34. REPO_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
  35. OUTPUT_DIR = os.getenv('OUTPUT_DIR', os.path.join(REPO_DIR, 'output'))
  36. ARCHIVE_DIR = os.path.join(OUTPUT_DIR, 'archive')
  37. SOURCES_DIR = os.path.join(OUTPUT_DIR, 'sources')
  38. PYTHON_PATH = os.path.join(REPO_DIR, 'archivebox')
  39. TEMPLATES_DIR = os.path.join(PYTHON_PATH, 'templates')
  40. # ******************************************************************************
  41. # ********************** Do not edit below this point **************************
  42. # ******************************************************************************
  43. CHROME_SANDBOX = os.getenv('CHROME_SANDBOX', 'True' ).lower() == 'true'
  44. if not CHROME_BINARY:
  45. common_chrome_executable_names = (
  46. 'chromium-browser',
  47. 'chromium',
  48. 'google-chrome',
  49. 'google-chrome-beta',
  50. 'google-chrome-canary',
  51. 'google-chrome-dev',
  52. )
  53. for name in common_chrome_executable_names:
  54. full_path_exists = shutil.which(name)
  55. if full_path_exists:
  56. CHROME_BINARY = name
  57. break
  58. else:
  59. CHROME_BINARY = 'chromium-browser'
  60. # print('[i] Using Chrome binary: {}'.format(shutil.which(CHROME_BINARY) or CHROME_BINARY))
  61. ### Terminal Configuration
  62. TERM_WIDTH = shutil.get_terminal_size((100, 10)).columns
  63. ANSI = {
  64. 'reset': '\033[00;00m',
  65. 'lightblue': '\033[01;30m',
  66. 'lightyellow': '\033[01;33m',
  67. 'lightred': '\033[01;35m',
  68. 'red': '\033[01;31m',
  69. 'green': '\033[01;32m',
  70. 'blue': '\033[01;34m',
  71. 'white': '\033[01;37m',
  72. 'black': '\033[01;30m',
  73. }
  74. if not USE_COLOR:
  75. # dont show colors if USE_COLOR is False
  76. ANSI = {k: '' for k in ANSI.keys()}
  77. ### Confirm Environment Setup
  78. try:
  79. GIT_SHA = run(["git", "rev-list", "-1", "HEAD", "./"], stdout=PIPE, cwd=REPO_DIR).stdout.strip().decode()
  80. except Exception:
  81. GIT_SHA = 'unknown'
  82. print('[!] Warning, you need git installed for code version to be saved with archive json!')
  83. if sys.stdout.encoding.upper() not in ('UTF-8', 'UTF8'):
  84. print('[X] Your system is running python3 scripts with a bad locale setting: {} (it should be UTF-8).'.format(sys.stdout.encoding))
  85. print(' To fix it, add the line "export PYTHONIOENCODING=UTF-8" to your ~/.bashrc file (without quotes)')
  86. print('')
  87. print(' Confirm that it\'s fixed by opening a new shell and running:')
  88. print(' python3 -c "import sys; print(sys.stdout.encoding)" # should output UTF-8')
  89. print('')
  90. print(' Alternatively, run this script with:')
  91. print(' env PYTHONIOENCODING=UTF-8 ./archive.py export.html')