summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2012-11-08 07:12:44 -0800
committerJean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org>2014-11-13 11:02:41 +0100
commitf90b939262b251edafac0f7dda2166192b3acce3 (patch)
tree2eca622dd7458bbb0a76856ebc27b675c193a0fc
parent68ffbfcfa267299b981504e29aacd1f504ac0f2d (diff)
downloadshared-mime-info-f90b939262b251edafac0f7dda2166192b3acce3.tar.gz
shared-mime-info-f90b939262b251edafac0f7dda2166192b3acce3.tar.bz2
shared-mime-info-f90b939262b251edafac0f7dda2166192b3acce3.zip
add missing files
-rw-r--r--packaging/macros.shared-mime-info39
-rw-r--r--packaging/mime-info-to-mime261
2 files changed, 300 insertions, 0 deletions
diff --git a/packaging/macros.shared-mime-info b/packaging/macros.shared-mime-info
new file mode 100644
index 0000000..56ef610
--- /dev/null
+++ b/packaging/macros.shared-mime-info
@@ -0,0 +1,39 @@
+# RPM macros for packages installing a MIME type according to the XDG specification
+#
+###
+#
+# When a package installs a MIME type as per the XDG specification, it should
+# use both macros:
+#
+# - %mime_database_post in %post
+# - %mime_database_postun in %postun
+#
+# Note that these macros can optionally take as argument the directory
+# where the MIME type is installed. If no argument is passed, then
+# %{_datadir}/mime will be used (which is where applications usually install
+# the MIME type information).
+#
+###
+
+# On install, update the mime database
+%mime_database_post() \
+if test -x %{_bindir}/update-mime-database; then \
+%if "x%1" != "x%%1" \
+ %{_bindir}/update-mime-database "%1" || true \
+%else \
+ %{_bindir}/update-mime-database "%{_datadir}/mime" || true \
+%endif \
+fi
+
+# On uninstall, update the mime database. Note: we ignore upgrades (already
+# handled in %post of the new package).
+%mime_database_postun() \
+if [ $1 -eq 0 ]; then \
+ if test -x %{_bindir}/update-mime-database; then \
+%if "x%1" != "x%%1" \
+ %{_bindir}/update-mime-database "%1" || true \
+%else \
+ %{_bindir}/update-mime-database "%{_datadir}/mime" || true \
+%endif \
+ fi \
+fi
diff --git a/packaging/mime-info-to-mime b/packaging/mime-info-to-mime
new file mode 100644
index 0000000..04aabf9
--- /dev/null
+++ b/packaging/mime-info-to-mime
@@ -0,0 +1,261 @@
+#! /usr/bin/perl
+
+# mime-info-to-mime
+# Script to help with conversion from mime-info to shared-mime-info.
+#
+# Conversion for simple description is automatic and correct, for
+# complicated or buggy descriptions, manual check is required (and
+# convertor returns error code 1).
+#
+# Call it without arguments to perform conversion of all files in your
+# system (previously installed files will not be overwritten) or use
+# DESTDIR variable, if you want to create package.
+#
+# (c) 2004 SuSE CR
+# Author: Stanislav Brabec <sbrabec@suse.cz>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+if ( $ENV{"DESTDIR"} eq "" && $ARGV[0] ne "--force" ) {
+ print "System-wide \"$0\" is disabled. It may create bogus definitions!\n";
+ print "Use \"$0 --force\" to force it or set DESTDIR.\n";
+ exit 1;
+}
+
+# directory with mime-info
+$mimeinfodir=$ENV{"DESTDIR"} . "/usr/share/mime-info";
+
+# directory with shared-mime-info
+$sharedmimedir=$ENV{"DESTDIR"} . "/usr/share/mime/packages";
+
+$rc=0;
+
+system "mkdir -p $sharedmimedir ; rm -v 2>/dev/null \$(fgrep 2>/dev/null -l \"generated by mime-info-to-mime\" $sharedmimedir/*.xml)";
+
+foreach $mimefile (glob("$mimeinfodir/*.mime")) {
+ $mimename = $mimefile;
+ $mimename=substr($mimename, length($mimeinfodir)+1, length($mimename)-length($mimeinfodir)-6);
+
+ if (-e "$sharedmimedir/$mimename.xml")
+ {
+ print "WARNING: File $sharedmimedir/$mimename.xml already exists. No conversion.\n";
+ next;
+ }
+# Maybe uncomment in future, but now gnome-vfs.xml is 4 times longer than freedesktop.org.xml.
+# GNOME 2
+# if ( $mimename =~ "gnome-vfs" )
+# {
+# print "INFO: Not creating gnome-vfs.xml. Data types should be present in freedesktop.org.xml.\n";
+# next;
+# }
+# GNOME 1.4
+# if ( $mimename =~ "gnome" )
+# {
+# print "INFO: Not creating gnome.xml. Data types should be present in freedesktop.org.xml.\n";
+# next;
+# }
+ open($xml, ">$sharedmimedir/$mimename.xml");
+ print $xml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ print $xml "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n";
+ print $xml "<!-- generated by mime-info-to-mime (Remove this line to prevent overwriting!) -->\n";
+
+ open($mime, "<$mimefile");
+ $lineno=0;
+ while ( <$mime> )
+ {
+ $lineno++;
+ $line = $_;
+ if ($line =~ /^[^ \t]+\/[^ \t]+/)
+ {
+ chomp $line;
+ $mime_type=$line;
+ }
+ else
+ {
+ if ($line =~ /^[ \t]/)
+ {
+ if ($line =~ /^[ \t]+ext:[ \t]?/)
+ {
+ $line =~ s/^[ \t]+ext:[ \t]?// ;
+ chomp $line;
+ foreach $ext (split " ", $line)
+ {
+ $xmlstring{$mime_type}=$xmlstring{$mime_type} . " <glob pattern=\"*.$ext\" />\n";
+ }
+ }
+ else
+ {
+ if ($line =~ /^[ \t]+ext,[0-9]+:[ \t]?/)
+ {
+ $line =~ s/^[ \t]+ext,[0-9]+:[ \t]?// ;
+ chomp $line;
+ print "WARNING in $mimename.mime $lineno: priority field ignored: $line\n";
+ foreach $ext (split " ", $line)
+ {
+ $xmlstring{$mime_type}=$xmlstring{$mime_type} . " <glob pattern=\"*.$ext\" />\n";
+ }
+ }
+ else
+ {
+ if ($line =~ /^[ \t]+regex:[ \t]?/)
+ {
+ $line =~ s/^[ \t]+regex:[ \t]?// ;
+ chomp $line;
+ print "ERROR in $mimename.mime $lineno: regex is not supported, FIXME(regex) created. Edit file manually.\n";
+ $rc=1;
+ $xmlstring{$mime_type}=$xmlstring{$mime_type} . " <glob pattern=\"FIXME(regex) $line\" />\n";
+ }
+ else
+ {
+ if ($line =~ /^[ \t]+regex,[0-9]+:[ \t]?/)
+ {
+ $line =~ s/^[ \t]+regex,[0-9]+:[ \t]?// ;
+ chomp $line;
+ print "WARNING in $mimename.mime $lineno: priority field ignored: $line\n";
+ print "ERROR in $mimename.mime $lineno: regex is not supported, FIXME(regex) created. Edit file manually.\n";
+ $rc=1;
+ $xmlstring{$mime_type}=$xmlstring{$mime_type} . " <glob pattern=\"FIXME(regex) $line\" />\n";
+ }
+ else
+ {
+ print "ERROR in $mimename.mime $lineno: unknown line format: $line\n";
+ $rc=1;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ if ($line =~ /^$/)
+ {
+ $mime_type="FIXME";
+ }
+ else
+ {
+ chomp $line;
+ if ($line =~ /^#/ )
+ {
+ $line =~ s/^#*[ \t]*// ;
+ print $xml "<!-- $line -->\n";
+ }
+ else
+ {
+ print "ERROR in $mimename.mime $lineno: unknown line: $line\n";
+ $rc=1;
+ }
+ }
+ }
+ }
+ }
+ close($mime);
+
+ if (-e "$mimeinfodir/$mimename.keys")
+ {
+ open($keys, "<$mimeinfodir/$mimename.keys");
+ $lineno=0;
+ while ( <$keys> )
+ {
+ $lineno++;
+ $line = $_;
+ if ($line =~ /^[^ \t]+\/[^ \t]+/)
+ {
+ chomp $line;
+ $mime_type=$line;
+ }
+ else
+ {
+ if ($line =~ /^[ \t]/)
+ {
+ chomp $line;
+ $line =~ s/^[ \t]*// ;
+ if ($line =~ /^\[[^=]+\][^=]+=/)
+ {
+ $lang=$line;
+ $lang =~ s/^\[([^=]+)\][^=]+=.*$/\1/ ;
+ $item=$line;
+ $item =~ s/^\[[^=]+\]([^=]+)=.*$/\1/ ;
+ $value=$line;
+ $value =~ s/^\[[^=]+\][^=]+=(.*)$/\1/ ;
+ }
+ else
+ {
+ if ($line =~ /^[^=]+=/)
+ {
+ $item=$line;
+ $item =~ s/^([^=]+)=.*$/\1/ ;
+ $value=$line;
+ $value =~ s/^[^=]+=(.*)$/\1/ ;
+ $lang="";
+ }
+ else
+ {
+ print "ERROR in $mimename.keys $lineno: unknown line format: $line\n";
+ $rc=1;
+ }
+ }
+
+ if ($item =~ /^description$/)
+ {
+ if ($lang)
+ {
+ $xmlstring_c{$mime_type}=$xmlstring_c{$mime_type} . " <comment xml:lang=\"$lang\">$value</comment>\n";
+ }
+ else
+ {
+ $xmlstring_c{$mime_type}=$xmlstring_c{$mime_type} . " <comment>$value</comment>\n";
+ }
+ }
+ }
+ else
+ {
+ if ($line =~ /^$/)
+ {
+ $mime_type="FIXME";
+ }
+ else
+ {
+ chomp $line;
+ if ($line =~ /^#/ )
+ {
+ $line =~ s/^#*[ \t]*// ;
+ print $xml "<!-- $line -->\n";
+ }
+ else
+ {
+ print "ERROR in $mimename.keys $lineno: unknown line: $line\n";
+ $rc=1;
+ }
+ }
+ }
+ }
+ }
+ close($keys);
+ }
+
+ foreach $mime_type (keys %xmlstring) {
+ print $xml " <mime-type type=\"$mime_type\">\n";
+ print $xml $xmlstring_c{$mime_type};
+ print $xml $xmlstring{$mime_type};
+ print $xml " </mime-type>\n";
+ }
+ print $xml "</mime-info>\n";
+ close($xml);
+
+ undef %xmlstring;
+ undef %xmlstring_c;
+
+ }
+ exit $rc;