config.py 5.4 KB

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