[diffoscope] 02/03: Improve how jQuery is specified

Jérémy Bobbio lunar at moszumanska.debian.org
Mon Dec 14 00:06:24 CET 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository diffoscope.

commit 05684aadd84f3710884e638558f1c5208cafd2b6
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sun Dec 13 13:20:19 2015 +0000

    Improve how jQuery is specified
    
    When --html-dir is used without specifying --jquery, diffoscope will look for
    its presence in a list of known locations. If found, a symlink will be created
    in the report directory. This makes it easy to use --html-dir in a local manner
    when libjs-jquery is installed in Debian. Supporting other operating systems
    should be as easy as modifying JQUERY_SYSTEM_LOCATIONS.
    
    If jQuery cannot be found in any known system locations, JavaScript will be
    disabled and a warning printed. This will still create usable reports as links
    point to proper HTML pages.
    
    Specifying --jquery=disable will always disable JavaScript.
---
 diffoscope/__main__.py        |  4 ++--
 diffoscope/presenters/html.py | 23 +++++++++++++++++++----
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/diffoscope/__main__.py b/diffoscope/__main__.py
index 0ba3f94..ac7913c 100644
--- a/diffoscope/__main__.py
+++ b/diffoscope/__main__.py
@@ -34,7 +34,7 @@ from diffoscope import logger, VERSION, set_locale, clean_all_temp_files
 import diffoscope.comparators
 from diffoscope.config import Config
 from diffoscope.presenters.html import output_html
-from diffoscope.presenters.html import output_html_directory
+from diffoscope.presenters.html import output_html_directory, JQUERY_SYSTEM_LOCATIONS
 from diffoscope.presenters.text import output_text
 
 
@@ -84,7 +84,7 @@ def create_parser():
     parser.add_argument('--css', metavar='url', dest='css_url',
                         help='link to an extra CSS for the HTML report')
     parser.add_argument('--jquery', metavar='url', dest='jquery_url',
-                        help='link to the jquery url, with --html-dir. By default, a symlink to /usr/share/javascript/jquery/jquery.js is created')
+                        help='link to the jquery url, with --html-dir. Specify “disable” to disable JavaScript. When omitted diffoscope will try to create a symlink to a system installation. Known locations: %s' % ', '.join(JQUERY_SYSTEM_LOCATIONS))
     parser.add_argument('file1', help='first file to compare')
     parser.add_argument('file2', help='second file to compare')
     if not tlsh:
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index c0c605a..cbf092d 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -575,6 +575,8 @@ def file_printer(directory, filename):
         print_func = create_limited_print_func(print_func, Config.general.max_report_size)
         yield print_func
 
+JQUERY_SYSTEM_LOCATIONS = ['/usr/share/javascript/jquery/jquery.js']
+
 def output_html_directory(directory, difference, css_url=None, jquery_url=None):
     """
     Multi-file presenter. Writes to a directory, and puts large diff tables
@@ -589,9 +591,21 @@ def output_html_directory(directory, difference, css_url=None, jquery_url=None):
 
     if not jquery_url:
         jquery_symlink = os.path.join(directory, "jquery.js")
-        if not os.path.exists(jquery_symlink):
-            os.symlink("/usr/share/javascript/jquery/jquery.js", jquery_symlink)
-        jquery_url = "./jquery.js"
+        if os.path.exists(jquery_symlink):
+            jquery_url = "./jquery.js"
+        else:
+            if os.path.lexists(jquery_symlink):
+                os.unlink(jquery_symlink)
+            for path in JQUERY_SYSTEM_LOCATIONS:
+                if os.path.exists(path):
+                    os.symlink("/usr/share/javascript/jquery/jquery.js", jquery_symlink)
+                    jquery_url = "./jquery.js"
+                    break
+            if not jquery_url:
+                logger.warning('--jquery was not specified and jQuery was not found in any known location. Disabling on-demand inline loading.')
+                logger.debug('Locations searched: %s', ', '.join(JQUERY_SYSTEM_LOCATIONS))
+    if jquery_url == 'disable':
+        jquery_url = None
 
     with file_printer(directory, "index.html") as print_func:
         print_func = create_limited_print_func(print_func, Config.general.max_report_size)
@@ -602,5 +616,6 @@ def output_html_directory(directory, difference, css_url=None, jquery_url=None):
             logger.debug('print limit reached')
             print_func(u"<div class='error'>Max output size reached.</div>",
                        force=True)
-        print_func(SCRIPTS % {'jquery_url': escape(jquery_url)}, force=True)
+        if jquery_url:
+            print_func(SCRIPTS % {'jquery_url': escape(jquery_url)}, force=True)
         output_footer(print_func)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list