You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/07/16 21:32:46 UTC

git commit: [#6456] Added importer framework base

Updated Branches:
  refs/heads/cj/6456 [created] 9f81810fe


[#6456] Added importer framework base

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/9f81810f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/9f81810f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/9f81810f

Branch: refs/heads/cj/6456
Commit: 9f81810fe6ed126205e85111f38ffc281d541219
Parents: d2a60bb
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Tue Jul 16 19:23:08 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Tue Jul 16 19:32:19 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py            |  8 +-
 Allura/allura/nf/allura/css/site_style.css      | 66 +++++++++++++++
 ForgeImporters/forgeimporters/__init__.py       |  0
 ForgeImporters/forgeimporters/base.py           | 86 ++++++++++++++++++++
 .../forgeimporters/templates/project_base.html  | 50 ++++++++++++
 ForgeImporters/setup.py                         | 39 +++++++++
 ForgeImporters/test.ini                         | 70 ++++++++++++++++
 7 files changed, 318 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9f81810f/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index bff0399..f0e5a95 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -23,7 +23,7 @@ from itertools import chain, islice
 
 from bson import ObjectId
 from tg import expose, flash, redirect, validate, request, response, config
-from tg.decorators import with_trailing_slash, without_trailing_slash
+from tg.decorators import with_trailing_slash, without_trailing_slash, override_template
 from pylons import tmpl_context as c, app_globals as g
 from paste.deploy.converters import asbool
 from webob import exc
@@ -47,6 +47,7 @@ from allura.lib.widgets import forms as ff
 from allura.lib.widgets import form_fields as ffw
 from allura.lib.widgets import project_list as plw
 from allura.lib import plugin, exceptions
+from forgeimporters.base import ProjectImporter
 from .auth import AuthController
 from .search import SearchController, ProjectBrowseController
 from .static import NewForgeController
@@ -77,6 +78,11 @@ class NeighborhoodController(object):
     def _check_security(self):
         require_access(self.neighborhood, 'read')
 
+    @property
+    def import_project(self):
+        source = request.params.get('source')
+        return ProjectImporter.by_source(source=source)
+
     @expose()
     def _lookup(self, pname, *remainder):
         pname = unquote(pname)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9f81810f/Allura/allura/nf/allura/css/site_style.css
----------------------------------------------------------------------
diff --git a/Allura/allura/nf/allura/css/site_style.css b/Allura/allura/nf/allura/css/site_style.css
index 1322fee..0b4eb92 100644
--- a/Allura/allura/nf/allura/css/site_style.css
+++ b/Allura/allura/nf/allura/css/site_style.css
@@ -3041,3 +3041,69 @@ ul.dropdown ul li a:hover {
     text-align: left;
     margin-right: 0;
 }
+#project-import-form {
+    margin-left: 5px;
+}
+#project-import-form fieldset {
+    margin-top: 10px;
+}
+#project-import-form label {
+    display: block;
+}
+#project-import-form #project-fields label {
+    text-align: right;
+    font-size: 18px;
+    font-weight: 300;
+    line-height: 28px;
+}
+#project-import-form .error {
+    background: transparent;
+    color: red;
+    border: 0;
+}
+#project-import-form .tool {
+    float: left;
+    position: relative;
+    padding: 10px 20px 10px 70px;
+    -moz-border-radius: 4px;
+    -webkit-border-radius: 4px;
+    -o-border-radius: 4px;
+    -ms-border-radius: 4px;
+    -khtml-border-radius: 4px;
+    border-radius: 4px;
+    border: 1px solid #aaa;
+    width: 360px;
+    margin: 5px;
+    background-color: whiteSmoke;
+    height: 74px;
+}
+#project-import-form .tool img {
+    left: 10px;
+    position: absolute;
+    top: 26px;
+}
+#project-import-form .tool label {
+    line-height: 24px;
+    font-size: 18px;
+    font-weight: 600;
+}
+#project-import-form input[type="submit"] {
+    margin-top: 30px;
+    margin-left: 5px;
+    float: none;
+    display: inline-block;
+    position: relative;
+    top: -1em;
+    font-size: 18px;
+    font-weight: 600;
+    text-shadow: none;
+    color: white !important;
+    padding: 1em 2em 1em 2em;
+    text-decoration: none;
+    -webkit-border-radius: 5px;
+    -moz-border-radius: 5px;
+    background: rgb(0,0,0);
+    background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, to(rgb(0,0,0)), from(rgb(90,90,90)));
+    background-image: -moz-linear-gradient(100% 100% 90deg, rgb(0,0,0), rgb(90,90,90) 100%);
+    border: 1px solid black;
+}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9f81810f/ForgeImporters/forgeimporters/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/__init__.py b/ForgeImporters/forgeimporters/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9f81810f/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
new file mode 100644
index 0000000..aa35c48
--- /dev/null
+++ b/ForgeImporters/forgeimporters/base.py
@@ -0,0 +1,86 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+from pkg_resources import iter_entry_points
+
+from tg import request
+
+from ming.utils import LazyProperty
+from allura.controllers import BaseController
+
+
+class ProjectImporter(BaseController):
+    source = None
+
+    @LazyProperty
+    def tool_importers(self):
+        tools = []
+        for ep in iter_entry_points('allura.importers'):
+            ep = ep.load()
+            if ep.source == self.source:
+                tools.append(ep())
+        return tools
+
+    @classmethod
+    def by_source(cls, source):
+        for ep in iter_entry_points('allura.project_importers'):
+            ep = ep.load()
+            if ep.source == source:
+                return ep()
+
+    def index(self, **kw):
+        """
+        Override and expose this view to present the project import form.
+
+        The template used by this view should extend the base template in:
+
+            jinja:forgeimporters:templates/project_base.html
+
+        This will list the available tool importers.  Other project fields
+        (e.g., project_name) should go in the project_fields block.
+        """
+        raise NotImplemented
+
+    def process(self, tools=None, **kw):
+        """
+        Override and expose this to handle a project import.
+
+        This should at a minimum create the stub project with the appropriate
+        tools installed and redirect to the new project, presumably with a
+        message indicating that some data will not be available immediately.
+        """
+        raise NotImplemented
+
+class ToolImporter(object):
+    target_app = None
+    source = None
+    controller = None
+
+    def import_tool(self, project, mount_point):
+        """
+        Override this method to perform the tool import.
+        """
+        raise NotImplementedError
+
+    @property
+    def tool_label(self):
+        return getattr(self.target_app, 'tool_label', None)
+
+    @property
+    def tool_description(self):
+        return getattr(self.target_app, 'tool_description', None)
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9f81810f/ForgeImporters/forgeimporters/templates/project_base.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/templates/project_base.html b/ForgeImporters/forgeimporters/templates/project_base.html
new file mode 100644
index 0000000..7d2aacb
--- /dev/null
+++ b/ForgeImporters/forgeimporters/templates/project_base.html
@@ -0,0 +1,50 @@
+{#-
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+-#}
+{% set hide_left_bar = True %}
+{% extends g.theme.master %}
+{% block title %}{{importer.source}} Project Importer{% endblock %}
+
+{% block header %}{{importer.source}} Project Importer{% endblock %}
+
+{% block content %}
+
+<form id="project-import-form" method="POST" action="process">
+    <input type="hidden" name="source" value="{{request.params.source}}" />
+
+    <fieldset id="project-fields">
+        {% block project_fields %}{% endblock %}
+    </fieldset>
+
+    <fieldset id="tool-fields">
+        {% for tool_importer in importer.tool_importers %}
+        <div class="tool">
+            <img src="{{ g.theme.app_icon_url(tool_importer.target_app, 48) }}" alt="{{ tool_importer.tool_label }} icon">
+            <label>
+                <input name="tools" value="{{tool_importer.tool_label}}" type="checkbox" />
+                {{tool_importer.tool_label}}
+            </label>
+            {{tool_importer.tool_description}}
+        </div>
+        {% endfor %}
+    </fieldset>
+
+    <input type="submit" value="Import" />
+</form>
+
+{% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9f81810f/ForgeImporters/setup.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/setup.py b/ForgeImporters/setup.py
new file mode 100644
index 0000000..5e45638
--- /dev/null
+++ b/ForgeImporters/setup.py
@@ -0,0 +1,39 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+from setuptools import setup, find_packages
+
+
+setup(name='ForgeImporters',
+      description="",
+      long_description="",
+      classifiers=[],
+      keywords='',
+      author='',
+      author_email='',
+      url='',
+      license='',
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=['Allura', ],
+      entry_points="""
+      # -*- Entry points: -*-
+      [allura.project_importers]
+
+      [allura.importers]
+      """,)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9f81810f/ForgeImporters/test.ini
----------------------------------------------------------------------
diff --git a/ForgeImporters/test.ini b/ForgeImporters/test.ini
new file mode 100644
index 0000000..019c262
--- /dev/null
+++ b/ForgeImporters/test.ini
@@ -0,0 +1,70 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+#
+# allura - TurboGears 2 testing environment configuration
+#
+# The %(here)s variable will be replaced with the parent directory of this file
+#
+[DEFAULT]
+debug = true
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 5000
+
+[app:main]
+use = config:../Allura/test.ini
+
+[app:main_without_authn]
+use = config:../Allura/test.ini#main_without_authn
+
+[app:main_with_amqp]
+use = config:../Allura/test.ini#main_with_amqp
+
+[loggers]
+keys = root, allura, tool
+
+[handlers]
+keys = test
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = INFO
+handlers = test
+
+[logger_allura]
+level = DEBUG
+handlers =
+qualname = allura
+
+[logger_tool]
+level = DEBUG
+handlers =
+qualname = forgeshorturl
+
+[handler_test]
+class = FileHandler
+args = ('test.log',)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
+datefmt = %H:%M:%S