plugins.rst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. =========
  2. Plugins
  3. =========
  4. GNU MediaGoblin supports plugins that allow you to augment MediaGoblin's
  5. behavior.
  6. This chapter covers discovering, installing, configuring and removing
  7. plugins.
  8. Discovering plugins
  9. ===================
  10. MediaGoblin comes with core plugins. Core plugins are located in the
  11. ``mediagoblin.plugins`` module of the MediaGoblin code. Because they
  12. come with MediaGoblin, you don't have to install them, but you do have
  13. to add them to your config file if you're interested in using them.
  14. You can also write your own plugins and additionally find plugins
  15. elsewhere on the Internet. Once you find a plugin you like, you need
  16. to first install it, then add it to your configuration.
  17. .. todo: how do you find plugins on the internet?
  18. Installing plugins
  19. ==================
  20. Core plugins
  21. ------------
  22. MediaGoblin core plugins don't need to be installed because they come
  23. with MediaGoblin. Further, when you upgrade MediaGoblin, you will also
  24. get updates to the core plugins.
  25. Other plugins
  26. -------------
  27. If the plugin is available on the `Python Package Index
  28. <http://pypi.python.org/pypi>`_, then you can install the plugin with pip::
  29. pip install <plugin-name>
  30. For example, if we wanted to install the plugin named
  31. "mediagoblin-licenses" (which allows you to customize the licenses you
  32. offer for your media), we would do::
  33. pip install mediagoblin-licenses
  34. .. Note::
  35. If you're using a virtual environment, make sure to activate the
  36. virtual environment before installing with pip. Otherwise the plugin
  37. may get installed in a different environment than the one MediaGoblin
  38. is installed in. Also make sure, you use e.g. pip-2.7 if your default
  39. python (and thus pip) is python 3 (e.g. in *buntu).
  40. Once you've installed the plugin software, you need to tell
  41. MediaGoblin that this is a plugin you want MediaGoblin to use. To do
  42. that, you edit the ``mediagoblin.ini`` file and add the plugin as a
  43. subsection of the plugin section.
  44. For example, say the "mediagoblin-licenses" plugin has the Python
  45. package path ``mediagoblin_licenses``, then you would add ``mediagoblin_licenses`` to
  46. the ``plugins`` section as a subsection::
  47. [plugins]
  48. [[mediagoblin_licenses]]
  49. license_01=abbrev1, name1, http://url1
  50. license_02=abbrev2, name1, http://url2
  51. Configuring plugins
  52. ===================
  53. Configuration for a plugin goes in the subsection for that plugin. Core
  54. plugins are documented in the administration guide. Other plugins
  55. should come with documentation that tells you how to configure them.
  56. Example 1: Core MediaGoblin plugin
  57. If you wanted to use the core MediaGoblin flatpages plugin, the module
  58. for that is ``mediagoblin.plugins.flatpagesfile`` and you would add
  59. that to your ``.ini`` file like this::
  60. [plugins]
  61. [[mediagoblin.plugins.flatpagesfile]]
  62. # configuration for flatpagesfile plugin here!
  63. about-view = '/about', about.html
  64. terms-view = '/terms', terms.html
  65. (Want to know more about the flatpagesfile plugin? See
  66. :ref:`flatpagesfile-chapter`)
  67. Example 2: Plugin that is not a core MediaGoblin plugin
  68. If you installed a hypothetical restrictfive plugin which is in the
  69. module ``restrictfive``, your ``.ini`` file might look like this (with
  70. comments making the bits clearer)::
  71. [plugins]
  72. [[restrictfive]]
  73. # configuration for restrictfive here!
  74. Check the plugin's documentation for what configuration options are
  75. available.
  76. Once you've set up your plugin, you should be sure to update the
  77. database to accomodate the new plugins::
  78. ./bin/gmg dbupdate
  79. Deactivating plugins
  80. ====================
  81. You should be aware that once you enable a plugin, deactivating it
  82. might be a bit tricky, for migrations reasons. In the future we may
  83. produce better tooling to accomodate this. In short, you will need to
  84. do a bit of database surgery by:
  85. - Removing all tables and indexes installed by the plugin
  86. - Removing the plugin's migration head id from the `alembic_version`
  87. table. (You might be able to determine which to remove via
  88. examining the output of `./bin/gmg alembic heads`)
  89. Note that this is a VERY TRICKY process, and you should be sure to make
  90. a backup first. You've been warned!
  91. Removing plugin packages
  92. ========================
  93. To remove an external plugin's package, use ``pip uninstall``. For example::
  94. pip uninstall mediagoblin-licenses
  95. .. Note::
  96. If you're using a virtual environment, make sure to activate the
  97. virtual environment before uninstalling with pip. Otherwise the
  98. plugin may get installed in a different environment.
  99. Upgrading plugins
  100. =================
  101. Core plugins
  102. ------------
  103. Core plugins get upgraded automatically when you upgrade MediaGoblin
  104. because they come with MediaGoblin.
  105. Other plugins
  106. -------------
  107. For plugins that you install with pip, you can upgrade them with pip::
  108. pip install -U <plugin-name>
  109. The ``-U`` tells pip to upgrade the package.
  110. Troubleshooting plugins
  111. =======================
  112. Sometimes plugins just don't work right. When you're having problems
  113. with plugins, think about the following:
  114. 1. Check the log files.
  115. Some plugins will log errors to the log files and you can use that
  116. to diagnose the problem.
  117. 2. Try running MediaGoblin without that plugin.
  118. It's easy to disable a plugin from MediaGoblin. Add a ``-`` to the
  119. name in your config file.
  120. For example, change::
  121. [[mediagoblin.plugins.flatpagesfile]]
  122. to::
  123. [[-mediagoblin.plugins.flatpagesfile]]
  124. That'll prevent the ``mediagoblin.plugins.flatpagesfile`` plugin from
  125. loading.
  126. 3. If it's a core plugin that comes with MediaGoblin, ask us for help!
  127. If it's a plugin you got from somewhere else, ask them for help!