[Portland] .desktop file test (was Re: In process? Out of process? And more...)

Bryce Harrington bryce at osdl.org
Wed Dec 21 21:48:12 EET 2005


On Tue, Dec 20, 2005 at 11:08:32PM -0800, Dan Kegel wrote:
> On 12/20/05, Bryce Harrington <bryce at osdl.org> wrote:
> > Anyway, do you think for the purposes of this test case, we could simply
> > check these specific locations for entries of the correct format, and
> > PASS if they're there?  This seems like it'd be fairly easy to write a
> > test for.
> 
> Sure, that'd be a reasonable check of the app's side of the equation.
> Judging by the pages I read, we'd have to check five or so things:
> - .desktop file
> - mime types
> - mime type sniffer
> - startup notification
> - thumbnailer (wait, is http://jens.triq.net/thumbnail-spec/ a fdo
> standard yet, or gnome only?)
> 
> The checklist at the bottom of
> http://primates.ximian.com/~federico/docs/gnome-isv-guide/index.html
> seems like a good start.

Okay, well here's a script for the first item.  The 'XDG Base Directory
Spec' tells where to look up the .desktop file, so looks like you just
iterate over a few dirs and look for the file.

The idea is that you'd run rpm -i or autopackage or Klik or apt-get or
make install or whatever to install your app, then call this script to
check if it installed its .desktop file in the proper location.  You
probably would want to call this ahead of time to check that the app
wasn't already installed.

The script is attached below.  Examples of usage:

  $ ./xdg_lookup_file -D applications/inkscape.desktop
  /usr/local/share/applications/inkscape.desktop

  $ ./xdg_lookup_file -D applications/kde-xmms.desktop

  $ ./xdg_lookup_file -d applications/kde-xmms.desktop
  /home/bryce/.local/share/applications/kde-xmms.desktop

  $ ./xdg_lookup_file -C menus/applications.menu
  /etc/xdg/menus/applications.menu

-D searches the system XDG data dir (only), -d searches the user XDG
data dir as well as the system dir.  -C and -c do the same thing but
search the config dirs.  In any case, it returns 0 if it found
something, 1 if it didn't, and -1 on error.

You could also probably use this to test that the app uninstalled itself
properly.  (I hate it when I uninstall an app and it leaves bits of
itself in my menu system...)

Bryce


#!/bin/bash
# Copyright 2005 Open Source Development Labs
# Distributed under the terms of the GNU General Public License

# This script locates a data or config file within the XDG directory paths

# XDG Base Directory Specification:
# http://standards.freedesktop.org/basedir-spec/latest/ar01s02.html

XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
XDG_CONFIG_HOME=${XDG_DATA_CONFIG:-$HOME/.config}
XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg}
XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}

case $1
    in
    -D) search_path="$XDG_DATA_DIRS"
    ;;
    -d) search_path="$XDG_DATA_HOME:$XDG_DATA_DIRS"
    ;;
    -C) search_path="$XDG_CONFIG_DIRS"
    ;;
    -c) search_path="$XDG_CONFIG_HOME:$XDG_CONFIG_DIRS"
    ;;
esac

item="$2"

if [ -z $search_path -o -z $2 ]; then
    echo "Usage:  $0 [-d|-D|-c|-C] <subdir/filename>"
    exit -1
fi

for path in `echo $search_path | sed -e "s/:/ /g"`; 
do 
  if [ -e $path/$item ]; then
      echo "$path/$item"
      exit 0
  fi
done

exit 1







More information about the Portland mailing list