JAL-3521 Debian mime-type and desktop helper files, and script to create them
authorBen Soares <b.soares@dundee.ac.uk>
Tue, 26 Jan 2021 13:59:13 +0000 (13:59 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Tue, 26 Jan 2021 14:02:34 +0000 (14:02 +0000)
utils/debian/debian/jalview-file.png [new file with mode: 0644]
utils/debian/debian/jalview-icon.png [new file with mode: 0644]
utils/debian/debian/jalview-mailcap [new file with mode: 0644]
utils/debian/debian/jalview-mime.xml [new file with mode: 0644]
utils/debian/debian/jalview.desktop [new file with mode: 0644]
utils/debian/file_associations_template-mailcap.txt [new file with mode: 0644]
utils/debian/file_associations_template-shared-mime-info.xml [new file with mode: 0644]
utils/debian/mime_types_for_debian.pl [new file with mode: 0755]

diff --git a/utils/debian/debian/jalview-file.png b/utils/debian/debian/jalview-file.png
new file mode 100644 (file)
index 0000000..1d98699
Binary files /dev/null and b/utils/debian/debian/jalview-file.png differ
diff --git a/utils/debian/debian/jalview-icon.png b/utils/debian/debian/jalview-icon.png
new file mode 100644 (file)
index 0000000..340f8e5
Binary files /dev/null and b/utils/debian/debian/jalview-icon.png differ
diff --git a/utils/debian/debian/jalview-mailcap b/utils/debian/debian/jalview-mailcap
new file mode 100644 (file)
index 0000000..5be7ab9
--- /dev/null
@@ -0,0 +1,22 @@
+application/x-jalview+xml+zip; jalview -open '%s'; description="Jalview File"; nametemplate=%s.jvp; test=test -n "$DISPLAY"; priority=10
+chemical/x-cif; jalview -open '%s'; description="CIF File"; nametemplate=%s.cif; test=test -n "$DISPLAY"; priority=4
+chemical/x-mmcif; jalview -open '%s'; description="mmCIF File"; nametemplate=%s.mcif; test=test -n "$DISPLAY"; priority=4
+chemical/x-pdb; jalview -open '%s'; description="PDB File"; nametemplate=%s.pdb; test=test -n "$DISPLAY"; priority=4
+application/x-amsa+txt; jalview -open '%s'; description="AMSA File"; nametemplate=%s.amsa; test=test -n "$DISPLAY"; priority=9
+application/x-jalview-annotations+text; jalview -open '%s'; description="Jalview Annotations File"; nametemplate=%s.annotations; test=test -n "$DISPLAY"; priority=10
+application/x-jalview-biojson+json; jalview -open '%s'; description="BioJSON File"; nametemplate=%s.biojson; test=test -n "$DISPLAY"; priority=10
+application/x-blc+txt; jalview -open '%s'; description="BLC File"; nametemplate=%s.blc; test=test -n "$DISPLAY"; priority=9
+application/x-clustal+txt; jalview -open '%s'; description="Clustal File"; nametemplate=%s.aln; test=test -n "$DISPLAY"; priority=9
+application/x-fasta+txt; jalview -open '%s'; description="Fasta File"; nametemplate=%s.fa; test=test -n "$DISPLAY"; priority=9
+application/x-jalview-features+text; jalview -open '%s'; description="Jalview Features File"; nametemplate=%s.features; test=test -n "$DISPLAY"; priority=10
+application/x-gff2+txt; jalview -open '%s'; description="Generic Features Format v2 File"; nametemplate=%s.gff2; test=test -n "$DISPLAY"; priority=9
+application/x-gff3+txt; jalview -open '%s'; description="Generic Features Format v3 File"; nametemplate=%s.gff3; test=test -n "$DISPLAY"; priority=9
+application/x-jalview-jnet+text; jalview -open '%s'; description="JnetFile File"; nametemplate=%s.concise; test=test -n "$DISPLAY"; priority=10
+application/x-msf+txt; jalview -open '%s'; description="MSF File"; nametemplate=%s.msf; test=test -n "$DISPLAY"; priority=9
+application/x-pfam+txt; jalview -open '%s'; description="PFAM File"; nametemplate=%s.pfam; test=test -n "$DISPLAY"; priority=9
+application/x-phylip+txt; jalview -open '%s'; description="PHYLIP File"; nametemplate=%s.phy; test=test -n "$DISPLAY"; priority=9
+application/x-pileup+txt; jalview -open '%s'; description="PileUp File"; nametemplate=%s.pileup; test=test -n "$DISPLAY"; priority=9
+application/x-pir+txt; jalview -open '%s'; description="PIR File"; nametemplate=%s.pir; test=test -n "$DISPLAY"; priority=9
+application/rnaml+xml; jalview -open '%s'; description="RNAML File"; nametemplate=%s.rnaml; test=test -n "$DISPLAY"; priority=9
+application/x-jalview-scorematrix+text; jalview -open '%s'; description="Substitution Matrix File"; nametemplate=%s.mat; test=test -n "$DISPLAY"; priority=10
+application/x-stockholm+txt; jalview -open '%s'; description="Stockholm File"; nametemplate=%s.sto; test=test -n "$DISPLAY"; priority=9
diff --git a/utils/debian/debian/jalview-mime.xml b/utils/debian/debian/jalview-mime.xml
new file mode 100644 (file)
index 0000000..181fbed
--- /dev/null
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
+
+  <mime-type type="application/x-jalview+xml+zip">
+    <comment>Jalview File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.jvp" weight="100"/>
+  </mime-type>
+
+  <mime-type type="chemical/x-cif">
+    <comment>CIF File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.cif" weight="40"/>
+  </mime-type>
+
+  <mime-type type="chemical/x-mmcif">
+    <comment>mmCIF File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.mcif" weight="40"/>
+    <glob pattern="*.mmcif" weight="40"/>
+  </mime-type>
+
+  <mime-type type="chemical/x-pdb">
+    <comment>PDB File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.pdb" weight="40"/>
+    <glob pattern="*.ent" weight="40"/>
+  </mime-type>
+
+  <mime-type type="application/x-amsa+txt">
+    <comment>AMSA File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.amsa" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-jalview-annotations+text">
+    <comment>Jalview Annotations File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.annotations" weight="100"/>
+    <glob pattern="*.jvannotations" weight="100"/>
+  </mime-type>
+
+  <mime-type type="application/x-jalview-biojson+json">
+    <comment>BioJSON File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.biojson" weight="100"/>
+  </mime-type>
+
+  <mime-type type="application/x-blc+txt">
+    <comment>BLC File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.blc" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-clustal+txt">
+    <comment>Clustal File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.aln" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-fasta+txt">
+    <comment>Fasta File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.fa" weight="90"/>
+    <glob pattern="*.fasta" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-jalview-features+text">
+    <comment>Jalview Features File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.features" weight="100"/>
+    <glob pattern="*.jvfeatures" weight="100"/>
+  </mime-type>
+
+  <mime-type type="application/x-gff2+txt">
+    <comment>Generic Features Format v2 File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.gff2" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-gff3+txt">
+    <comment>Generic Features Format v3 File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.gff3" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-jalview-jnet+text">
+    <comment>JnetFile File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.concise" weight="100"/>
+    <glob pattern="*.jnet" weight="100"/>
+  </mime-type>
+
+  <mime-type type="application/x-msf+txt">
+    <comment>MSF File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.msf" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-pfam+txt">
+    <comment>PFAM File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.pfam" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-phylip+txt">
+    <comment>PHYLIP File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.phy" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-pileup+txt">
+    <comment>PileUp File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.pileup" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-pir+txt">
+    <comment>PIR File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.pir" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/rnaml+xml">
+    <comment>RNAML File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.rnaml" weight="90"/>
+  </mime-type>
+
+  <mime-type type="application/x-jalview-scorematrix+text">
+    <comment>Substitution Matrix File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.mat" weight="100"/>
+  </mime-type>
+
+  <mime-type type="application/x-stockholm+txt">
+    <comment>Stockholm File</comment>
+    <icon name="jalview-file"/>
+    <glob pattern="*.sto" weight="90"/>
+    <glob pattern="*.stk" weight="90"/>
+  </mime-type>
+
+</mime-info>
diff --git a/utils/debian/debian/jalview.desktop b/utils/debian/debian/jalview.desktop
new file mode 100644 (file)
index 0000000..ba7c157
--- /dev/null
@@ -0,0 +1,13 @@
+[Desktop Entry]
+Version=1.1
+Type=Application
+Name=Jalview
+Comment=Multiple Sequence Alignment Editor
+Icon=jalview-icon
+Type=Application
+TryExec=jalview
+Exec=jalview -open %f
+Terminal=false
+Categories=Science;Biology;
+Keywords=alignment;sequence;
+MimeType=application/x-jalview+xml+zip;chemical/x-cif;chemical/x-mmcif;chemical/x-pdb;application/x-amsa+txt;application/x-jalview-annotations+text;application/x-jalview-biojson+json;application/x-blc+txt;application/x-clustal+txt;application/x-fasta+txt;application/x-jalview-features+text;application/x-gff2+txt;application/x-gff3+txt;application/x-jalview-jnet+text;application/x-msf+txt;application/x-pfam+txt;application/x-phylip+txt;application/x-pileup+txt;application/x-pir+txt;application/rnaml+xml;application/x-jalview-scorematrix+text;application/x-stockholm+txt
diff --git a/utils/debian/file_associations_template-mailcap.txt b/utils/debian/file_associations_template-mailcap.txt
new file mode 100644 (file)
index 0000000..9a96e97
--- /dev/null
@@ -0,0 +1 @@
+$$MIMETYPE$$; jalview -open '%s'; description="$$NAME$$ File"; nametemplate=%s.$$EXTENSION$$; test=test -n "$DISPLAY"; priority=$$PRIORITY$$
diff --git a/utils/debian/file_associations_template-shared-mime-info.xml b/utils/debian/file_associations_template-shared-mime-info.xml
new file mode 100644 (file)
index 0000000..5136d0b
--- /dev/null
@@ -0,0 +1,6 @@
+  <mime-type type="$$MIMETYPE$$">
+    <comment>$$NAME$$ File</comment>
+    <icon name="$$ICONFILE$$"/>
+$$    <glob pattern="*.EXTENSIONS" weight="$$PRIORITY$$0"/>
+$$  </mime-type>
+
diff --git a/utils/debian/mime_types_for_debian.pl b/utils/debian/mime_types_for_debian.pl
new file mode 100755 (executable)
index 0000000..3c1ed24
--- /dev/null
@@ -0,0 +1,249 @@
+#!/usr/bin/env perl
+
+use strict;
+
+my $fileformats = $ARGV[0];
+$fileformats = "../../src/jalview/io/FileFormat.java" unless $fileformats;
+
+# default mimetype will be text/x-$shortname
+# TODO: find an actual extension for mat, see JAL-Xxxxx for outstanding issues too
+# TODO: look up standard mime type used for BLASTfmt matrices, etc
+my $mimetypes = {
+  rnaml => "application/rnaml+xml",
+  biojson => "application/x-jalview-biojson+json",
+  jnet => "application/x-jalview-jnet+text",
+  features => "application/x-jalview-features+text",
+  scorematrix => "application/x-jalview-scorematrix+text",
+  pdb => "chemical/x-pdb",
+  mmcif => "chemical/x-cif",
+  mmcif2 => "chemical/x-mmcif",
+  jalview => "application/x-jalview+xml+zip",
+  #jvl => "application/x-jalview-jvl+text",
+  annotations => "application/x-jalview-annotations+text",
+};
+
+my @dontaddshortname = qw(features json);
+my @dontaddextension = qw(html xml json jar mfa fastq);
+my $add_associations = {
+  biojson => {shortname=>"biojson",name=>"BioJSON",extensions=>["biojson"]},
+  gff2 => {shortname=>"gff2",name=>"Generic Features Format v2",extensions=>["gff2"]},
+  gff3 => {shortname=>"gff3",name=>"Generic Features Format v3",extensions=>["gff3"]},
+  features => {shortname=>"features",name=>"Jalview Features",extensions=>["features","jvfeatures"]},
+  annotations => {shortname=>"annotations",name=>"Jalview Annotations",extensions=>["annotations","jvannotations"]},
+  mmcif => {shortname=>"mmcif",name=>"CIF",extensions=>["cif"]},
+  mmcif2 => {shortname=>"mmcif2",name=>"mmCIF",extensions=>["mcif","mmcif"]},
+  #jvl => {shortname=>"jvl",name=>"Jalview Launch",extensions=>["jvl"],iconfile=>"jalview-launch"},
+  jnet => {shortname=>"jnet",name=>"JnetFile",extensions=>["concise","jnet"]},
+  scorematrix => {shortname=>"scorematrix",name=>"Substitution Matrix",extensions=>["mat"]},
+};
+my $add_extensions = {
+  blc => ["blc"],
+};
+my @put_first = qw(jalview jvl);
+
+my @non_primary = qw(mmcif mmcif2 pdb);
+
+my $mailcaptemplatefile = "file_associations_template-mailcap.txt";
+my $mailcaptemplate;
+my $sharedmimeinfotemplatefile = "file_associations_template-shared-mime-info.xml";
+my $sharedmimeinfotemplate;
+
+open(SMT,"<$sharedmimeinfotemplatefile") or die("Could not open '$sharedmimeinfotemplatefile' for reading");
+while(<SMT>){
+  $sharedmimeinfotemplate .= $_;
+}
+close(SMT);
+open(MCT,"<$mailcaptemplatefile") or die("Could not open '$mailcaptemplatefile' for reading");
+while(<MCT>){
+  $mailcaptemplate .= $_;
+}
+close(MCT);
+my $sharedmimeinfoauto;
+my $mailcapauto;
+
+# this file should go in /usr/share/mime/packages
+my $sharedmimeinfoautofile = "debian/jalview-mime.xml";
+
+# this file should go in /usr/lib/mime/packages
+my $mailcapautofile = "debian/jalview-mailcap";
+
+# this should be part of the jalview.desktop file that goes in /usr/shares/applications
+my $desktopfile = "debian/jalview.desktop";
+
+my $MimeType = "";
+
+for my $key (sort keys %$add_associations) {
+  my $a = $add_associations->{$key};
+  warn("Known file association for $a->{shortname} (".join(",",@{$a->{extensions}}).")\n");
+}
+
+open(SMI,">$sharedmimeinfoautofile") or die ("Could not open '$sharedmimeinfoautofile' for writing");
+
+open(MCA,">$mailcapautofile") or die ("Could not open '$mailcapautofile' for writing");
+
+open(IN, "<$fileformats") or die ("Could not open '$fileformats' for reading");
+my $id = 10000;
+my $file_associations = {};
+while(my $line = <IN>) {
+  $line =~ s/\s+/ /g;
+  $line =~ s/(^ | $)//g;
+  if ($line =~ m/^(\w+) ?\( ?"([^"]*)" ?, ?"([^"]*)" ?, ?(true|false) ?, ?(true|false) ?\)$/i) {
+    my $shortname = lc($1);
+    next if (grep($_ eq $shortname, @dontaddshortname));
+    my $name = $2;
+    my $extensions = $3;
+    $extensions =~ s/\s+//g;
+    my @possextensions = map(lc($_),split(m/,/,$extensions));
+    my @extensions;
+    my $addext = $add_extensions->{$shortname};
+    if (ref($addext) eq "ARRAY") {
+      push(@possextensions, @$addext);
+    }
+    for my $possext (@possextensions) {
+      next if grep($_ eq $possext, @extensions);
+      next if grep($_ eq $possext, @dontaddextension);
+      push(@extensions,$possext);
+    }
+    next unless scalar(@extensions);
+    $file_associations->{$shortname} = {
+      shortname => $shortname,
+      name => $name,
+      extensions => \@extensions
+    };
+    warn("Reading file association for $shortname (".join(",",@extensions).")\n");
+  }
+}
+close(IN);
+
+my %all_associations = (%$file_associations, %$add_associations);
+
+my @ordered = (@put_first, @non_primary);
+for my $key (sort keys %all_associations) {
+  next if grep($_ eq $key, @ordered);
+  push(@ordered, $key);
+}
+my $num = $#ordered + 1;
+
+warn("--\n");
+print SMI qq(<?xml version="1.0" encoding="UTF-8"?>\n<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">\n\n);
+
+my $mailcapcount = 0;
+for my $shortname (@ordered) {
+  my $a = $all_associations{$shortname};
+  next if (ref($a) ne "HASH");
+
+  my $name = $a->{name};
+  my $extensions = $a->{extensions};
+  my $mimetype = $mimetypes->{$shortname};
+  $mimetype = "application/x-$shortname+txt" unless $mimetype;
+
+  $MimeType .= $MimeType?";":"";
+  $MimeType .= $mimetype;
+
+  my $iconfile = $a->{iconfile};
+  $iconfile = "jalview-file" unless $iconfile;
+
+  my $primary = (! grep($_ eq $shortname, @non_primary));
+  my $primarystring = $primary?"true":"false";
+  my $role = $primary?"Editor":"Viewer";
+  my $priority = $primary?9:4;
+  $priority = 10 if $mimetype =~ m/\bjalview\b/;
+
+  my @extensions = @$extensions;
+  my $extension0 = $extensions[0];
+
+  my $xname = xml_escape($name);
+  my $xmimetype = xml_escape($mimetype);
+  my $xshortname = xml_escape($shortname);
+  my $xiconfile = xml_escape($iconfile);
+  my $xrole = xml_escape($role);
+  my $xROLE = xml_escape(uc($role));
+  my $xprimarystring = xml_escape($primarystring);
+
+  my $sharedmimeinfoentry = $sharedmimeinfotemplate;
+  $sharedmimeinfoentry =~ s/\$\$NAME\$\$/$xname/g;
+  $sharedmimeinfoentry =~ s/\$\$SHORTNAME\$\$/$xshortname/g;
+  $sharedmimeinfoentry =~ s/\$\$MIMETYPE\$\$/$xmimetype/g;
+  $sharedmimeinfoentry =~ s/\$\$ICONFILE\$\$/$xiconfile/g;
+  $sharedmimeinfoentry =~ s/\$\$ROLE\$\$/$xrole/g;
+  $sharedmimeinfoentry =~ s/\$\$PRIMARY\$\$/$xprimarystring/g;
+  $sharedmimeinfoentry =~ s/\$\$PRIORITY\$\$/$priority/g;
+  while ($sharedmimeinfoentry =~ m/\$\$([^\$]*)EXTENSIONS([^\$]*)\$\$/) {
+    my $pre = $1;
+    my $post = $2;
+    my $sharedmimeinfoextensions;
+    for my $ext (@extensions) {
+      my $xext = xml_escape($ext);
+      $sharedmimeinfoextensions .= $pre.$xext.$post;
+    }
+    my $prere = $pre;
+    $prere =~ s/([\*\.])/\\\1/g;
+    my $postre = $post;
+    $postre =~ s/([\*\.])/\\\1/g;
+    $sharedmimeinfoentry =~ s/\$\$${prere}EXTENSIONS${postre}\$\$/$sharedmimeinfoextensions/gs;
+  }
+  print SMI $sharedmimeinfoentry;
+
+  my $mailcapentry = $mailcaptemplate;
+  $mailcapentry =~ s/\$\$NAME\$\$/$xname/g;
+  $mailcapentry =~ s/\$\$SHORTNAME\$\$/$xshortname/g;
+  $mailcapentry =~ s/\$\$MIMETYPE\$\$/$xmimetype/g;
+  $mailcapentry =~ s/\$\$ICONFILE\$\$/$xiconfile/g;
+  $mailcapentry =~ s/\$\$PRIMARY\$\$/$xprimarystring/g;
+  $mailcapentry =~ s/\$\$MACASSOCIATIONROLE\$\$/$xROLE/g;
+  $mailcapentry =~ s/\$\$EXTENSION\$\$/$extension0/g;
+  $mailcapentry =~ s/\$\$PRIORITY\$\$/$priority/g;
+
+  my $ext = join(",",sort(@extensions));
+  my $xdisplayext = xml_escape(join(", ", map(".$_",sort(@extensions))));
+  my $progresspercent = int(($mailcapcount/$num)*100);
+  $progresspercent = 100 if $progresspercent > 100;
+  $mailcapcount++;
+  my $xext = xml_escape($ext);
+  my $addunixextension = "true";
+
+  $mailcapentry =~ s/\$\$ADDUNIXEXTENSION\$\$/$addunixextension/g;
+  $mailcapentry =~ s/\$\$EXTENSION\$\$/$xext/g;
+  $mailcapentry =~ s/\$\$DISPLAYEXTENSION\$\$/$xdisplayext/g;
+  $mailcapentry =~ s/\$\$PROGRESSPERCENT\$\$/$progresspercent/g;
+  $mailcapentry =~ s/\$\$ID\$\$/$id/g;
+  $id++;
+  $mailcapentry =~ s/\$\$ID1\$\$/$id/g;
+  $id++;
+  $mailcapentry =~ s/\$\$ID2\$\$/$id/g;
+  $id++;
+
+  print MCA $mailcapentry;
+
+  delete $all_associations{$shortname};
+  warn("Writing entry for $name (".join(",",@$extensions).": $mimetype)\n");
+}
+
+print SMI "</mime-info>\n";
+
+close(MCA);
+close(SMI);
+
+open(D,">$desktopfile") or die ("Could not open '$desktopfile' for writing");
+print D qq([Desktop Entry]
+Version=1.1
+Type=Application
+Name=Jalview
+Comment=Multiple Sequence Alignment Editor
+Icon=jalview-icon
+Type=Application
+TryExec=jalview
+Exec=jalview -open %f
+Terminal=false
+Categories=Science;Biology;
+Keywords=alignment;sequence;
+MimeType=${MimeType}
+);
+close(D);
+
+sub xml_escape {
+  my $x = shift;
+  # stolen from Pod::Simple::XMLOutStream in base distro
+  $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}a-zA-Z0-9])/'&#'.(ord($1)).';'/eg;
+  return $x;
+}