[tools] Add Docs Menu

John J. McDonough jjmcd at fedoraproject.org
Fri Oct 15 14:51:09 UTC 2010


commit 6cf55175f0fba3e5bc4d46ee4dbda10c0567ab84
Author: John J. McDonough <jjmcd at fedoraproject.org>
Date:   Fri Oct 15 10:49:08 2010 -0400

    Add Docs Menu
    
    Include source for buildDocsMenu.pl and docs-menu.spec.  The create
    a menu of online documents on the user's desktop.

 tools/buildDocsMenu/README           |   13 +++
 tools/buildDocsMenu/buildDocsMenu.pl |  176 ++++++++++++++++++++++++++++++++++
 tools/buildDocsMenu/docs-menu.spec   |   57 +++++++++++
 3 files changed, 246 insertions(+), 0 deletions(-)
---
diff --git a/tools/buildDocsMenu/README b/tools/buildDocsMenu/README
new file mode 100644
index 0000000..eb270d2
--- /dev/null
+++ b/tools/buildDocsMenu/README
@@ -0,0 +1,13 @@
+buildDocsMenu is a Perl script that reads fedoradocs.db from docs.fp.o
+and creates a set of .desktop and .xml files to allow a user to access
+the online Fedora documentation directly from the desktop menu.
+
+WHen building the SRPM, both the Perl script and the latest copy of
+fedoradocs.db must be included in the source tarball.  docs-menu.spec
+passes the %{version} in to buildDocsMenu allowing it to create the
+menu for the appropriate version of Fedora.
+
+The resulting .noarch.rpm contains only .desktop and .html files.  The
+.html files examine the user's language and select the appropriate
+URL.  If Javascript is not enabled, the user is presented with a list
+of languages.
diff --git a/tools/buildDocsMenu/buildDocsMenu.pl b/tools/buildDocsMenu/buildDocsMenu.pl
new file mode 100755
index 0000000..f60983e
--- /dev/null
+++ b/tools/buildDocsMenu/buildDocsMenu.pl
@@ -0,0 +1,176 @@
+#!/usr/bin/perl -w
+#
+# buildDocsMenu.pl - Create menu entries for online documentation
+#
+# Script reads the Publican-produced fedoradocs.db (previously
+# extracted from the web git), and creates appropriate .desktop files
+# for those documents.  Those .desktop files point to HTML files which
+# determine the user's language and then open the appropriate 
+# document on docs.fedoraproject.org.
+#
+# Note that these menu entries are somewhat sub-optimal since the
+# name_label field in fedoradocs.db is often blank and there is no
+# subtitle field, so sometimes the only available text is the English
+# language name and the language code.
+
+use DBI;
+use Getopt::Std;
+
+getopt("v",\%args);
+
+# Release of Fedora
+# This could be cleaned up, but it is assumed that the caller will pass
+# in a version from the spec in the form xx.y.z (%{version} in the .spec). 
+# Since this assumes a 2-digit xx, it will not work for versions of
+# Fedora prior to 10.
+my $release_string = $args{v};
+if ( !$release_string ) { die("Must provide release string\n"); }
+my $release = substr($release_string,0,2);
+
+# Open the sqlite file
+my $db = DBI->connect("dbi:SQLite:fedoradocs.db","","",
+		      {RaiseError => 1, AutoCommit => 1});
+
+# Remove any directory from a previous life and create new tree
+#
+# The directory tree mimics how the files should be installed, basically
+# the .desktop files go in /usr/share/applications and the html files in
+# the newly-created /usr/share/doc/HTML/fedora-documentation.
+my $status;
+$status = system("rm -Rf scratch");
+$status = system("mkdir scratch");
+$status = system("mkdir scratch/usr");
+$status = system("mkdir scratch/usr/share");
+$status = system("mkdir scratch/usr/share/applications");
+$status = system("mkdir scratch/usr/share/doc");
+$status = system("mkdir scratch/usr/share/doc/HTML");
+$status = system("mkdir scratch/usr/share/doc/HTML/fedora-documentation");
+
+# Figure out what docs are available for this release
+my $query1 = "SELECT DISTINCT name FROM books WHERE format='html' and version="
+    . $release;
+my $dox = $db->selectall_arrayref($query1);
+
+# Now loop through each document
+foreach my $row1 (@$dox)
+{
+    my ($document) = @$row1;
+    print "\nProcessing $document\n";
+
+    # Open up the .desktop file and print fixed header information
+    my $filename = "scratch/usr/share/applications/" . $document . ".desktop";
+    open OUTPUT, ">", $filename;
+    print OUTPUT "[Desktop Entry]\n";
+    print OUTPUT "Name=$document\n";
+
+    # Pick up the language and name_label for all languages
+    my $query2 = 
+      "SELECT language, name_label FROM books WHERE format='html' AND version="
+      . $release . " AND name='" . $document . "'";
+    my $lines = $db->selectall_arrayref($query2);
+
+    # Add the "Name" line for each language
+    foreach my $row2 (@$lines)
+    {
+	my ($lang, $label) = @$row2;
+	if ( !$label ) { $label="$document $lang"; }
+	print OUTPUT "Name[$lang]=$label\n";
+    }
+
+    # Add the "GenericName" line for each language
+    print OUTPUT "GenericName=$document\n";
+    foreach my $row2 (@$lines)
+    {
+	my ($lang, $label) = @$row2;
+	if ( !$label ) { $label="$document $lang"; }
+	print OUTPUT "GenericName[$lang]=$label\n";
+    }
+
+    # Add the "Comment" line for each language
+    foreach my $row2 (@$lines)
+    {
+	my ($lang, $label) = @$row2;
+	if ( !$label ) { $label="$document $lang"; }
+	print OUTPUT "Comment[$lang]=$label\n";
+    }
+
+    # Now add the trailing bits and close this file
+    print OUTPUT "Exec=htmlview /usr/share/doc/HTML/fedora-documentation/$document.html\n";
+    print OUTPUT "Icon=fedora-documentation\n";
+    print OUTPUT "Type=Application\n";
+    print OUTPUT "Categories=Documentation;X-Red-Hat-Base;\n";
+    print OUTPUT "StartupNotify=true\n";
+    print OUTPUT "OnlyShowIn=GNOME;XFCE;LXDE;\n";
+    close OUTPUT;
+
+    # Now open up the html.  We need some JavaScript that grabs the user's
+    # language and calculates the correct URL for the document.  Most of
+    # the html file is the same for all documents, with only the list
+    # of languages available changing.
+    open OUTPUT, ">", "scratch/usr/share/doc/HTML/fedora-documentation/$document.html";
+    print OUTPUT "<html>\n";
+    print OUTPUT "<head>\n";
+    print OUTPUT "<script language=\"Javascript1.2\">\n";
+    print OUTPUT "<!-- Begin\n";
+    print OUTPUT "if (navigator.appName == 'Netscape')\n";
+    print OUTPUT "  var l1 = navigator.language;\n";
+    print OUTPUT "else\n";
+    print OUTPUT "  var l1 = navigator.browserLanguage;\n";
+    print OUTPUT "-->\n";
+    print OUTPUT "</script>\n";
+    print OUTPUT "<title>$document</title>\n";
+    print OUTPUT "<body>\n";
+    print OUTPUT "<script type=\"text/javascript\">\n";
+    print OUTPUT "  var lang = l1;\n";
+    print OUTPUT "  var match = 0;\n";
+    # Build up a string of the available languages
+    my $langstr = "";
+    foreach my $row2 (@$lines)
+    {
+	my ($lang) = @$row2;
+	if ( length($langstr) > 0 ) { $langstr = $langstr . ", "; }
+	$langstr = $langstr . "\"$lang\"";
+    }
+    print OUTPUT "var locales = [$langstr];\n";
+    print OUTPUT "for(locale in locales)\n";
+    print OUTPUT "  {\n";
+    print OUTPUT "    if(lang == locales[locale])\n";
+    print OUTPUT "      {\n";
+    print OUTPUT "        match = 1;\n";
+    print OUTPUT "        break;\n";
+    print OUTPUT "      }\n";
+    print OUTPUT "  }\n";
+    print OUTPUT "if(match == 0)\n";
+    print OUTPUT "  {\n";
+    print OUTPUT "    for(locale in locales)\n";
+    print OUTPUT "      {\n";
+    print OUTPUT "        var loc_lang = locales[locale].substring(0,2);\n";
+    print OUTPUT "        var lanuage = lang.substring(0,2);\n";
+    print OUTPUT "        if(loc_lang == language)\n";
+    print OUTPUT "          {\n";
+    print OUTPUT "            lang = locales[locale];\n";
+    print OUTPUT "            match = 1;\n";
+    print OUTPUT "            break;\n";
+    print OUTPUT "          }\n";
+    print OUTPUT "      }\n";
+    print OUTPUT "  }\n";
+    print OUTPUT "if(match == 0)\n";
+    print OUTPUT "  {\n";
+    print OUTPUT "    lang = 'en-US';\n";
+    print OUTPUT "  }\n";
+    print OUTPUT "  window.location = \"http://docs.fedoraproject.org/\" + lang + \"/Fedora/$release/html/$document/index.html\";\n";
+    print OUTPUT "</script>\n";
+    # This part is only necessary for users who have disabled Javascript.
+    # It is fairly ugly, presenting the user with a list of available
+    # language codes to choose from.
+    print OUTPUT "<noscript>\n";
+    print OUTPUT "<p>\n<ul>\n<ul>\n";
+    $langstr = "";
+    foreach my $row2 (@$lines)
+    {
+	my ($lang) = @$row2;
+	print OUTPUT "<li><a href=\"http://docs.fedoraproject.org/$lang/Fedora/$release/html/$document/index.html\">$lang</a></li>\n";
+    }
+    print OUTPUT "</ul>\n</ul>\n</p>\n";
+    print OUTPUT "</noscript>\n";
+}
diff --git a/tools/buildDocsMenu/docs-menu.spec b/tools/buildDocsMenu/docs-menu.spec
new file mode 100644
index 0000000..3ca2dd2
--- /dev/null
+++ b/tools/buildDocsMenu/docs-menu.spec
@@ -0,0 +1,57 @@
+Summary:	Menu for Fedora Documentation
+Name:		docs-menu
+Version:	13.0.2
+Release:	1%{?dist}
+License:	GPLv2
+Group:		System Environment/Base
+URL:		http://git.fedorahosted.org/git/?p=docs/web.git
+Source0:	%{name}-%{version}.tar.gz
+BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root
+BuildArch:	noarch
+
+BuildRequires:	/usr/bin/perl
+
+%description
+docs-menu adds menu items for online Fedora documentation.
+
+%prep
+%setup -q
+
+%build
+perl buildDocsMenu.pl -v %{version}
+
+%install
+rm -Rf $RPM_BUILD_ROOT
+mkdir $RPM_BUILD_ROOT
+mkdir $RPM_BUILD_ROOT/usr
+mkdir $RPM_BUILD_ROOT/usr/share
+mkdir $RPM_BUILD_ROOT/usr/share/applications
+mkdir $RPM_BUILD_ROOT/usr/share/doc
+mkdir $RPM_BUILD_ROOT/usr/share/doc/HTML
+mkdir $RPM_BUILD_ROOT/usr/share/doc/HTML/fedora-documentation
+
+
+LOCALSHARE=$RPM_BUILD_ROOT/usr/share
+install -m 755 scratch/usr/share/applications/* $LOCALSHARE/applications/
+LOCALDOC=$LOCALSHARE/doc/HTML
+install -m 644 scratch/usr/share/doc/HTML/fedora-documentation/* \
+	$LOCALDOC/fedora-documentation
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root,-)
+%{_datadir}/applications/
+%{_defaultdocdir}/HTML/fedora-documentation
+
+%changelog
+* Thu Oct 14 2010 John J. McDonough <jjmcd at fedoraproject.org> - 13.0.2
+- Minor cleanup of Perl script
+- More recent database
+
+* Fri Oct  8 2010 John J. McDonough <jjmcd at fedoraproject.org> - 13.0.1
+- Select release via parameter rather than hardcoded
+
+* Tue Oct  5 2010 John J. McDonough <jjmcd at fedoraproject.org> - 13.0.0
+- Fedora 13


More information about the docs-commits mailing list