__init__.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 .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. # Load ABX Plugin Specifications + Default Implementations
  44. import abx # noqa
  45. import abx_spec_archivebox # noqa
  46. import abx_spec_config # noqa
  47. import abx_spec_pydantic_pkgr # noqa
  48. import abx_spec_django # noqa
  49. import abx_spec_searchbackend # noqa
  50. abx.pm.add_hookspecs(abx_spec_config.PLUGIN_SPEC)
  51. abx.pm.register(abx_spec_config.PLUGIN_SPEC())
  52. abx.pm.add_hookspecs(abx_spec_pydantic_pkgr.PLUGIN_SPEC)
  53. abx.pm.register(abx_spec_pydantic_pkgr.PLUGIN_SPEC())
  54. abx.pm.add_hookspecs(abx_spec_django.PLUGIN_SPEC)
  55. abx.pm.register(abx_spec_django.PLUGIN_SPEC())
  56. abx.pm.add_hookspecs(abx_spec_searchbackend.PLUGIN_SPEC)
  57. abx.pm.register(abx_spec_searchbackend.PLUGIN_SPEC())
  58. # Cast to ArchiveBoxPluginSpec to enable static type checking of pm.hook.call() methods
  59. abx.pm = cast(abx.ABXPluginManager[abx_spec_archivebox.ArchiveBoxPluginSpec], abx.pm)
  60. pm = abx.pm
  61. # Load all pip-installed ABX-compatible plugins
  62. ABX_ECOSYSTEM_PLUGINS = abx.get_pip_installed_plugins(group='abx')
  63. # Load all built-in ArchiveBox plugins
  64. ARCHIVEBOX_BUILTIN_PLUGINS = {
  65. 'config': PACKAGE_DIR / 'config',
  66. 'core': PACKAGE_DIR / 'core',
  67. # 'search': PACKAGE_DIR / 'search',
  68. # 'core': PACKAGE_DIR / 'core',
  69. }
  70. # Load all user-defined ArchiveBox plugins
  71. USER_PLUGINS = abx.find_plugins_in_dir(Path(os.getcwd()) / 'user_plugins')
  72. # Import all plugins and register them with ABX Plugin Manager
  73. ALL_PLUGINS = {**ABX_ECOSYSTEM_PLUGINS, **ARCHIVEBOX_BUILTIN_PLUGINS, **USER_PLUGINS}
  74. LOADED_PLUGINS = abx.load_plugins(ALL_PLUGINS)
  75. # Setup basic config, constants, paths, and version
  76. from .config.constants import CONSTANTS # noqa
  77. from .config.paths import PACKAGE_DIR, DATA_DIR, ARCHIVE_DIR # noqa
  78. from .config.version import VERSION # noqa
  79. __version__ = VERSION
  80. __author__ = 'ArchiveBox'
  81. __license__ = 'MIT'
  82. ASCII_ICON = """
  83. ██████████████████████████████████████████████████████████████████████████████████████████████████
  84. ██████████████████████████████████████████████████████████████████████████████████████████████████
  85. ██████████████████████████████████████████████████████████████████████████████████████████████████
  86. ██████████████████████████████████████████████████████████████████████████████████████████████████
  87. ██████████████████████████████████████████████████████████████████████████████████████████████████
  88. ██████████████████████████████████████████████████████████████████████████████████████████████████
  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. """