incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [3/6] git commit: [#4647] Make html2text import in ForgeBlog optional
Date Wed, 09 Jan 2013 19:52:13 GMT
[#4647] Make html2text import in ForgeBlog optional

Signed-off-by: Peter Hartmann <peterhartmann@apache.org>


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

Branch: refs/heads/master
Commit: 3617548fac07bb9a07098c1907d5105c43a9cb63
Parents: 46c751e
Author: Peter Hartmann <peterhartmann@apache.org>
Authored: Thu Dec 27 23:39:15 2012 +0100
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Jan 9 19:47:11 2013 +0000

----------------------------------------------------------------------
 Allura/development.ini                     |    6 ++++++
 ForgeBlog/forgeblog/command/rssfeeds.py    |    9 ++++++++-
 ForgeBlog/forgeblog/main.py                |   10 +++++++---
 ForgeBlog/forgeblog/tests/test_commands.py |   16 ++++++++++++----
 4 files changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3617548f/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 501f8a9..ae550ae 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -213,6 +213,12 @@ auto_reload_templates = true
 # execute malicious code after an exception is raised.
 #set debug = false
 
+# Enable or disable external RSS feed importing in ForgeBlog tool.
+# Default is "false". This feature requires GPL library "html2text". Install it
+# with following command:
+# pip install -e git://github.com/brondsem/html2text.git#egg=html2text
+forgeblog.exfeed = false
+
 [app:tool_test]
 use = egg:Allura
 override_root=basetest_project_root

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3617548f/ForgeBlog/forgeblog/command/rssfeeds.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/command/rssfeeds.py b/ForgeBlog/forgeblog/command/rssfeeds.py
index abbc346..d4f6582 100644
--- a/ForgeBlog/forgeblog/command/rssfeeds.py
+++ b/ForgeBlog/forgeblog/command/rssfeeds.py
@@ -3,7 +3,6 @@ from datetime import datetime
 import re
 
 import feedparser
-import html2text
 from bson import ObjectId
 
 import base
@@ -19,6 +18,14 @@ from forgeblog.main import ForgeBlogApp
 from allura.lib import exceptions
 from allura.lib.decorators import exceptionless
 
+## Everything in this file depends on html2text,
+## so import attempt is placed in global scope.
+try:
+    import html2text
+except ImportError:
+    raise ImportError("""Importing RSS feeds requires GPL library "html2text":
+    https://github.com/brondsem/html2text""")
+
 html2text.BODY_WIDTH = 0
 
 re_amp = re.compile(r'''

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3617548f/ForgeBlog/forgeblog/main.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index 3b46f42..b2cf875 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -6,9 +6,10 @@ import urllib2
 # Non-stdlib imports
 import pkg_resources
 import pymongo
-from tg import expose, validate, redirect, flash
+from tg import config, expose, validate, redirect, flash
 from tg.decorators import with_trailing_slash, without_trailing_slash
 from pylons import g, c, request, response
+from paste.deploy.converters import asbool
 import formencode
 from formencode import validators
 from webob import exc
@@ -123,10 +124,13 @@ class ForgeBlogApp(Application):
         return links
 
     def admin_menu(self):
+        import sys
         admin_url = c.project.url() + 'admin/' + self.config.options.mount_point + '/'
         # temporarily disabled until some bugs are fixed
-        links = [SitemapEntry('External feeds', admin_url + 'exfeed', className='admin_modal')]
-        links += super(ForgeBlogApp, self).admin_menu(force_options=True)
+        links = super(ForgeBlogApp, self).admin_menu(force_options=True)
+        # We don't want external feeds in menu unless they're enabled
+        if asbool(config.get('forgeblog.exfeed', 'false')):
+            links.insert(0, SitemapEntry('External feeds', admin_url + 'exfeed', className='admin_modal'))
         return links
         #return super(ForgeBlogApp, self).admin_menu(force_options=True)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3617548f/ForgeBlog/forgeblog/tests/test_commands.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/test_commands.py b/ForgeBlog/forgeblog/tests/test_commands.py
index 6b4b44c..cf6b00b 100644
--- a/ForgeBlog/forgeblog/tests/test_commands.py
+++ b/ForgeBlog/forgeblog/tests/test_commands.py
@@ -5,7 +5,7 @@ pylons.g = pylons.app_globals
 from pylons import c, g
 from datadiff.tools import assert_equal
 
-from html2text import html2text
+from IPython.testing.decorators import module_not_available, skipif
 
 from ming.orm.ormsession import ThreadLocalORMSession
 
@@ -14,10 +14,10 @@ from allura import model as M
 from allura.lib import security
 from allura.lib import helpers as h
 from forgeblog import model as BM
-from forgeblog.command import rssfeeds
 
 import mock
 
+import feedparser
 
 test_config = 'test.ini#main'
 
@@ -51,7 +51,8 @@ def _mock_feed(*entries):
     return feed
 _mock_feed.i = 0
 
-@mock.patch.object(rssfeeds.feedparser, 'parse')
+@skipif(module_not_available('html2text'))
+@mock.patch.object(feedparser, 'parse')
 def test_pull_rss_feeds(parsefeed):
     parsefeed.return_value = _mock_feed(
         dict(title='Test', subtitle='test', summary='This is a test'),
@@ -81,6 +82,7 @@ def test_pull_rss_feeds(parsefeed):
     BM.Globals(app_config_id=tmp_app._id, external_feeds=new_external_feeds)
     ThreadLocalORMSession.flush_all()
 
+    from forgeblog.command import rssfeeds
     cmd = rssfeeds.RssFeedsCommand('pull-rss-feeds')
     cmd.run([test_config, '-a', tmp_app._id])
     cmd.command()
@@ -102,7 +104,9 @@ def test_pull_rss_feeds(parsefeed):
         " [link](http://example.com/)",
     ]))
 
+@skipif(module_not_available('html2text'))
 def test_plaintext_preprocessor():
+    from html2text import html2text
     text = html2text(
         "[plain]1. foo[/plain]\n"
         "\n"
@@ -120,7 +124,9 @@ def test_plaintext_preprocessor():
         '#foo bar <a class="" href="../baz"> baz </a></p></div>'
     )
 
+@skipif(module_not_available('html2text'))
 def test_plaintext_preprocessor_wrapped():
+    from html2text import html2text
     text = html2text(
         "<p>[plain]1. foo[/plain]</p>\n"
         "\n"
@@ -140,7 +146,7 @@ def test_plaintext_preprocessor_wrapped():
         '<p>#foo bar <a class="" href="../baz"> baz </a></p></div>'
     )
 
-
+@skipif(module_not_available('html2text'))
 def test_plain2markdown():
     text = '''paragraph
 
@@ -168,6 +174,8 @@ http://blah.com/?x=y&a=b - not escaped either
     # note: the \# isn't necessary it could be just # but that's the way
     # html2text escapes all #s currently.  The extra escaping of \# ends up
     # being ok though when rendered
+    
+    from forgeblog.command import rssfeeds
 
     assert_equal(rssfeeds.plain2markdown(text), expected)
 


Mime
View raw message