allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/7] git commit: [#7316] better git/svn/mercurial naming rather than code-0 etc..
Date Thu, 08 May 2014 14:44:41 GMT
[#7316] better git/svn/mercurial naming rather than code-0 etc..

.. for both bootstrap 'test' project and new projects with
multiple code repos


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

Branch: refs/heads/master
Commit: 515d18df5e6edde289d1cda116b6bae6fc495b7a
Parents: 8cf970b
Author: Dave Brondsema <dave@brondsema.net>
Authored: Wed Apr 16 11:51:41 2014 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu May 8 10:44:08 2014 -0400

----------------------------------------------------------------------
 Allura/allura/controllers/project.py |  4 +++-
 Allura/allura/model/project.py       | 37 ++++++++++++++++++++++++++++---
 Allura/allura/websetup/bootstrap.py  | 12 +++++-----
 3 files changed, 43 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/515d18df/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index bf5e227..db13383 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -242,9 +242,11 @@ class NeighborhoodController(object):
         offset = c.project.next_mount_point(include_hidden=True)
         if tools and not neighborhood.project_template:
             anchored_tools = neighborhood.get_anchored_tools()
+            install_params = []
             for i, tool in enumerate(tools):
                 if (tool.lower() not in anchored_tools.keys()) and (c.project.app_instance(tool)
is None):
-                    c.project.install_app(tool, ordinal=i + offset)
+                    install_params.append(dict(ep_name=tool, ordinal=i + offset))
+            c.project.install_apps(install_params)
         flash('Welcome to the %s Project System! '
               'To get started, fill out some information about your project.' % config['site_name'])
         redirect(c.project.script_name + 'admin/overview')

http://git-wip-us.apache.org/repos/asf/allura/blob/515d18df/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 1fe11b8..587fd11 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -686,13 +686,44 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             key=lambda r: r.name.lower())
         return roles
 
-    def install_app(self, ep_name, mount_point=None, mount_label=None, ordinal=None, **override_options):
-        App = g.entry_points['tool'][ep_name]
+    def install_apps(self, apps_params):
+        '''
+        Install many apps at once. Better than doing individually if you expect
+        default name conflicts (e.g. "code" for both git & svn), by using the
+        tool_label value.
+
+        :param list apps_params: list of dicts, where each dict is the args used
+        in install_app()
+        '''
+        # determine all the mount points
+        mount_points = dict()
+        for app_params in apps_params:
+            App = g.entry_points['tool'][app_params['ep_name']]
+            mount_point = self._mount_point_for_install(App, app_params.get('mount_point'))
+            mount_points[App] = mount_point
+
+        # count mount point names
+        mount_point_counts = Counter(mount_points.values())
+
+        # install each app with unique names
+        for app_params in apps_params:
+            App = g.entry_points['tool'][app_params['ep_name']]
+            mount_point = mount_points[App]
+            if mount_point_counts[mount_point] > 1:
+                app_params.update(mount_point=App.tool_label.lower(),
+                                  mount_label=App.tool_label)
+            self.install_app(**app_params)
+
+    def _mount_point_for_install(self, App, mount_point):
         with h.push_config(c, project=self):
             try:
-                mount_point = v.MountPointValidator(App).to_python(mount_point)
+                return v.MountPointValidator(App).to_python(mount_point)
             except fe.Invalid as e:
                 raise exceptions.ToolError(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)
         if ordinal is None:
             ordinal = int(self.ordered_mounts(include_hidden=True)
                           [-1]['ordinal']) + 1

http://git-wip-us.apache.org/repos/asf/allura/blob/515d18df/Allura/allura/websetup/bootstrap.py
----------------------------------------------------------------------
diff --git a/Allura/allura/websetup/bootstrap.py b/Allura/allura/websetup/bootstrap.py
index 87fed58..1086661 100644
--- a/Allura/allura/websetup/bootstrap.py
+++ b/Allura/allura/websetup/bootstrap.py
@@ -250,12 +250,12 @@ def bootstrap(command, conf, vars):
         p0.add_user(u_admin, ['Admin'])
         log.info('Registering initial apps')
         with h.push_config(c, user=u_admin):
-            for ep_name, app in g.entry_points['tool'].iteritems():
-                if not app._installable(tool_name=ep_name,
-                                        nbhd=n_projects,
-                                        project_tools=[]):
-                    continue
-                p0.install_app(ep_name)
+            p0.install_apps([{'ep_name': ep_name}
+                for ep_name, app in g.entry_points['tool'].iteritems()
+                if app._installable(tool_name=ep_name,
+                                    nbhd=n_projects,
+                                    project_tools=[])
+            ])
 
     # reload our p0 project so that p0.app_configs is accurate with all the
     # newly installed apps


Mime
View raw message