From 7e61e8d818944f66d6ed34c69a22d2c4c16a56ff41c3940e96427f97cb57e042 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Tue, 13 Dec 2011 11:07:15 +0000 Subject: [PATCH 1/2] Accepting request 96425 from home:coolo:branches:openSUSE:Factory - split brp-trim-desktopfiles that installs a brp script to trim all .desktop files without need of an extra macro OBS-URL: https://build.opensuse.org/request/show/96425 OBS-URL: https://build.opensuse.org/package/show/X11:common:Factory/update-desktop-files?expand=0&rev=29 --- brp-trim-desktop.sh | 46 +++++++++++++++++++++++++++++ macro | 2 +- suse_update_desktop_file.sh | 57 +----------------------------------- update-desktop-files.changes | 6 ++++ update-desktop-files.spec | 26 +++++++++------- 5 files changed, 70 insertions(+), 67 deletions(-) create mode 100644 brp-trim-desktop.sh diff --git a/brp-trim-desktop.sh b/brp-trim-desktop.sh new file mode 100644 index 0000000..f2a9f95 --- /dev/null +++ b/brp-trim-desktop.sh @@ -0,0 +1,46 @@ +#! /bin/sh + +# macro: suse_update_desktop_file +# +# Used to add easily a category to .desktop files according to XDG +# standard. +# + +# +# find file +# +BASEDIR=`dirname $RPM_SOURCE_DIR`/OTHER +if ! test -w $BASEDIR; then + echo "WARNING: Can't write to $BASEDIR, skipping" + exit 0 +fi + +find /$RPM_BUILD_ROOT/opt/kde3/share/applications/kde/ \ + /$RPM_BUILD_ROOT/opt/kde3/share/applnk/ \ + /$RPM_BUILD_ROOT/usr/share/xsessions/ \ + /$RPM_BUILD_ROOT/usr/share/applications/ \ + /$RPM_BUILD_ROOT/usr/share/mimelnk/ \ + /$RPM_BUILD_ROOT/usr/share/gnome/apps/ \ + /$RPM_BUILD_ROOT/etc/xdg/autostart/ -name *.desktop -o -name .directory 2>/dev/null | while read FILE; do + +if grep -q ^X-SuSE-translate= "$FILE"; then + echo "DEBUG: $FILE contains X-SuSE-translate - skipping" >&2 + continue +fi + +# save for backup +if test -w $BASEDIR && test -f /.buildenv; then + echo "<<$FILE>>" >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles + cat $FILE >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles + echo "created $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles" +fi +# +# Trim translations (desktops will use gettext to find them) +# +grep -v -E '^Name\[|^GenericName\[|^Comment\[' $FILE > ${FILE}_ +sed -i -e '/^\[Desktop Entry\]/a \ +X-SuSE-translate=true' ${FILE}_ +mv ${FILE}_ $FILE + +done + diff --git a/macro b/macro index 1e7359c..b748689 100644 --- a/macro +++ b/macro @@ -2,5 +2,5 @@ # Used to add easily a category to .desktop files according to XDG # standard. %suse_update_desktop_file(cinrud:D:N:C:G:) \ - /usr/lib/rpm/suse_update_desktop_file.sh %{?distribution:--project "%distribution"} %{?_project:--project "%_project"} --basedir %_srcrpmdir %{**} || exit 1 \ + /usr/lib/rpm/suse_update_desktop_file.sh %{**} || exit 1 \ %nil diff --git a/suse_update_desktop_file.sh b/suse_update_desktop_file.sh index 228f161..23c48b0 100644 --- a/suse_update_desktop_file.sh +++ b/suse_update_desktop_file.sh @@ -13,15 +13,12 @@ # INSTALL=no I18N=yes -TRIM=no CREATE=no RESET=no UNIMPORTANT=no NAME=no COMMENT=no GNAME=no -BASEDIR=/no -PROJECT= function usage() { local exitcode="$1" @@ -49,8 +46,6 @@ function usage() { echo " file." echo " -n|--no-i18n : Do not prepare the desktop file for translators (obsoletes -t)." echo " (adds X-SuSE-translate=false to the desktop file)" - echo " -t|--trim-i18n : Trim translations (desktops will use gettext to find them)" - echo " otherwise upstream translations are preferred." echo " -i|--install : Install an existing desktop file in /usr/share/applications/" echo " The to be installed desktop file can be located in:" echo " - RPM_SOURCE_DIR or" @@ -68,8 +63,6 @@ function usage() { echo " -C|--comment : Use as \"Comment=\" in desktop file." echo " -N|--name : Use as \"Name=\" in desktop file." echo " -G|--genericname : Use as \"GenericName=\" in desktop file." - echo " --basedir : needed only for -t; normally %_srcrpmdir" - echo " --project : set some default values for if any." echo "" exit $exitcode } @@ -87,10 +80,6 @@ while [ "${1:0:1}" = "-" ]; do I18N=no shift continue;; - -t|--trim-i18n) - TRIM=yes - shift - continue;; -i|--install) INSTALL=yes shift @@ -132,31 +121,12 @@ while [ "${1:0:1}" = "-" ]; do GNAME="${1}" shift continue;; - --basedir) - shift - BASEDIR="${1}" - shift - continue;; - --project) - shift - PROJECT="${1}" - shift - continue;; *) echo "UNKNOWN OPTION: $1" usage 1 ;; esac done -case "$PROJECT" in - SUSE:*|SuSE:*|openSUSE:*) - TRIM=yes - ;; - home:coolo:test-desktop-files*) - TRIM=yes - ;; -esac - APPLICATION="$1" shift if [ "$CREATE" = "yes" ]; then @@ -406,32 +376,7 @@ if [ "$COMMENT" != "no" ]; then fi fi -if [ "$I18N" = "yes" ]; then - - if ! iconv -f utf-8 -t utf-8 $FILE &> /dev/null ; then - echo "ERROR: $FILE is not an UTF-8 file" >&2 - usage 1 - fi - - if [ "$TRIM" = "yes" ]; then - # save for backup - if test -w $BASEDIR && test -f /.buildenv; then - echo "<<$FILE>>" >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles - cat $FILE >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles - echo "created $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles" - fi - # - # Trim translations (desktops will use gettext to find them) - # - grep -v -E '^Name\[|^GenericName\[|^Comment\[' $FILE > ${FILE}_ - sed -i -e '/^\[Desktop Entry\]/a \ -X-SuSE-translate=true' ${FILE}_ - mv ${FILE}_ $FILE - else # silently do nothing - upstream translations preferred - sed -e '/^\[Desktop Entry\]/a \ -X-SuSE-translate=true' $FILE > ${FILE}_ && mv ${FILE}_ $FILE - fi -else +if [ "$I18N" = "no" ]; then # # this file will not get translated # diff --git a/update-desktop-files.changes b/update-desktop-files.changes index 152ae8d..7638f3f 100644 --- a/update-desktop-files.changes +++ b/update-desktop-files.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Dec 9 14:26:41 UTC 2011 - coolo@suse.com + +- split brp-trim-desktopfiles that installs a brp script to trim all + .desktop files without need of an extra macro + ------------------------------------------------------------------- Thu Sep 29 14:58:16 UTC 2011 - vuntz@opensuse.org diff --git a/update-desktop-files.spec b/update-desktop-files.spec index 359438e..06fedc6 100644 --- a/update-desktop-files.spec +++ b/update-desktop-files.spec @@ -15,21 +15,18 @@ # Please submit bugfixes or comments via http://bugs.opensuse.org/ # -# norootforbuild - - Name: update-desktop-files Version: 12.1 -Release: 1 +Release: 0 Summary: A Build Tool to Update Desktop Files -License: GPLv2+ +License: GPL-2.0+ Group: Development/Tools/Building BuildRoot: %{_tmppath}/%{name}-%{version}-build -AutoReqProv: on Source: suse_update_desktop_file.sh Source1: map-desktop-category.sh Source2: macro Source3: desktop.attr +Source4: brp-trim-desktop.sh Source100: mimetypes.prov # This is not true technically, but we do that to make the rpm macros from # desktop-file-utils available to most packages that ship a .desktop file @@ -39,7 +36,13 @@ BuildArch: noarch %description This package provides further translations and a shell script to update -desktop files. It is used by the %suse_update_desktop_file rpm macro. +desktop files. It is used by the %%suse_update_desktop_file rpm macro. + +%package -n brp-trim-desktopfiles +Summary: Trim translations from .deskop files + +%description -n brp-trim-desktopfiles +Trim translations from all .deskop files found in build root %prep %setup -q -n . -D -T 0 @@ -53,13 +56,16 @@ mkdir -p $RPM_BUILD_ROOT%_rpmconfigdir install -m0755 %SOURCE0 %SOURCE1 %SOURCE100 $RPM_BUILD_ROOT%_rpmconfigdir install -m0644 -D %SOURCE2 $RPM_BUILD_ROOT/etc/rpm/macros.%name install -m0644 -D %SOURCE3 $RPM_BUILD_ROOT%_rpmconfigdir/fileattrs/desktop.attr - -%clean -rm -rf $RPM_BUILD_ROOT +install -m0755 -D %SOURCE4 $RPM_BUILD_ROOT/usr/lib/rpm/brp-suse.d/brp-70-trim-desktopfiles %files %defattr(-,root,root) %_rpmconfigdir/* +%exclude %_rpmconfigdir/brp-suse.d /etc/rpm/* +%files -n brp-trim-desktopfiles +%defattr(-,root,root) +%_rpmconfigdir/brp-suse.d + %changelog From 065e41031dd5f5ee8af6307bb6ec752698dc664f940a637d699732339399c240 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Tue, 13 Dec 2011 11:13:15 +0000 Subject: [PATCH 2/2] strip buildroot OBS-URL: https://build.opensuse.org/package/show/X11:common:Factory/update-desktop-files?expand=0&rev=30 --- brp-trim-desktop.sh | 39 +++++++++++++++++++++++---------------- update-desktop-files.spec | 1 + 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/brp-trim-desktop.sh b/brp-trim-desktop.sh index f2a9f95..90c2c4e 100644 --- a/brp-trim-desktop.sh +++ b/brp-trim-desktop.sh @@ -10,6 +10,13 @@ # find file # BASEDIR=`dirname $RPM_SOURCE_DIR`/OTHER + +if ! test -f /.buildenv; then + # this looks fishy, skip it + echo "WARNING: I better not trim without a /.buildenv around" + exit 0 +fi + if ! test -w $BASEDIR; then echo "WARNING: Can't write to $BASEDIR, skipping" exit 0 @@ -23,24 +30,24 @@ find /$RPM_BUILD_ROOT/opt/kde3/share/applications/kde/ \ /$RPM_BUILD_ROOT/usr/share/gnome/apps/ \ /$RPM_BUILD_ROOT/etc/xdg/autostart/ -name *.desktop -o -name .directory 2>/dev/null | while read FILE; do -if grep -q ^X-SuSE-translate= "$FILE"; then - echo "DEBUG: $FILE contains X-SuSE-translate - skipping" >&2 - continue -fi + if grep -q ^X-SuSE-translate= "$FILE"; then + echo "DEBUG: $FILE contains X-SuSE-translate - skipping" >&2 + continue + fi -# save for backup -if test -w $BASEDIR && test -f /.buildenv; then - echo "<<$FILE>>" >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles - cat $FILE >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles - echo "created $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles" -fi -# -# Trim translations (desktops will use gettext to find them) -# -grep -v -E '^Name\[|^GenericName\[|^Comment\[' $FILE > ${FILE}_ -sed -i -e '/^\[Desktop Entry\]/a \ + # save for backup + NFILE=${FILE#$RPM_BUILD_ROOT} + echo "<<$NFILE>>" >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles + cat $FILE >> $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles + echo "trimmed output to $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles" + + # + # Trim translations (desktops will use gettext to find them) + # + grep -v -E '^Name\[|^GenericName\[|^Comment\[' $FILE > ${FILE}_ + sed -i -e '/^\[Desktop Entry\]/a \ X-SuSE-translate=true' ${FILE}_ -mv ${FILE}_ $FILE + mv ${FILE}_ $FILE done diff --git a/update-desktop-files.spec b/update-desktop-files.spec index 06fedc6..8aeffc1 100644 --- a/update-desktop-files.spec +++ b/update-desktop-files.spec @@ -15,6 +15,7 @@ # Please submit bugfixes or comments via http://bugs.opensuse.org/ # + Name: update-desktop-files Version: 12.1 Release: 0