allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [2/8] allura git commit: [#6057] ticket:788 Handle extra options on tool install
Date Tue, 09 Jun 2015 21:08:25 GMT
[#6057] ticket:788 Handle extra options on tool install


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

Branch: refs/heads/master
Commit: 72decc8f1ac5ee4d2600dbfd3f6fbcd199e4337b
Parents: 0f559d6
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Jun 5 08:52:53 2015 +0000
Committer: Heith Seewald <hseewald@slashdotmedia.com>
Committed: Tue Jun 9 21:06:05 2015 +0000

----------------------------------------------------------------------
 Allura/allura/app.py                  |  7 ++++++-
 Allura/allura/ext/admin/admin_main.py | 12 +++++++++++-
 Allura/allura/model/project.py        | 15 ++++++++++++---
 ForgeLink/forgelink/link_main.py      |  4 +++-
 4 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/72decc8f/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 4d96a8f..c52f1c7 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -55,12 +55,13 @@ class ConfigOption(object):
 
     """
 
-    def __init__(self, name, ming_type, default, label=None):
+    def __init__(self, name, ming_type, default, label=None, validator=None):
         """Create a new ConfigOption.
 
         """
         self.name, self.ming_type, self._default, self.label = (
             name, ming_type, default, label or name)
+        self.validator = validator
 
     @property
     def default(self):
@@ -71,6 +72,10 @@ class ConfigOption(object):
             return self._default()
         return self._default
 
+    def validate(self, value):
+        if self.validator:
+            return self.validator.to_python(value)
+
 
 class SitemapEntry(object):
 

http://git-wip-us.apache.org/repos/asf/allura/blob/72decc8f/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 4ec1568..46cdf9c 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -687,8 +687,18 @@ class ProjectAdminController(BaseController):
                 h.log_action(log, 'install tool').info(
                     'install tool %s', mount_point,
                     meta=dict(tool_type=ep_name, mount_point=mount_point, mount_label=new['mount_label']))
+                App = g.entry_points['tool'][ep_name]
+                # pass only options which app expects
+                config_on_install = {
+                    k: v for (k, v) in kw.iteritems()
+                    if k in [o.name for o in App.options_on_install()]
+                }
                 return c.project.install_app(
-                    ep_name, mount_point, mount_label=new['mount_label'], ordinal=new['ordinal'])
+                    ep_name,
+                    mount_point,
+                    mount_label=new['mount_label'],
+                    ordinal=new['ordinal'],
+                    **config_on_install)
         g.post_event('project_updated')
 
     @h.vardec

http://git-wip-us.apache.org/repos/asf/allura/blob/72decc8f/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index db460a1..e280d63 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -725,6 +725,12 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             except fe.Invalid as e:
                 raise exceptions.ToolError(str(e))
 
+    def _validate_tool_option(self, opt, value):
+        try:
+            return opt.validate(value)
+        except fe.Invalid as e:
+            raise exceptions.ToolError(u'{}: {}'.format(opt.name, str(e)))
+
     def install_app(self, ep_name, mount_point=None, mount_label=None, ordinal=None, **override_options):
         App = g.entry_points['tool'][ep_name]
         mount_point = self._mount_point_for_install(App, mount_point)
@@ -733,10 +739,13 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                           [-1]['ordinal']) + 1
         options = App.default_options()
         options['mount_point'] = mount_point
-        options[
-            'mount_label'] = mount_label or App.default_mount_label or mount_point
+        options['mount_label'] = mount_label or App.default_mount_label or mount_point
         options['ordinal'] = int(ordinal)
-        options.update(override_options)
+        options_on_install = {o.name: o for o in App.options_on_install()}
+        for o, v in override_options.iteritems():
+            if o in options_on_install:
+                v = self._validate_tool_option(options_on_install[o], v)
+            options[o] = v
         cfg = AppConfig(
             project_id=self._id,
             tool_name=ep_name.lower(),

http://git-wip-us.apache.org/repos/asf/allura/blob/72decc8f/ForgeLink/forgelink/link_main.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/link_main.py b/ForgeLink/forgelink/link_main.py
index 87fbdbb..cd43d3f 100644
--- a/ForgeLink/forgelink/link_main.py
+++ b/ForgeLink/forgelink/link_main.py
@@ -49,7 +49,9 @@ class ForgeLinkApp(Application):
         'read': 'View link.',
     }
     config_options = Application.config_options + [
-        ConfigOption('url', str, None)
+        ConfigOption(
+            'url', str, None,
+            validator=fev.URL(not_empty=True, add_http=True)),
     ]
     config_on_install = ['url']
     searchable = True


Mime
View raw message