Skip to content

Commit

Permalink
initial sample plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixSchwarz committed Oct 29, 2013
0 parents commit f1c6528
Show file tree
Hide file tree
Showing 26 changed files with 246 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.egg-info
.project
.pydevproject
.settings
dist
build
14 changes: 14 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

The "Sample Plugin" is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The software is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this package (gpl-3.0.txt).
If not, see <http://www.gnu.org/licenses/>.

6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
recursive-include mediadropext/myplugin/public *
recursive-include mediadropext/myplugin/templates *
recursive-include mediadropext/myplugin/migrations *.mako
#recursive-include mediadropext/myplugin/i18n *.pot
#recursive-include mediadropext/myplugin/i18n *.po
#recursive-include mediadropext/myplugin/i18n *.mo
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Sample Plugin for MediaDrop
================================

This is a sample plugin (skeleton) for MediaDrop. It illustrates the basic
structure of MediaDrop plugins without providing a lot of functionality.
The plugin comes with a custom controller, one very simple template and some
CSS.

If you use this package as a basis for your own experiments please replace the
references to "myplugin" with a name of your own.


Installation
-----------------------------
To install the plugin you need a working MediaDrop install (0.11dev from git).
- activate your virtualenv (e.g. `source venv/bin/activate`)
- extract the source code (e.g. `tar xzf SamplePlugin-1.0.tar.gz`)
- run `python setup.py develop` for the sample plugin (e.g. `cd SamplePlugin-1.0; python setup.py develop`)
- check your deployment.ini: If you have a "plugins" settings it should read either`plugins = *` or seomthing like `plugins = …, myplugin, …`.
- run paster (e.g. `paster serve deployment.ini`)

If everything went ok you should be able to check out
http://localhost:8080/myplugin/sample
and see the new controller in action.


Questions
-----------------------------
If you have any questions please use our [mailing list](https://groups.google.com/d/forum/mediadrop-developers).
Alternatively you may also ask your question in the [forum](http://mediadrop.net/community/)
though personally I prefer email for communication involving code.

4 changes: 4 additions & 0 deletions mediadropext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Binary file added mediadropext/__init__.pyc
Binary file not shown.
Empty file.
Binary file added mediadropext/myplugin/__init__.pyc
Binary file not shown.
Empty file.
Binary file added mediadropext/myplugin/controllers/__init__.pyc
Binary file not shown.
Binary file added mediadropext/myplugin/controllers/myplugin.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions mediadropext/myplugin/controllers/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# encoding: utf-8

from mediacore.lib.base import BaseController
from mediacore.lib.decorators import expose

class SampleController(BaseController):
@expose('myplugin/sample-page.html')
def index(self, value=None, **kwargs):
# do your backend work here
# …
return {'value': value}
Binary file added mediadropext/myplugin/controllers/sample.pyc
Binary file not shown.
Empty file.
4 changes: 4 additions & 0 deletions mediadropext/myplugin/mediadrop_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# In the sample file we don't do anything here but a real plugin should trigger
# imports to other files which register components (e.g. custom players or
# storage engines) and events.
Binary file added mediadropext/myplugin/mediadrop_plugin.pyc
Binary file not shown.
Empty file.
61 changes: 61 additions & 0 deletions mediadropext/myplugin/migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

from alembic import context
from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

if config.config_file_name is not None:
# set up loggers
from logging.config import fileConfig
fileConfig(config.config_file_name)

db_url = config.get_main_option("sqlalchemy.url")
version_table_name = config.get_main_option('version_table')
configure_opts = dict()
if version_table_name:
configure_opts['version_table'] = version_table_name

def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
context.configure(url=db_url, **configure_opts)
with context.begin_transaction():
context.run_migrations()

def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)

connection = engine.connect()
context.configure(connection=connection, **configure_opts)

try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()

if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

23 changes: 23 additions & 0 deletions mediadropext/myplugin/migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is a part of the "SamplePlugin" for MediaDrop.
# The source code contained in this file is licensed under the GPL v3 (or at
# your option any later version).
# See LICENSE.txt in the main project directory for more information.
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision}
Create Date: ${create_date}
"""

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}

${imports if imports else ""}

def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
Empty file.
17 changes: 17 additions & 0 deletions mediadropext/myplugin/public/sample-style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

.sample-content h1 {
margin-bottom: 0px;
}

.parameter {
margin-top: 1ex;
margin-bottom: 1ex;
}

.sample-content .input-value {
font-weight: bold;
}

.footer {
margin-top: 2ex;
}
Empty file.
34 changes: 34 additions & 0 deletions mediadropext/myplugin/templates/sample-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:xi="http://www.w3.org/2001/XInclude"
i18n:domain="myplugin">
<xi:include href="../master.html" />
<head>
<link rel="stylesheet" type="text/css" href="${h.url_for('/myplugin/public/sample-style.css')}" />
<title>${_('Success')}</title>
</head>

<body>
<div class="mediacore-content sample-content clearfix">
<h1>Congratulations,</h1>
<div>you installed your first MediaDrop plugin!</div>

<div class="parameter">
<py:choose>
<py:when test="not value"
py:with="url = h.current_url(with_qs=False, qualified=True) + '?value=Hello World'">
Try this page with some dynamic content: <a href="${url}">${url}</a>
</py:when>
<py:otherwise>
Specified value is <span class="input-value">${value}</span>.
</py:otherwise>
</py:choose>
</div>

<div class="footer">
Sample code provided by <a href="http://mediadrop.net">MediaDrop</a> / <a href="http://www.schwarz.eu">Felix Schwarz</a>
</div>
</div>
</body>
</html>
34 changes: 34 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python

from setuptools import setup, find_packages

setup(
name='SamplePlugin',
version='1.0',

author='YOUR NAME',
author_email='[email protected]',
license='GPL v3 or later',
install_requires = [
'MediaCore >= 0.11dev', # use whatever version you support
],

namespace_packages = ['mediadropext'],
# package_data is only for binary distributions ("bdist_egg") otherwise ("sdist")
# MANIFEST.in is used. One of the arcane things in setuptools:
# http://stackoverflow.com/a/14159430/138526
package_data={
'mediadropext.myplugin': [
'public/*',
'templates/*',
'migrations/*.mako',
],
},
packages=find_packages(),
entry_points = {
'mediacore.plugin': [
'myplugin = mediadropext.myplugin.mediadrop_plugin',
],
}
)

0 comments on commit f1c6528

Please sign in to comment.