__init__.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. ASCII_LOGO = """
  15. █████╗ ██████╗ ██████╗██╗ ██╗██╗██╗ ██╗███████╗ ██████╗ ██████╗ ██╗ ██╗
  16. ██╔══██╗██╔══██╗██╔════╝██║ ██║██║██║ ██║██╔════╝ ██╔══██╗██╔═══██╗╚██╗██╔╝
  17. ███████║██████╔╝██║ ███████║██║██║ ██║█████╗ ██████╔╝██║ ██║ ╚███╔╝
  18. ██╔══██║██╔══██╗██║ ██╔══██║██║╚██╗ ██╔╝██╔══╝ ██╔══██╗██║ ██║ ██╔██╗
  19. ██║ ██║██║ ██║╚██████╗██║ ██║██║ ╚████╔╝ ███████╗ ██████╔╝╚██████╔╝██╔╝ ██╗
  20. ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝
  21. """
  22. PACKAGE_DIR = Path(__file__).resolve().parent
  23. # # Add PACKAGE_DIR to sys.path - required for Django migrations to import models
  24. # # Migrations reference models like 'machine.Binary' which need to be importable
  25. # if str(PACKAGE_DIR) not in sys.path:
  26. # sys.path.append(str(PACKAGE_DIR))
  27. os.environ['DJANGO_SETTINGS_MODULE'] = 'archivebox.core.settings'
  28. os.environ['TZ'] = 'UTC'
  29. # detect ArchiveBox user's UID/GID based on data dir ownership
  30. from .config.permissions import drop_privileges # noqa
  31. drop_privileges()
  32. from .misc.checks import check_not_root, check_not_inside_source_dir, check_io_encoding # noqa
  33. check_not_root()
  34. check_not_inside_source_dir()
  35. check_io_encoding()
  36. # Install monkey patches for third-party libraries
  37. from .misc.monkey_patches import * # noqa
  38. # Built-in plugin directories
  39. BUILTIN_PLUGINS_DIR = PACKAGE_DIR / 'plugins'
  40. USER_PLUGINS_DIR = Path(os.getcwd()) / 'plugins'
  41. # These are kept for backwards compatibility with existing code
  42. # that checks for plugins. The new hook system uses discover_hooks()
  43. ALL_PLUGINS = {
  44. 'builtin': BUILTIN_PLUGINS_DIR,
  45. 'user': USER_PLUGINS_DIR,
  46. }
  47. LOADED_PLUGINS = ALL_PLUGINS
  48. # Setup basic config, constants, paths, and version
  49. from .config.constants import CONSTANTS # noqa
  50. from .config.paths import PACKAGE_DIR, DATA_DIR, ARCHIVE_DIR # noqa
  51. from .config.version import VERSION # noqa
  52. # Set MACHINE_ID env var so hook scripts can use it
  53. os.environ.setdefault('MACHINE_ID', CONSTANTS.MACHINE_ID)
  54. __version__ = VERSION
  55. __author__ = 'ArchiveBox'
  56. __license__ = 'MIT'
  57. ASCII_ICON = """
  58. ██████████████████████████████████████████████████████████████████████████████████████████████████
  59. ██████████████████████████████████████████████████████████████████████████████████████████████████
  60. ██████████████████████████████████████████████████████████████████████████████████████████████████
  61. ██████████████████████████████████████████████████████████████████████████████████████████████████
  62. ██████████████████████████████████████████████████████████████████████████████████████████████████
  63. ██████████████████████████████████████████████████████████████████████████████████████████████████
  64. ██████████████████████████████████████████████████████████████████████████████████████████████████
  65. ██ ██
  66. ██ ██
  67. ██ ██
  68. ██ ██
  69. ██ ██
  70. ██ ██
  71. ██ ██
  72. ██ ██
  73. ██ ██
  74. ██ ██
  75. ██ ██
  76. ██ ██
  77. ██ ████████████████████████████████████ ██
  78. ██ ██ █████████████████████████ █ ██
  79. ██ ██ █████████████████████████ █ ██
  80. ██ ██ █████████████████████████ █ ██
  81. ██ ██ █████████████████████████ █ ██
  82. ██ ██ █████████████████████████ █ ██
  83. ██ ██ █████████████████████████ █ ██
  84. ██ ██ █████████████████████████ █ ██
  85. ██ ██ █████████████████████████ █ ██
  86. ██ ██ █████████████████████████ █ ██
  87. ██ ████████████████████████████████████ ██
  88. ██ ██
  89. ██ ██
  90. ██ ██
  91. ██ ██
  92. ██ ██████████████████████████████████████████ ██
  93. ██ ██████████████████████████████████████████ ██
  94. ██ ██
  95. ██ ██
  96. ██ ██
  97. ██ ██
  98. ██ ██
  99. ████████████████████████████████████████████████████████████████████████████████
  100. """