__init__.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env python3
  2. # Welcome to the ArchiveBox source code! Thanks for checking it out!
  3. #
  4. # "We are swimming upstream against a great torrent of disorganization.
  5. # In this, our main obligation is to establish arbitrary enclaves of order and system.
  6. # It is the greatest possible victory to be, to continue to be, and to have been.
  7. # No defeat can deprive us of the success of having existed for some moment of time
  8. # in a universe that seems indifferent to us."
  9. # --Norber Weiner
  10. __package__ = 'archivebox'
  11. import os
  12. import sys
  13. from pathlib import Path
  14. from typing import cast
  15. ASCII_LOGO = """
  16. █████╗ ██████╗ ██████╗██╗ ██╗██╗██╗ ██╗███████╗ ██████╗ ██████╗ ██╗ ██╗
  17. ██╔══██╗██╔══██╗██╔════╝██║ ██║██║██║ ██║██╔════╝ ██╔══██╗██╔═══██╗╚██╗██╔╝
  18. ███████║██████╔╝██║ ███████║██║██║ ██║█████╗ ██████╔╝██║ ██║ ╚███╔╝
  19. ██╔══██║██╔══██╗██║ ██╔══██║██║╚██╗ ██╔╝██╔══╝ ██╔══██╗██║ ██║ ██╔██╗
  20. ██║ ██║██║ ██║╚██████╗██║ ██║██║ ╚████╔╝ ███████╗ ██████╔╝╚██████╔╝██╔╝ ██╗
  21. ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝
  22. """
  23. # make sure PACKAGE_DIR is in sys.path so we can import all subfolders
  24. # without necessarily waiting for django to load them thorugh INSTALLED_APPS
  25. PACKAGE_DIR = Path(__file__).resolve().parent
  26. if str(PACKAGE_DIR) not in sys.path:
  27. sys.path.append(str(PACKAGE_DIR))
  28. os.environ['DJANGO_SETTINGS_MODULE'] = 'core.settings'
  29. os.environ['TZ'] = 'UTC'
  30. # detect ArchiveBox user's UID/GID based on data dir ownership
  31. from .config.permissions import drop_privileges # noqa
  32. drop_privileges()
  33. from .misc.checks import check_not_root, check_io_encoding # noqa
  34. check_not_root()
  35. check_io_encoding()
  36. # print('INSTALLING MONKEY PATCHES')
  37. from .misc.monkey_patches import * # noqa
  38. # print('DONE INSTALLING MONKEY PATCHES')
  39. # print('LOADING VENDORED LIBRARIES')
  40. from .pkgs import load_vendored_pkgs # noqa
  41. load_vendored_pkgs()
  42. # print('DONE LOADING VENDORED LIBRARIES')
  43. # print('LOADING ABX PLUGIN SPECIFICATIONS')
  44. # Load ABX Plugin Specifications + Default Implementations
  45. import abx # noqa
  46. import abx_spec_archivebox # noqa
  47. import abx_spec_config # noqa
  48. import abx_spec_abx_pkg # noqa
  49. import abx_spec_django # noqa
  50. import abx_spec_searchbackend # noqa
  51. abx.pm.add_hookspecs(abx_spec_config.PLUGIN_SPEC)
  52. abx.pm.register(abx_spec_config.PLUGIN_SPEC())
  53. abx.pm.add_hookspecs(abx_spec_abx_pkg.PLUGIN_SPEC)
  54. abx.pm.register(abx_spec_abx_pkg.PLUGIN_SPEC())
  55. abx.pm.add_hookspecs(abx_spec_django.PLUGIN_SPEC)
  56. abx.pm.register(abx_spec_django.PLUGIN_SPEC())
  57. abx.pm.add_hookspecs(abx_spec_searchbackend.PLUGIN_SPEC)
  58. abx.pm.register(abx_spec_searchbackend.PLUGIN_SPEC())
  59. # Cast to ArchiveBoxPluginSpec to enable static type checking of pm.hook.call() methods
  60. abx.pm = cast(abx.ABXPluginManager[abx_spec_archivebox.ArchiveBoxPluginSpec], abx.pm)
  61. pm = abx.pm
  62. # print('DONE LOADING ABX PLUGIN SPECIFICATIONS')
  63. # Load all pip-installed ABX-compatible plugins
  64. ABX_ECOSYSTEM_PLUGINS = abx.get_pip_installed_plugins(group='abx')
  65. # Load all built-in ArchiveBox plugins
  66. ARCHIVEBOX_BUILTIN_PLUGINS = {
  67. 'config': PACKAGE_DIR / 'config',
  68. 'workers': PACKAGE_DIR / 'workers',
  69. 'core': PACKAGE_DIR / 'core',
  70. 'crawls': PACKAGE_DIR / 'crawls',
  71. # 'machine': PACKAGE_DIR / 'machine'
  72. # 'search': PACKAGE_DIR / 'search',
  73. }
  74. # Load all user-defined ArchiveBox plugins
  75. USER_PLUGINS = abx.find_plugins_in_dir(Path(os.getcwd()) / 'user_plugins')
  76. # Import all plugins and register them with ABX Plugin Manager
  77. ALL_PLUGINS = {**ABX_ECOSYSTEM_PLUGINS, **ARCHIVEBOX_BUILTIN_PLUGINS, **USER_PLUGINS}
  78. # print('LOADING ALL PLUGINS')
  79. LOADED_PLUGINS = abx.load_plugins(ALL_PLUGINS)
  80. # print('DONE LOADING ALL PLUGINS')
  81. # Setup basic config, constants, paths, and version
  82. from .config.constants import CONSTANTS # noqa
  83. from .config.paths import PACKAGE_DIR, DATA_DIR, ARCHIVE_DIR # noqa
  84. from .config.version import VERSION # noqa
  85. __version__ = VERSION
  86. __author__ = 'ArchiveBox'
  87. __license__ = 'MIT'
  88. ASCII_ICON = """
  89. ██████████████████████████████████████████████████████████████████████████████████████████████████
  90. ██████████████████████████████████████████████████████████████████████████████████████████████████
  91. ██████████████████████████████████████████████████████████████████████████████████████████████████
  92. ██████████████████████████████████████████████████████████████████████████████████████████████████
  93. ██████████████████████████████████████████████████████████████████████████████████████████████████
  94. ██████████████████████████████████████████████████████████████████████████████████████████████████
  95. ██████████████████████████████████████████████████████████████████████████████████████████████████
  96. ██ ██
  97. ██ ██
  98. ██ ██
  99. ██ ██
  100. ██ ██
  101. ██ ██
  102. ██ ██
  103. ██ ██
  104. ██ ██
  105. ██ ██
  106. ██ ██
  107. ██ ██
  108. ██ ████████████████████████████████████ ██
  109. ██ ██ █████████████████████████ █ ██
  110. ██ ██ █████████████████████████ █ ██
  111. ██ ██ █████████████████████████ █ ██
  112. ██ ██ █████████████████████████ █ ██
  113. ██ ██ █████████████████████████ █ ██
  114. ██ ██ █████████████████████████ █ ██
  115. ██ ██ █████████████████████████ █ ██
  116. ██ ██ █████████████████████████ █ ██
  117. ██ ██ █████████████████████████ █ ██
  118. ██ ████████████████████████████████████ ██
  119. ██ ██
  120. ██ ██
  121. ██ ██
  122. ██ ██
  123. ██ ██████████████████████████████████████████ ██
  124. ██ ██████████████████████████████████████████ ██
  125. ██ ██
  126. ██ ██
  127. ██ ██
  128. ██ ██
  129. ██ ██
  130. ████████████████████████████████████████████████████████████████████████████████
  131. """