From 2abb487945ede57261122c2edd2b77e403ec2f2e Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Sat, 5 Sep 2015 20:03:51 -0300 Subject: [PATCH] Implemented startplugin command --- colab/conf/__init__.py | 0 colab/conf/plugin_template/setup.py | 37 +++++++++++++++++++++++++++++++++++++ colab/conf/plugin_template/src/app_name/__init__.py | 3 +++ colab/conf/plugin_template/src/app_name/apps.py | 8 ++++++++ colab/conf/plugin_template/src/app_name/data_importer.py | 9 +++++++++ colab/conf/plugin_template/src/app_name/diazo.xml | 6 ++++++ colab/conf/plugin_template/src/app_name/models.py | 1 + colab/conf/plugin_template/src/app_name/search_indexes.py | 2 ++ colab/conf/plugin_template/src/app_name/urls.py | 8 ++++++++ colab/conf/plugin_template/src/app_name/views.py | 6 ++++++ colab/conf/plugin_template/tests/__init__.py | 0 colab/conf/plugin_template/tests/colab_settings.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ colab/conf/plugin_template/tests/plugins.d/app_name.py | 32 ++++++++++++++++++++++++++++++++ colab/conf/plugin_template/tests/runtests.py | 22 ++++++++++++++++++++++ colab/conf/plugin_template/tests/test_plugin.py | 11 +++++++++++ colab/management/commands/startplugin.py | 25 +++++++++++++++++++++++++ 16 files changed, 225 insertions(+), 0 deletions(-) create mode 100644 colab/conf/__init__.py create mode 100644 colab/conf/plugin_template/setup.py create mode 100644 colab/conf/plugin_template/src/app_name/__init__.py create mode 100644 colab/conf/plugin_template/src/app_name/apps.py create mode 100644 colab/conf/plugin_template/src/app_name/data_importer.py create mode 100644 colab/conf/plugin_template/src/app_name/diazo.xml create mode 100644 colab/conf/plugin_template/src/app_name/models.py create mode 100644 colab/conf/plugin_template/src/app_name/search_indexes.py create mode 100644 colab/conf/plugin_template/src/app_name/urls.py create mode 100644 colab/conf/plugin_template/src/app_name/views.py create mode 100644 colab/conf/plugin_template/tests/__init__.py create mode 100644 colab/conf/plugin_template/tests/colab_settings.py create mode 100644 colab/conf/plugin_template/tests/plugins.d/app_name.py create mode 100644 colab/conf/plugin_template/tests/runtests.py create mode 100644 colab/conf/plugin_template/tests/test_plugin.py create mode 100644 colab/management/commands/startplugin.py diff --git a/colab/conf/__init__.py b/colab/conf/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/conf/__init__.py diff --git a/colab/conf/plugin_template/setup.py b/colab/conf/plugin_template/setup.py new file mode 100644 index 0000000..bfe066c --- /dev/null +++ b/colab/conf/plugin_template/setup.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +""" +{{ app_name_verbose }} Colab plugin +=================================== +""" +from setuptools import setup, find_packages + +install_requires = ['colab'] + +tests_require = ['mock'] + + +setup( + name="{{ app_name_dash }}", + version='0.1.0', + author='<>', + author_email='<>', + url='<< project url/repo url >>', + description='{{ app_name_verbose }} Colab plugin', + long_description=__doc__, + license='<< project license >>', + package_dir={'': 'src'}, + packages=find_packages('src'), + zip_safe=False, + install_requires=install_requires, + test_suite="tests.runtests.run", + tests_require=tests_require, + extras_require={'test': tests_require}, + include_package_data=True, + classifiers=[ + 'Framework :: Django', + 'Intended Audience :: Developers', + 'Intended Audience :: System Administrators', + 'Operating System :: OS Independent', + 'Topic :: Software Development' + ], +) diff --git a/colab/conf/plugin_template/src/app_name/__init__.py b/colab/conf/plugin_template/src/app_name/__init__.py new file mode 100644 index 0000000..7ee63aa --- /dev/null +++ b/colab/conf/plugin_template/src/app_name/__init__.py @@ -0,0 +1,3 @@ + + +default_app_config = '{{ app_name }}.apps.PluginAppConfig' diff --git a/colab/conf/plugin_template/src/app_name/apps.py b/colab/conf/plugin_template/src/app_name/apps.py new file mode 100644 index 0000000..a9a0150 --- /dev/null +++ b/colab/conf/plugin_template/src/app_name/apps.py @@ -0,0 +1,8 @@ + +from colab.plugins.utils.apps import ColabPluginAppConfig + + +class {{ app_name_camel }}AppConfig(ColabPluginAppConfig): + name = '{{ app_name }}' + verbose_name = '{{ app_name_verbose }} Plugin' + short_name = '{{ app_name }}' diff --git a/colab/conf/plugin_template/src/app_name/data_importer.py b/colab/conf/plugin_template/src/app_name/data_importer.py new file mode 100644 index 0000000..08a7183 --- /dev/null +++ b/colab/conf/plugin_template/src/app_name/data_importer.py @@ -0,0 +1,9 @@ + +from colab.plugins.data import PluginDataImporter + + +class {{ app_name_camel }}DataImporter(PluginDataImporter): + app_label = '{{ app_name }}' + + def fetch_data(self): + pass diff --git a/colab/conf/plugin_template/src/app_name/diazo.xml b/colab/conf/plugin_template/src/app_name/diazo.xml new file mode 100644 index 0000000..2c64946 --- /dev/null +++ b/colab/conf/plugin_template/src/app_name/diazo.xml @@ -0,0 +1,6 @@ + + + diff --git a/colab/conf/plugin_template/src/app_name/models.py b/colab/conf/plugin_template/src/app_name/models.py new file mode 100644 index 0000000..0bc177d --- /dev/null +++ b/colab/conf/plugin_template/src/app_name/models.py @@ -0,0 +1 @@ +# Your models here. diff --git a/colab/conf/plugin_template/src/app_name/search_indexes.py b/colab/conf/plugin_template/src/app_name/search_indexes.py new file mode 100644 index 0000000..225185d --- /dev/null +++ b/colab/conf/plugin_template/src/app_name/search_indexes.py @@ -0,0 +1,2 @@ +# Your search indexes here. +# See: http://django-haystack.readthedocs.org/en/latest/searchindex_api.html diff --git a/colab/conf/plugin_template/src/app_name/urls.py b/colab/conf/plugin_template/src/app_name/urls.py new file mode 100644 index 0000000..54ca456 --- /dev/null +++ b/colab/conf/plugin_template/src/app_name/urls.py @@ -0,0 +1,8 @@ + +from django.conf.urls import patterns, url + +from .views import {{ app_name_camel }}ProxyView + +urlpatterns = patterns('', + url(r'^(?P.*)$', GitlabProxyView.as_view(), name='{{ app_name }}'), +) diff --git a/colab/conf/plugin_template/src/app_name/views.py b/colab/conf/plugin_template/src/app_name/views.py new file mode 100644 index 0000000..2c802fc --- /dev/null +++ b/colab/conf/plugin_template/src/app_name/views.py @@ -0,0 +1,6 @@ + +from colab.plugins.views import ColabProxyView + + +class {{ app_name_camel }}ProxyView(ColabProxyView): + app_label = '{{ app_name }}' diff --git a/colab/conf/plugin_template/tests/__init__.py b/colab/conf/plugin_template/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/conf/plugin_template/tests/__init__.py diff --git a/colab/conf/plugin_template/tests/colab_settings.py b/colab/conf/plugin_template/tests/colab_settings.py new file mode 100644 index 0000000..bf1efa5 --- /dev/null +++ b/colab/conf/plugin_template/tests/colab_settings.py @@ -0,0 +1,55 @@ + +## Set to false in production +DEBUG = True +TEMPLATE_DEBUG = False + +## System admins +ADMINS = [['John Foo', 'john@example.com'], ['Mary Bar', 'mary@example.com']] + +MANAGERS = ADMINS + +COLAB_FROM_ADDRESS = '"Colab" ' +SERVER_EMAIL = '"Colab" ' + +EMAIL_HOST = 'localhost' +EMAIL_PORT = 25 +EMAIL_SUBJECT_PREFIX = '[colab]' + +SECRET_KEY = 'not-a-secret' + +ALLOWED_HOSTS = [ + 'localhost', +# 'example.com', +# 'example.org', +# 'example.net', +] + +### Uncomment to enable social networks fields profile +SOCIAL_NETWORK_ENABLED = True + +## Disable indexing +ROBOTS_NOINDEX = True + +LOGGING = { + 'version': 1, + + 'handlers': { + 'null': { + 'level': 'DEBUG', + 'class': 'logging.NullHandler', + }, + }, + + 'loggers': { + 'colab.mailman': { + 'handlers': ['null'], + 'propagate': False, + }, + 'haystack': { + 'handlers': ['null'], + 'propagate': False, + }, + }, +} + +STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' diff --git a/colab/conf/plugin_template/tests/plugins.d/app_name.py b/colab/conf/plugin_template/tests/plugins.d/app_name.py new file mode 100644 index 0000000..5fbad26 --- /dev/null +++ b/colab/conf/plugin_template/tests/plugins.d/app_name.py @@ -0,0 +1,32 @@ + +from django.utils.translation import ugettext_lazy as _ +from colab.plugins.utils.menu import colab_url_factory + +name = '{{ app_name }}' +verbose_name = '{{ app_name_verbose }} Plugin' + +upstream = 'localhost' +# middlewares = [] + +urls = { + 'include': '{{ app_name }}.urls', + 'namespace': '{{ app_name }}', + 'prefix': '^{{ app_name }}/', +} + +menu_title = _('{{ app_name }}') + +url = colab_url_factory('{{ app_name }}') + +# Extra data to be exposed to plugin app config +extra = {} + +menu_urls = ( +# Example of menu URL: +# url(display=_('Public Projects'), viewname='gitlab', +# kwargs={'path': 'public/projects'}, auth=False), + +# Example of authenticated user menu URL: +# url(display=_('Profile'), viewname='gitlab', +# kwargs={'path': 'profile'}, auth=True), +) diff --git a/colab/conf/plugin_template/tests/runtests.py b/colab/conf/plugin_template/tests/runtests.py new file mode 100644 index 0000000..ad6efad --- /dev/null +++ b/colab/conf/plugin_template/tests/runtests.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +import django +from django.conf import settings +from django.test.utils import get_runner + + +def run(): + os.environ['DJANGO_SETTINGS_MODULE'] = 'colab.settings' + os.environ['COLAB_PLUGINS'] = 'tests/plugins.d' + os.environ['COLAB_SETTINGS'] = 'tests/colab_settings.py' + django.setup() + TestRunner = get_runner(settings) + test_runner = TestRunner() + failures = test_runner.run_tests(["tests"]) + sys.exit(bool(failures)) + + +if __name__ == "__main__": + run() diff --git a/colab/conf/plugin_template/tests/test_plugin.py b/colab/conf/plugin_template/tests/test_plugin.py new file mode 100644 index 0000000..bdd2df6 --- /dev/null +++ b/colab/conf/plugin_template/tests/test_plugin.py @@ -0,0 +1,11 @@ + +from django.test import TestCase, Client + + +class PluginTest(TestCase): + + def setUp(self): + self.client = Client() + + def test_true(self): + assert True diff --git a/colab/management/commands/startplugin.py b/colab/management/commands/startplugin.py new file mode 100644 index 0000000..d2bc449 --- /dev/null +++ b/colab/management/commands/startplugin.py @@ -0,0 +1,25 @@ + +import os + +import colab + +from django.core.management.commands.startapp import Command as StartAppCommand + + +class Command(StartAppCommand): + help = ("Creates a Colab plugin directory structure for the given " + "plugin name in the current directory or optionally in the " + "plugin directory.") + missing_args_message = "You must provide a plugin name" + + def handle_template(self, template, subdir): + if template is None: + return os.path.join(colab.__path__[0], 'conf', 'plugin_template') + + return super(Command, self).handle_template(template, subdir) + + def handle(self, name, **kwargs): + kwargs['app_name_dash'] = name.replace('_', '-') + kwargs['app_name_camel'] = name.title().replace('_', '') + kwargs['app_name_verbose'] = name.replace('_', ' ').title() + super(Command, self).handle(name, **kwargs) -- libgit2 0.21.2