You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/08/21 17:27:24 UTC
[42/50] git commit: [#4154] ticket:411 project export refactoring
[#4154] ticket:411 project export refactoring
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/7be92777
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/7be92777
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/7be92777
Branch: refs/heads/db/3154b
Commit: 7be92777feee97569877d1134c3aaad2c579a6e8
Parents: 663cc9a
Author: Anton Kasyanov <mi...@gmail.com>
Authored: Thu Aug 15 14:31:27 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Aug 21 15:25:59 2013 +0000
----------------------------------------------------------------------
Allura/allura/ext/admin/admin_main.py | 7 +++--
Allura/allura/ext/admin/templates/export.html | 5 ++++
Allura/allura/model/project.py | 6 +++-
Allura/allura/tasks/export_tasks.py | 33 ++++++++++------------
Allura/allura/tests/functional/test_admin.py | 10 +++++--
5 files changed, 37 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7be92777/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 6031625..9cc0f28 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -106,7 +106,7 @@ class AdminApp(Application):
@staticmethod
def exportable_tools_for(project):
cls = AdminApp
- tools = []
+ tools = [project]
if cls._exportable_tools is None:
for tool in project.ordered_mounts(include_hidden=True):
if not tool.get('ac'):
@@ -142,7 +142,7 @@ class AdminApp(Application):
SitemapEntry('Categorization', admin_url+'trove')
]
links.append(SitemapEntry('Tools', admin_url+'tools'))
- if config.get('bulk_export_enabled', 'false') == 'true':
+ if config.get('bulk_export_enabled', 'true') == 'true':
links.append(SitemapEntry('Export', admin_url + 'export'))
if c.project.is_root and has_access(c.project, 'admin')():
links.append(SitemapEntry('User Permissions', admin_url+'groups/'))
@@ -645,7 +645,8 @@ class ProjectAdminController(BaseController):
redirect('export')
if isinstance(tools, basestring):
tools = [tools]
- allowed = set(t.options.mount_point for t in exportable_tools)
+ allowed = set(t.options.mount_point for t in exportable_tools if hasattr(t, 'options'))
+ allowed.add('project')
if not set(tools).issubset(allowed):
flash('Wrong tools in input data', 'error')
redirect('export')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7be92777/Allura/allura/ext/admin/templates/export.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/export.html b/Allura/allura/ext/admin/templates/export.html
index eff9d5a..6287be7 100644
--- a/Allura/allura/ext/admin/templates/export.html
+++ b/Allura/allura/ext/admin/templates/export.html
@@ -38,8 +38,13 @@
<form method="POST" action="">
{% for tool in tools %}
<div class="grid-19">
+ {% if tool.name %}
+ <input type="checkbox" name="tools" id="tool-{{ loop.index }}" value="project">
+ <label for="tool-{{ loop.index }}">{{ tool.name }}</label> <a href="{{ tool.url() }}">{{ tool.url() }}</a>
+ {% else %}
<input type="checkbox" name="tools" id="tool-{{ loop.index }}" value="{{ tool.options.mount_point }}">
<label for="tool-{{ loop.index }}">{{ tool.options.mount_label }}</label> <a href="{{ tool.url() }}">{{ tool.url() }}</a>
+ {% endif %}
</div>
{% endfor %}
<p><div class="grid-19"><input type="submit" value="Export"></div></p>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7be92777/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 18bd934..41ea5c7 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -17,12 +17,13 @@
import os
import logging
+import json
from collections import Counter, OrderedDict
from datetime import datetime
from copy import deepcopy
import urllib
-from tg import config
+from tg import config, jsonify
from pylons import tmpl_context as c, app_globals as g
from pylons import request
from paste.deploy.converters import asbool
@@ -875,6 +876,9 @@ class Project(MappedClass, ActivityNode, ActivityObject):
elif os.path.exists(tmpdir):
return 'busy'
+ def bulk_export(self, f):
+ json.dump(self, f, cls=jsonify.GenericJSON, indent=2)
+
def __json__(self):
return dict(
shortname=self.shortname,
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7be92777/Allura/allura/tasks/export_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index b5fcb34..bbd4b1d 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -45,33 +45,30 @@ def bulk_export(project_shortname, tools, username, neighborhood):
return
not_exported_tools = []
for tool in tools or []:
- app = project.app_instance(tool)
- if not app:
- log.info('Can not load app for %s mount point. Skipping.' % tool)
- not_exported_tools.append(tool)
- continue
- if not app.exportable:
- log.info('Tool %s is not exportable. Skipping.' % tool)
- not_exported_tools.append(tool)
- continue
+ entry_to_export = None
+ if tool == 'project':
+ entry_to_export = project
+ else:
+ entry_to_export = project.app_instance(tool)
+ if not entry_to_export:
+ log.info('Can not load app for %s mount point. Skipping.' % tool)
+ not_exported_tools.append(tool)
+ continue
+ if not entry_to_export.exportable:
+ log.info('Tool %s is not exportable. Skipping.' % tool)
+ not_exported_tools.append(tool)
+ continue
log.info('Exporting %s...' % tool)
try:
path = create_export_dir(project)
with open(os.path.join(path, '%s.json' % tool), 'w') as f:
- with h.push_context(project._id, app_config_id=app.config._id):
- app.bulk_export(f)
+ with h.push_context(project._id):
+ entry_to_export.bulk_export(f)
except:
log.error('Something went wrong during export of %s' % tool, exc_info=True)
not_exported_tools.append(tool)
continue
- try:
- path = create_export_dir(project)
- with open(os.path.join(path, 'project.json'), 'w') as f:
- json.dump(project, f, cls=tg.jsonify.GenericJSON, indent=2)
- except:
- log.error('Something went wrong during export of project metadata', exc_info=True)
-
if tools and len(not_exported_tools) < len(tools):
# If that fails, we need to let it fail
# there won't be a valid zip file for the user to get.
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7be92777/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index bc16982..9703b76 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -783,9 +783,12 @@ class TestExport(TestController):
def test_exportable_tools_for(self):
project = M.Project.query.get(shortname='test')
+ exportable_tools = AdminApp.exportable_tools_for(project)
tools = [t.options.mount_point
- for t in AdminApp.exportable_tools_for(project)]
+ for t in AdminApp.exportable_tools_for(project)
+ if hasattr(t, 'options')]
assert_equals(tools, [u'wiki', u'wiki2'])
+ assert_in(project, exportable_tools)
def test_access(self):
r = self.app.get('/admin/export',
@@ -820,8 +823,11 @@ class TestExport(TestController):
def test_export_page_contains_hidden_tools(self):
with patch('allura.ext.search.search_main.SearchApp.exportable'):
project = M.Project.query.get(shortname='test')
- tools = [t.options.mount_point for t in AdminApp.exportable_tools_for(project)]
+ exportable_tools = AdminApp.exportable_tools_for(project)
+ tools = [t.options.mount_point for t in exportable_tools
+ if hasattr(t, 'options')]
assert_equals(tools, [u'search', u'wiki', u'wiki2'])
+ assert_in(project, exportable_tools)
def test_tools_not_selected(self):
r = self.app.post('/admin/export')