- Generate files that allow easy upstreaming. (boo#1158957)

- Embed SUSE translations to the desktop file
  (add suse_update_desktop_file_process_translations.py).
(The same as rq 1207014, just texts are shorter, referring to openSUSE Wiki.)

OBS-URL: https://build.opensuse.org/package/show/X11:common:Factory/update-desktop-files?expand=0&rev=74
This commit is contained in:
Dirk Mueller 2024-10-28 10:19:16 +00:00 committed by Git OBS Bridge
commit 38409f7bd1
9 changed files with 2188 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.osc

125
brp-trim-translations.sh Normal file
View File

@ -0,0 +1,125 @@
#!/bin/bash
# This script goes through all polkit actions, appstream metadata and mimeinfo xml data
# and copies the .xml files into a .tar.xz for each kind. Then the xml:lang values are
# stripped out.
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
fi
strip_xml_lang() {
type="$1"
file="$2"
notrim="$3"
if grep -q '^<!-- X-SuSE-translate=false -->' "$file"; then
return
fi
nfile="${file#/$RPM_BUILD_ROOT}"
mkdir -p "$(dirname "${BASEDIR}/${type}/${nfile}")"
cp "${file}" "${BASEDIR}/${type}/${nfile}"
if [ -n "${notrim}" ]; then
return # Extraction only
fi
doctype=
if [ "$type" = "polkitactions" ]; then
doctype='<xsl:output doctype-public="-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" doctype-system="http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"/>'
elif [ "$type" = "appstream" ]; then
doctype=''
return # For now
elif [ "$type" = "mimetypes" ]; then
doctype=''
else
echo "Unknown type '${type}'!"
fi
xsltproc --novalid --nonet - "$file" > "${file}_" << EOF
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="UTF-8" />
$doctype
<xsl:strip-space elements="*"/>
<!-- Remove nodes with xml:lang attribute -->
<xsl:template match="node()[@xml:lang]"/>
<!-- Copy everything else recursively -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
EOF
if [ $? -ne 0 ]; then
echo "XSL processing failed - invalid XML?"
else
mv -- "${file}_" "${file}"
echo "trimmed output to ${BASEDIR}/${type}/${nfile}"
fi
}
strip_desktop_lang() {
type="$1"
file="$2"
if grep -q ^X-SuSE-translate= "${file}"; then
return
fi
nfile="${file#/$RPM_BUILD_ROOT}"
mkdir -p "$(dirname "${BASEDIR}/${type}/${nfile}")"
cp "${file}" "${BASEDIR}/${type}/${nfile}"
echo "trimmed output to ${BASEDIR}/${type}/${nfile}"
echo "trimmed output to $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles"
# Remove translations for Name,GenericName and Comment only in the [Desktop Entry] section
awk '/^\[/ { translate=0 } /^\[Desktop Entry\]/ { translate=1; print $0; print "X-SuSE-translate=true"; next } /^(Name\[|GenericName\[|Comment\[)/ && translate==1 { next; } { print $0 }' "${file}" > "${file}_" && mv "${file}_" "${file}"
}
# Handle polkit actions
find "/$RPM_BUILD_ROOT/usr/share/polkit-1/actions/" -type f -name '*.policy' | while read -r file; do
strip_xml_lang "polkitactions" "$file" "notrim"
done
# Handle mimetype info
find "/$RPM_BUILD_ROOT/usr/share/mime/" -type f -name '*.xml' | while read -r file; do
strip_xml_lang "mimetypes" "$file" "notrim"
done
# Handle appstream metainfo
find "/$RPM_BUILD_ROOT/usr/share/metainfo/" "/$RPM_BUILD_ROOT/usr/share/appdata/" -type f -name '*.xml' | while read -r file; do
strip_xml_lang "appstream" "$file" "notrim"
done
# Handle desktop files
find "/$RPM_BUILD_ROOT/usr/share/xsessions/" \
"/$RPM_BUILD_ROOT/usr/share/applications/" \
"/$RPM_BUILD_ROOT/usr/share/autostart/" \
"/$RPM_BUILD_ROOT/etc/xdg/autostart/" \
"/$RPM_BUILD_ROOT/usr/share/wallpapers/" \
"/$RPM_BUILD_ROOT/usr/share/autoinstall/" \
-type f \( -name '*.desktop' -o -name '.directory' \) 2>/dev/null | while read -r file; do
strip_desktop_lang "desktopfiles" "$file"
done
# Pack all files into tars
for type in desktopfiles polkitactions mimetypes appstream; do
[ -d "${BASEDIR}/${type}" ] || continue
pushd "${BASEDIR}/${type}"
tar -cjf "${BASEDIR}/${RPM_PACKAGE_NAME}-${type}.tar.bz2" *
popd
rm -rf "${BASEDIR}/${type}"
done

6
macro Normal file
View File

@ -0,0 +1,6 @@
# macro: %suse_update_desktop_file
# 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 %{**} || exit 1 \
%nil

146
map-desktop-category.sh Normal file
View File

@ -0,0 +1,146 @@
#!/bin/bash
function mapCategory() {
ret=""
local in="${1#X-SuSE-}"
case $in in
#old 9.0 Categories
AddressBook)
ret="ContactManagement"
echo WARNING: AddressBook is an outdated Category, mapping it to ContactManagement
;;
Camera)
ret="Photography"
echo WARNING: Camera is an outdated Category, mapping it to Photography
;;
NewsReader)
ret="News"
echo WARNING: NewsReader is an outdated Category, mapping it to News
;;
DialUp)
ret="Dialup"
echo WARNING: DialUp is an outdated Category, mapping it to Dialup
;;
Telephone)
ret="Telephony"
echo WARNING: Telephone is an outdated Category, mapping it to Telephony
;;
MidiPlayer)
ret="Midi"
echo WARNING: MidiPlayer is an outdated Category, mapping it to Midi
;;
AudioMixer)
ret="Mixer"
echo WARNING: AudioMixer is an outdated Category, mapping it to Mixer
;;
SimulationGame)
ret="Simulation"
echo WARNING: SimulationGame is an outdated Category, mapping it to Simulation
;;
RolePlayingGame)
ret="RolePlaying"
echo WARNING: RolePlayingGame is an outdated Category, mapping it to RolePlaying
;;
School)
ret="Teaching"
echo WARNING: School is an outdated Category, mapping it to Teaching
;;
PuzzleGame)
ret="LogicGame"
echo WARNING: PuzzleGame is an outdated Category, mapping it to LogicGame
;;
#special cases
Internet)
ret="Network"
echo WARNING: Internet is an illegal Category, mapping it to Network
;;
DevelopmentWWW)
ret="X-SuSE-WebDevelopment"
echo WARNING: DevelopmentWWW is an illegal Category, mapping it to WebDevelopment
;;
Language)
ret="Languages"
echo WARNING: Language is an illegal Category, mapping it to Languages
;;
Burning)
ret="DiscBurning"
echo WARNING: Burning is an illegal Category, mapping it to DiscBurning
;;
AudioVideoRecorder)
ret="Recorder"
echo WARNING: AudioVideoRecorder is an illegal Category, mapping it to Recorder
;;
AudioVideoPlayer)
ret="Player"
echo WARNING: AudioVideoPlayer is an illegal Category, mapping it to Player
;;
Photograph)
ret="Photography"
echo WARNING: Photograph is a mistyped Category, mapping it to Photography
;;
#Office Menu:
Calendar|WordProcessor|Spreadsheet|ProjectManagement|Presentation| \
Database|Dictionary|Finance|FlowChart|ContactManagement|PDFViewer) ret=$in ;;
Warehouse|Addressbook)
ret="X-SuSE-$in";;
#Internet/Network Menu:
P2P|HamRadio|Email|News|Dialup|IRCClient|FileTransfer|InstantMessaging|WebBrowser|WebDevelopment|Feed) ret=$in ;;
RSS-News)
ret="X-SuSE-$in";;
#Development Menu:
GUIDesigner|RevisionControl|IDE|Building|Debugger|Profiling|Translation) ret=$in ;;
Design)
ret="X-SuSE-$in";;
#Graphics Menu:
3DGraphics|Photography|Scanning|OCR|VectorGraphics|RasterGraphics|2DGraphics|Maps| \
Publishing|Viewer) ret=$in ;;
#Education and Science Menu:
Art|ArtificialIntelligence|Astronomy|Biology|Chemistry|ComputerScience|Construction| \
DataVisualization|Economy|Electricity|Engineering|Geography|Geology|Geoscience| \
History|Humanities|ImageProcessing|Languages|Literature|Maps|Math|MedicalSoftware| \
Music|NumericalAnalysis|ParallelComputing|Physics|Robotics|Spirituality|Sports| \
Teaching) ret=$in ;;
#Multimedia Menu:
AudioVideoEditing|Music|DiscBurning|Mixer|Player|Midi|Sequencer| \
TV|Tuner|Recorder|Video) ret=$in ;;
CD|CDReader|Jukebox)
ret="X-SuSE-$in";;
#System Menu:
Applet|Emulator|Monitor|Screensaver|TerminalEmulator|SystemSetup| \
FileManager|Filesystem|Archiving|PackageManager|TrayIcon| \
Security|RemoteAccess) ret=$in ;;
ServiceConfiguration| \
Backup|YaST|YaST-Hardware|YaST-Misc|YaST-Network|YaST-Virtualization|YaST-Support| \
Feedback|YaST-Net_advanced|YaST-Security|YaST-Software|YaST-System|YaST-AppArmor|YaST-High_Availability)
ret="X-SuSE-$in" ;;
#Utility Menu:
Telephony|Accessibility|TextEditor|PDA|Calculator|Clock) ret=$in ;;
DesktopUtility|SyncUtility|PrintingUtility|TimeUtility|WebUtility|Editor)
ret="X-SuSE-$in" ;;
#Game Menu:
3DGame|Amusement|ArcadeGame|CardGame|FirstPersonGame|BoardGame|\
PlatformGame|PuzzleGame|SportsGame|StrategyGame|BlocksGame| \
ActionGame|AdventureGame|KidsGame|LogicGame|Simulation|RolePlaying|Shooter)
ret=$in ;;
#Control Center Categories:
ControlCenter-Personal|ControlCenter-Hardware|ControlCenter-LookAndFeel|ControlCenter-System)
ret="X-SuSE-$in" ;;
#XFCE Private Categories:
X-Xfce*|X-XFCE*)
ret="$in" ;;
#special tags:
Application|Qt|KDE|GTK|GNOME|XFCE|Motif|ConsoleOnly|Shell|X-Red-*| \
X-Ximian-*|X-GNOME-*|X-KDE-*|Settings|DesktopSettings|HardwareSettings| \
Office|Network|Game|Graphics|Education|Documentation|Development| \
Science|System|Utility|AudioVideo|AdvancedSettings|More) ret=$in ;;
Core-Edutainment|Core-Game|Core-Graphics|Core-Internet| \
Core-Multimedia|Core-Office|Core-Settings|Core-Utility|Core-System| \
Core-Configuration|Core-Development|core)
ret="X-SuSE-$in" ;;
Core)
ret="$in" ;;
*) ret="" ;;
esac
}

499
suse_update_desktop_file.sh Normal file
View File

@ -0,0 +1,499 @@
#!/bin/bash
# macro: suse_update_desktop_file
#
# Used to add easily a category to .desktop files according to XDG
# standard.
#
. /usr/lib/rpm/map-desktop-category.sh
#
# parse arguments
#
INSTALL=no
I18N=yes
CREATE=no
RESET=no
UNIMPORTANT=no
NAME=no
COMMENT=no
GNAME=no
function usage() {
local exitcode="$1"
if [ -z "$exitcode" ]; then
exitcode=1
fi
echo
echo "Usage: $(basename $0) [OPTIONS] <APPLICATION> [CATEGORIES]"
echo
echo " Summary:"
echo " Used to add easily a category to .desktop files according to XDG"
echo " standard. More information is available on"
echo " http://en.opensuse.org/SUSE_Package_Conventions/RPM_Macros"
echo " If you have any questions, please use our mailinglist: "
echo " opensuse-packaging@opensuse.org"
echo " Options:"
echo " <APPLICATION> : The name of the desktop file."
echo " Example: use \"qbrew\" to edit qbrew.desktop"
echo " If APPLICATION has multiple desktop files, try the exact path"
echo " to the desktop file."
echo " Example: use \"%suse_update_desktop_file \\"
echo " %{buildroot}%{_datadir}/susehelp/meta/%name/%name.desktop\""
echo " to edit the susehelp desktop entry file instead."
echo " -u|--unimportant : add \"NoDisplay=true\" to the resulting desktop"
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 " -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"
echo " - RPM_BUILD_DIR"
echo " A referenced icon file (ending *.png; *.xpm) is installed in"
echo " /usr/share/pixmaps/ automatically if it is located in one of the "
echo " directories mentioned above (-maxdepth 1)."
echo " -r|--reset : Reset the \"Categories\" line in an existing desktop file."
echo " Normally, categories mentioned in an existing desktop file will be"
echo " obtained. Additional categories from commandline are added."
echo " -d|--docid <string> : Add \"X-SuSE-DocTeamID=<string>\" to the desktop file."
echo " -D|--docpath <path> : Add \"DocPath=<path>\" to the desktop file - do not guess it"
echo " automatically."
echo " -c|--create <name> : Create a new desktop file in /usr/share/applications/<name>.desktop ."
echo " -C|--comment <string> : Use <string> as \"Comment=<string>\" in desktop file."
echo " -N|--name <string> : Use <string> as \"Name=<string>\" in desktop file."
echo " -G|--genericname <string> : Use <string> as \"GenericName=<string>\" in desktop file."
echo ""
exit $exitcode
}
while [ "${1:0:1}" = "-" ]; do
case ${1} in
-h|--help)
usage 0 ;;
-u|--unimportant)
UNIMPORTANT=yes
shift
continue;;
-n|--no-i18n)
I18N=no
shift
continue;;
-i|--install)
INSTALL=yes
shift
continue;;
-r|--reset)
RESET=yes
shift
continue;;
-d|--docid)
shift
DOCID="${1}"
shift
continue;;
-D|--docpath)
shift
DOCPATH="${1}"
if ! [ -r "$RPM_BUILD_ROOT/opt/kde3/share/doc/HTML/en/$DOCPATH/index.docbook" -o -r $RPM_BUILD_ROOT/usr/share/gnome/help/$DOCPATH/C/$DOCPATH.xml -o -r $RPM_BUILD_ROOT/usr/share/gnome/help/${DOCPATH/\///C/} ] ; then
echo WARNING: suse_update_desktop_file: DocPath target $DOCPATH for $FILE does not exist
fi
shift
continue;;
-c|--create)
CREATE=yes
INSTALL=yes
shift
continue;;
-C|--comment)
shift
COMMENT="${1}"
shift
continue;;
-N|--name)
shift
NAME="${1}"
shift
continue;;
-G|--genericname)
shift
GNAME="${1}"
shift
continue;;
--basedir)
echo "WARNING: basedir is no longer supported"
shift
shift
continue;;
--project)
echo "WARNING: project is no longer supported"
shift
shift
continue;;
*)
echo "UNKNOWN OPTION: $1"
usage 1 ;;
esac
done
APPLICATION="$1"
shift
if [ "$CREATE" = "yes" ]; then
NAME="$1"
shift
GNAME="$1"
shift
EXEC="$1"
shift
ICON="$1"
shift
if [ -z "$NAME" -o -z "$EXEC" ]; then
echo "ERROR: after --create you should define" >&2
echo " DESKTOP_FILE_NAME NAME GENERICNAME EXECUTABLE \[ ICON CATEGORIES... \]" >&2
usage 1
fi
mkdir -p $RPM_BUILD_ROOT/usr/share/applications/
cat > $RPM_SOURCE_DIR/$APPLICATION.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
Name=$NAME
GenericName=$GNAME
Type=Application
Exec=$EXEC
Icon=$ICON
EOF
NAME=no
GNAME=no
fi
if [ "$INSTALL" = "yes" ]; then
mkdir -p $RPM_BUILD_ROOT/usr/share/applications/
FILE=`find $RPM_SOURCE_DIR $RPM_BUILD_DIR . -name $APPLICATION.desktop| sort -r | head -n 1`
if [ -s "$FILE" ]; then
cp -v "$FILE" $RPM_BUILD_ROOT/usr/share/applications/
icon_file=`sed -n '/^\[Desktop Entry\]/,/(\[.*|$)/ s,Icon=\(.*\),\1,p' "$FILE"`
icon_file=`find $RPM_SOURCE_DIR $RPM_BUILD_DIR -maxdepth 1 -name ${icon_file}.png -o -name ${icon_file}.xpm -o -name $icon_file | sort -r | head -n 1`
if [ -s "$icon_file" ]; then
mkdir -p $RPM_BUILD_ROOT/usr/share/pixmaps/
cp -v "$icon_file" $RPM_BUILD_ROOT/usr/share/pixmaps/
fi
fi
fi
while [ "$1" ]; do
CATEGORIES="$CATEGORIES;$1"
shift
done
CATEGORIES="${CATEGORIES#;}"
if [ -z "$APPLICATION" ]; then
echo "ERROR: suse_update_desktop_file: no application argument given" >&2
echo " Example: use "qbrew" to edit qbrew.desktop" >&2
usage 1
fi
#
# find file
#
for i in /$RPM_BUILD_ROOT/usr/share/applications/ \
/$RPM_BUILD_ROOT/etc/xdg/autostart/ ; do
[ -e "$i" ] && DIRS="$DIRS $i"
done
if [ "${APPLICATION:0:1}" == "/" -a -e "$APPLICATION" ]; then
FILE_="$APPLICATION"
else
FILE_=`find $DIRS -name $APPLICATION.desktop`
fi
if [ -z "$FILE_" ]; then
echo "ERROR: suse_update_desktop_file: unable to find $APPLICATION" >&2
usage 1
fi
FILE=""
for i in $FILE_; do
#
# fix old files
#
sed -e 's/\[KDE Desktop Entry\]/[Desktop Entry]/' "$i" > "${i}_" && mv "${i}_" "$i"
# dos2unix for the poor
sed -e 's/\r//' "$i" > "${i}_" && mv "${i}_" "$i"
if [ "$FILE" ]; then
echo "ERROR: suse_update_desktop_file: $APPLICATION has multiple desktop files" >&2
usage 1
fi
FILE=$i
done
#
# validate file
#
if [ ! -r "$FILE" ]; then
echo "ERROR: suse_update_desktop_file: unable to read $FILE" >&2
usage 1
fi
# esp. for susehelp
FILE_DOCPATH=`sed -n -e '/^\[Desktop Entry\]/,/(\[.*|$)/ s,;, ,g' -e 's,^DocPath=\\(.*\\),\\1,p' ${FILE}`
if [ -n "$FILE_DOCPATH" ] ; then
if [ ! -r "$RPM_BUILD_ROOT/usr/share/gnome/help/$FILE_DOCPATH/C/$FILE_DOCPATH.xml" ] && [ ! -r $RPM_BUILD_ROOT/usr/share/gnome/help/${DOCPATH/\///C/} ] ; then
echo WARNING: suse_update_desktop_file: DocPath target $FILE_DOCPATH for $FILE does not exist
fi
fi
#BEGIN Upstreaming help
DESKTOP_NAME=${APPLICATION##*/}
DESKTOP_PATH=${APPLICATION%$DESKTOP_NAME}
DESKTOP_NAME=${DESKTOP_NAME%.desktop}
if test -z "$DESKTOP_PATH" ; then
DESKTOP_PATH=$RPM_BUILD_ROOT/usr/share/applications/
fi
# Get rid ugly but common slash duplication
DESKTOP_PATH=${DESKTOP_PATH//\/\//\/}
# Set working directory always to $RPM_BUILD_DIR. It prevents placing
# the files inside BUILDROOT. And some packages are confused by new
# desktop files placed to its build directory.
SUDF_DIR=$RPM_BUILD_DIR
mkdir -p $SUDF_DIR/suse_update_desktop_file/update-desktop-files/$DESKTOP_NAME
cp -v "$FILE" $SUDF_DIR/suse_update_desktop_file/update-desktop-files/$DESKTOP_NAME/$DESKTOP_NAME-upstream.desktop
#END Upstreaming help
#
# update Categories
#
if [ "$RESET" = "no" ]; then
CATIN=`sed -n -e '/^\[Desktop Entry\]/,/(\[.*|$)/ s,;, ,g' -e 's,^Categories=\\(.*\\),\\1,p' ${FILE}`
fi
CATIN="$CATIN ${CATEGORIES//;/ }"
unset CAT
unset DCAT
for i in $CATIN; do
ret=""
mapCategory $i
if [ -z "$ret" ]; then
echo "WARNING: Category \"$i\" is unknown \!"
echo WARNING: it is ignored, until you registered a Category at opensuse-packaging@opensuse.org .
else
echo "$CAT" | grep -q "[=;]$i;" || CAT="$CAT$ret;"
fi
done
echo "" >> "${FILE}"
CAT="${CAT#;}"
if grep -q ^Categories= $FILE; then
sed -i -e '/^\[Desktop Entry\]/,/(\[.*|$)/ s,^Categories=.*,Categories='${CAT}',' "$FILE"
else
if [ -n "${CAT%;}" ]; then
sed -i -e '/^\[Desktop Entry\]/a \
'"Categories=${CAT%;};" $FILE
fi
fi
if [ "$UNIMPORTANT" = "yes" ]; then
if grep -q ^NoDisplay= $FILE; then
sed -i -e '/^\[Desktop Entry\]/,/(\[.*|$)/ s,^NoDisplay=.*,NoDisplay=true,' "$FILE"
else
sed -i -e '/^\[Desktop Entry\]/a \
NoDisplay=true' $FILE
fi
fi
if [ "$DOCID" ]; then
sed -i -e '/^\[Desktop Entry\]/a \
'"X-SuSE-DocTeamID=$DOCID" $FILE
fi
#
# check or set DocPath
#
DOCPATH_IS_GUESS=false
if [ -z "$DOCPATH" ] ; then
if [ -f $RPM_BUILD_ROOT/usr/share/gnome/help/$APPLICATION/C/$APPLICATION.xml ] ; then
DOCPATH=$APPLICATION
DOCPATH_IS_GUESS=true
fi
# NOTE: Here we can add guess for application/file.xml
fi
if [ -n "$DOCPATH" ] ; then
if [ -n "$FILE_DOCPATH" ] ; then
# DocPath already exists. Update it only from command line, not from guess.
if $DOCPATH_IS_GUESS ; then
if [ "$DOCPATH" != "$FILE_DOCPATH" ] ; then
echo WARNING: suse_update_desktop_file: DocPath target $FILE_DOCPATH differs from guess $DOCPATH for $FILE
fi
else
sed -e '/^\[Desktop Entry\]/,/(\[.*|$)/ s,^DocPath=.*,DocPath='${DOCPATH}',' "$FILE" > "${FILE}.new" &&
mv "${FILE}.new" "${FILE}"
fi
else
sed -i -e '/^\[Desktop Entry\]/a \
'"DocPath=${DOCPATH}" $FILE
if $DOCPATH_IS_GUESS ; then
echo NOTE: suse_update_desktop_file: Guessing DocPath=$DOCPATH in $FILE
fi
fi
fi
if grep -q ^X-SuSE-translate= $FILE; then
echo "ERROR: $FILE contains X-SuSE-translate - called the macro twice?" >&2
usage 1
fi
if [ "$NAME" != "no" ]; then
sed -i -e '/^Name\[/d' $FILE
if [ -n "$NAME" ]; then
if ! grep -q ^Name= ${FILE}; then
sed -i -e '/^\[Desktop Entry\]/a '"Name=${NAME//,/\,}" ${FILE}
else
sed -i -e '/^\[Desktop Entry\]/,/(\[.*|$)/ s,^Name=.*,Name='"${NAME//,/\,}"',' ${FILE}
fi
else
sed -i -e '/^Name=/d' $FILE
fi
fi
if [ "$GNAME" != "no" ]; then
sed -i -e '/^GenericName\[/d' $FILE
if [ -n "$GNAME" ]; then
if ! grep -q ^GenericName= ${FILE}; then
sed -i -e '/^\[Desktop Entry\]/a '"GenericName=${GNAME//,/\,}" ${FILE}
else
sed -i -e '/^\[Desktop Entry\]/,/(\[.*|$)/ s,^GenericName=.*,GenericName='"${GNAME//,/\,}"',' ${FILE}
fi
else
sed -i -e '/^GenericName=/d' $FILE
fi
fi
if [ "$COMMENT" != "no" ]; then
sed -i -e '/^Comment\[/d' $FILE
if [ -n "$COMMENT" ]; then
if ! grep -q ^Comment= ${FILE}; then
sed -i -e '/^\[Desktop Entry\]/a '"Comment=${COMMENT//,/\,}" ${FILE}
else
sed -i -e '/^\[Desktop Entry\]/,/(\[.*|$)/ s,^Comment=.*,Comment='"${COMMENT//,/\,}"',' ${FILE}
fi
else
sed -i -e '/^Comment=/d' $FILE
fi
fi
#BEGIN Upstreaming help
GENERIC_CHANGES=false
TRANSLATION_CHANGES=false
shopt -s nullglob
cp -v "$FILE" $SUDF_DIR/suse_update_desktop_file/update-desktop-files/$DESKTOP_NAME/$DESKTOP_NAME-downstream-no-translation.desktop
# Insert translations from the downstream
ORIG_DIR=$PWD
cd $SUDF_DIR/suse_update_desktop_file/update-desktop-files/$DESKTOP_NAME
if [ "$I18N" != "no" ]; then
sed "s@^Name=@_&Name($DESKTOP_NAME.desktop): @;s@^GenericName=@_&GenericName($DESKTOP_NAME.desktop): @;s@^Comment=@_&Comment($DESKTOP_NAME.desktop): @;s@^Keywords=@_&Keywords($DESKTOP_NAME.desktop): @" $FILE >$DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop
intltool-merge /usr/share/desktop-translations/desktop_translations $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop $DESKTOP_NAME-downstream-translated-raw.desktop -d -u
sed -i "s@^Name=Name($DESKTOP_NAME.desktop): @Name=@;s@^GenericName=GenericName($DESKTOP_NAME.desktop): @GenericName=@;s@^Comment=Comment($DESKTOP_NAME.desktop): @Comment=@;s@^Keywords=Keywords($DESKTOP_NAME.desktop): @Keywords=@" $DESKTOP_NAME-downstream-translated-raw.desktop
${0%.sh}_process_translations.py $DESKTOP_NAME
cp -a -v $DESKTOP_NAME-downstream-translated.desktop $FILE
if ! diff -u $DESKTOP_NAME-upstream.desktop $DESKTOP_NAME-downstream-translated.desktop >$DESKTOP_NAME-downstream-directly-translated.diff ; then
TRANSLATION_CHANGES=true
fi
sed -i "1,2s/$DESKTOP_NAME-\(upstream\|downstream-translated\).desktop/$DESKTOP_NAME.desktop/" $DESKTOP_NAME-downstream-directly-translated.diff
for DESKTOP in $DESKTOP_NAME-upstream $DESKTOP_NAME-downstream-no-translation ; do
sed "/\(Name\|GenericName\|Comment\|Keywords\)\[/d;s@^Name=@_Name=@;s@^GenericName=@_GenericName=@;s@^Comment=@_Comment=@;s@^Keywords=@_Keywords=@" $DESKTOP.desktop >$DESKTOP.desktop.in
done
if ! diff -u $DESKTOP_NAME-upstream.desktop.in $DESKTOP_NAME-downstream-no-translation.desktop.in >$DESKTOP_NAME-downstream-in-translated.diff ; then
GENERIC_CHANGES=true
fi
sed -i "1,2s/$DESKTOP_NAME-\(upstream\|downstream-no-translation\).desktop.in/$DESKTOP_NAME.desktop.in/" $DESKTOP_NAME-downstream-in-translated.diff
mkdir po
intltool-extract --type=gettext/ini $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop
xgettext --default-domain=$DESKTOP_NAME --add-comments --keyword=_ --keyword=N_ --keyword=U_ $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop.h -o po/$DESKTOP_NAME.pot
for PO in /usr/share/desktop-translations/desktop_translations/*.po ; do
LNG=${PO##*/}
LNG=${LNG%.po}
msgmerge $PO po/$DESKTOP_NAME.pot -o po/$LNG-pre.po
if test -f po/$LNG-pre.po ; then
msgattrib --no-obsolete po/$LNG-pre.po -o po/$LNG.po
fi
sed -i "s@\"\(Name\|GenericName\|Comment\|Keywords\)($DESKTOP_NAME.desktop): @\"@" po/$LNG.po
rm po/$LNG-pre.po
done
sed -i "s@\"\(Name\|GenericName\|Comment\|Keywords\)($DESKTOP_NAME.desktop): @\"@" po/$DESKTOP_NAME.pot
rm $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop $DESKTOP_NAME-downstream-no-translation-desktop_translations.desktop.h $DESKTOP_NAME-downstream-translated-raw.desktop
fi
# Generate output in the OTHER directory
cd ..
RPM_OTHER_DIR=${RPM_BUILD_DIR%/BUILD*}/OTHER
if test -f $RPM_OTHER_DIR/update-desktop-files.tar.gz ; then
X=r
else
X=c
fi
cd ..
tar ${X}f $RPM_OTHER_DIR/update-desktop-files.tar.gz update-desktop-files
EOF=EOF
cat <<EOF
========================= Deprecation notice ==============================
%suse_update_desktop_file is deprecated and will be removed in the future.
It provides SUSE specific changes that were never sent to the upstream.
there is a time to change this now.
Please follow
https://en.opensuse.org/openSUSE:Update-desktop-files_deprecation
Are there any generic changes to upstream: $GENERIC_CHANGES
Are there any translation changes to upstream: $TRANSLATION_CHANGES
Location of the upstreaming files during the build:
$SUDF_DIR/suse_update_desktop_file/$DESKTOP_NAME
- $DESKTOP_NAME-downstream-directly-translated.diff
- $DESKTOP_NAME-downstream-in-translated.diff
- $DESKTOP_NAME-downstream-no-translation.desktop
- $DESKTOP_NAME-downstream-no-translation.desktop.in
- $DESKTOP_NAME-downstream-translated.desktop
- $DESKTOP_NAME-upstream.desktop
- $DESKTOP_NAME-upstream.desktop.in
Customized helpers for you:
cd update-desktop-files/$DESKTOP_NAME/po
for PO in *.po ; do
if test -f ../../../po/\$PO ; then
msgcat --use-first \$PO ../../../po/\$PO -o ../../../po/\$PO.new
mv ../../../po/\$PO.new ../../../po/\$PO
else
cp -a \$PO ../../../po/\$PO
fi
done
Or swap arguments of msgcat according to the documentation:
msgcat --use-first ../../../po/\$PO \$PO -o ../../../po/\$PO.new
sed "/\(Name\|GenericName\|Comment\|Keywords\)\[/d;s@^Name=@_Name=@;s@^GenericName=@_GenericName=@;s@^Comment=@_Comment=@;s@^Keywords=@_Keywords=@" <$DESKTOP_NAME.desktop >$DESKTOP_NAME.desktop.in
patch <$DESKTOP_NAME-downstream-in-translated.diff
Source{number}: $DESKTOP_NAME.desktop.in
or
Source{number}: $DESKTOP_NAME.desktop
cp %{SOURCE{NUMBER}} .
%translate_suse_desktop $DESKTOP_NAME.desktop
install -D -m 0644 $DESKTOP_NAME.desktop %{buildroot}${DESKTOP_PATH#$RPM_BUILD_ROOT}$DESKTOP_NAME.desktop
osc add $DESKTOP_NAME.desktop.in
osc rm $DESKTOP_NAME.desktop
if ! diff $DESKTOP_NAME.desktop %{SOURCE{number}} ; then
cat <<EOF
A new version of desktop file exists. Please update $DESKTOP_NAME.desktop
rpm source from $PWD to get translations to older products.
$EOF
-===========================================================================
EOF
cd $ORIG_DIR
#END Upstreaming help
if [ "$I18N" = "no" ]; then
#
# this file will not get translated
#
sed -i -e '/^\[Desktop Entry\]/a \
X-SuSE-translate=false' $FILE
fi

View File

@ -0,0 +1,67 @@
#!/usr/bin/python3
import sys
file = sys.argv[1]
po_raw = open(file + '-downstream-translated-raw.desktop', 'r')
po_clean = open(file + '-downstream-translated.desktop', 'w')
lines = po_raw.readlines()
items = dict()
name_processing = False
genericname_processing = False
comment_processing = False
keywords_processing = False
for line in lines:
if ( name_processing and not (line.startswith("Name[") or\
line.startswith("Name="))) or\
( genericname_processing and not (line.startswith("GenericName[") or\
line.startswith("GenericName="))) or\
( comment_processing and not (line.startswith("Comment[") or\
line.startswith("Comment="))) or\
( keywords_processing and not (line.startswith("Keywords[") or\
line.startswith("Keywords="))):
name_processing = False
genericname_processing = False
comment_processing = False
keywords_processing = False
for item in sorted(items):
po_clean.write(items[item])
items = dict()
# Why lang = "AAAA"? Untranslated string is supposed to be first,
# but not all desktop files conform to this conventions. Expect it
# anywhere, but move it to the beginning of the list.
if line.startswith("Name["):
name_processing = True
lang = line[5:line.find(']')]
items[lang] = line
elif line.startswith("Name="):
name_processing = True
lang = "AAAA"
items[lang] = line
elif line.startswith("GenericName["):
genericname_processing = True
lang = line[12:line.find(']')]
items[lang] = line
elif line.startswith("GenericName="):
genericname_processing = True
lang = "AAAA"
items[lang] = line
elif line.startswith("Comment["):
comment_processing = True
lang = line[8:line.find(']')]
items[lang] = line
elif line.startswith("Comment="):
comment_processing = True
lang = "AAAA"
items[lang] = line
elif line.startswith("Keywords["):
keywords_processing = True
lang = line[9:line.find(']')]
items[lang] = line
elif line.startswith("Keywords="):
keywords_processing = True
lang = "AAAA"
items[lang] = line
else:
po_clean.write(line)

1221
update-desktop-files.changes Normal file

File diff suppressed because it is too large Load Diff

100
update-desktop-files.spec Normal file
View File

@ -0,0 +1,100 @@
#
# spec file for package update-desktop-files
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
Name: update-desktop-files
Version: 84.87
Release: 0
Summary: A Build Tool to Update Desktop Files
License: GPL-2.0-or-later
Group: Development/Tools/Building
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source: suse_update_desktop_file.sh
Source1: map-desktop-category.sh
Source2: macro
Source4: brp-trim-translations.sh
Source5: suse_update_desktop_file_process_translations.py
# 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
# (since they already have a update-desktop-files BuildRequires).
Requires: desktop-file-utils
Requires: desktop-translations-devel
Requires: gettext-tools
Requires: intltool
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.
%package -n brp-trim-translations
Summary: Trim translations from desktop files, polkit actions, mimetype descriptions and AppStream metainfo
Group: Development/Tools/Building
Provides: brp-trim-desktop = %{version}
Obsoletes: brp-trim-desktop < %{version}
Requires: awk
Requires: libxslt-tools
Conflicts: brp-extract-translations
%description -n brp-trim-translations
Extract and trim translations from all desktop files, polkit
actions, mimetype descriptions and AppStream metainfo found in
build root
%package -n brp-extract-translations
Summary: Extract translations from desktop files, polkit actions, mimetype descriptions and AppStream metainfo
Group: Development/Tools/Building
Provides: brp-trim-desktop = %{version}
Obsoletes: brp-trim-desktop < %{version}
Requires: libxslt-tools
Conflicts: brp-trim-translations
%description -n brp-extract-translations
Extract translations from all desktop files, polkit actions, mimetype descriptions
and AppStream metainfo found in build root
%prep
%setup -q -D -T 0 -c
# supi hack
sed -e '/awk/d' < %SOURCE4 > brp-extract-translations
%build
%install
mkdir -p $RPM_BUILD_ROOT%_rpmconfigdir
install -m0755 %SOURCE0 %SOURCE1 %SOURCE5 $RPM_BUILD_ROOT%_rpmconfigdir
install -m0644 -D %SOURCE2 $RPM_BUILD_ROOT%_rpmmacrodir/macros.%name
install -m0755 -D %SOURCE4 $RPM_BUILD_ROOT/usr/lib/rpm/brp-suse.d/brp-70-trim-translations
install -m0755 -D brp-extract-translations $RPM_BUILD_ROOT/usr/lib/rpm/brp-suse.d/brp-70-extract-translations
%files
%defattr(-,root,root)
%_rpmconfigdir/*
%exclude %_rpmconfigdir/brp-suse.d
%_rpmmacrodir/*
%files -n brp-trim-translations
%defattr(-,root,root)
%dir %_rpmconfigdir/brp-suse.d/
%_rpmconfigdir/brp-suse.d/brp-70-trim-translations
%files -n brp-extract-translations
%defattr(-,root,root)
%dir %_rpmconfigdir/brp-suse.d/
%_rpmconfigdir/brp-suse.d/brp-70-extract-translations
%changelog