Skip to content

Commit

Permalink
Associate QGIS MIME types with the QGIS application entry (#59)
Browse files Browse the repository at this point in the history
Resolves #55
  • Loading branch information
yuvipanda authored May 17, 2023
2 parents 074b678 + 5b88a97 commit 3b59501
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 10 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ hosted on https://quay.io/repository/cryointhecloud/cryo-hub-image
The image is built with [repo2docker](https://repo2docker.readthedocs.io), which uses
Ubuntu Bionic Beaver (18.04) as the base image. If you'd like to run a test build
locally, please read the [repo2docker Getting Started
doc](https://repo2docker.readthedocs.io/en/latest/getting-started/index.html).
doc](https://repo2docker.readthedocs.io/en/latest/getting-started/index.html) and the
[repo2docker Configuration Files
doc](https://repo2docker.readthedocs.io/en/latest/config_files.html#config-files).

## Updating packages in this repository

Expand All @@ -31,6 +33,35 @@ repository. Follow these steps:
status of the action in the "Actions" tab; the bot could fail silently, in which case you should address
any errors and re-comment with the `/condalock` command.

### Testing locally

To test the build locally, first ensure you have an up-to-date conda lock file, then
build with `repo2docker` (if your conda lock file was already updated by the bot as
described above, you can skip the first line):

```
conda-lock lock --mamba --kind explicit --file environment.yml --platform linux-64
repo2docker .
```

This build may take up to 30 minutes.

Once the image is built, `repo2docker` will automatically run a JupyterLab
server and display a message like this:

```
To access the notebook, open this file in a browser:
file:///home/<YOUR_USERNAME>/.local/share/jupyter/runtime/nbserver-27-open.html
Or copy and paste this URL:
http://127.0.0.1:53695/?token=<YOUR_TOKEN>
```

Click the URL on the last line of the `repo2docker` output to open the local JupyterLab
instance in your browser, and you're ready to test!

From here, you'll be able to locally test anything you can do in a cloud deployment:
run terminal commands, edit and run notebooks, or start a desktop VNC session.

## Updating the CryoCloud JupyterHub to use a new image

After your PR gets merged, our GitHub Actions will build and push a new image to
Expand All @@ -48,6 +79,6 @@ update it to use the new image.
page to see if the tag stuck!
4. Once this is done, you can go start your server again (restart it if it is currently running). This will make sure
you get the new image, with the changes you have performed!

The [2i2c docs](https://docs.2i2c.org/en/latest/admin/howto/configurator.html)
have some more information about the configurator!
212 changes: 212 additions & 0 deletions mime/qgis.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?xml version="1.0"?>
<!-- From: https://raw.githubusercontent.com/qgis/QGIS/ltr-3_28/debian/qgis.xml -->
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>

<mime-type type="application/x-qgis-project">
<comment>QGIS Project</comment>
<comment xml:lang="de">QGIS-Projekt</comment>
<sub-class-of type="application/xml"/>
<alias type="application/x-qgis"/>
<icon name="qgis-qgs"/>
<magic priority="50">
<match type="string" offset="0" value="&lt;!DOCTYPE qgis"/>
</magic>
<glob pattern="*.qgs"/>
</mime-type>

<mime-type type="application/x-qgis-project-container">
<comment>QGIS Project</comment>
<comment xml:lang="de">QGIS-Projekt</comment>
<sub-class-of type="application/zip"/>
<alias type="application/x-qgis"/>
<icon name="qgis-qgs"/>
<glob pattern="*.qgz"/>
</mime-type>

<mime-type type="application/x-qgis-layer-settings">
<comment>QGIS layer settings</comment>
<comment xml:lang="de">QGIS-Layereinstellungen</comment>
<sub-class-of type="application/xml"/>
<icon name="qgis-qml"/>
<magic priority="80">
<match type="string" offset="0" value="&lt;!DOCTYPE qgis"/>
</magic>
<glob pattern="*.qml"/>
</mime-type>

<mime-type type="application/x-qgis-layer-definition">
<comment>QGIS layer definition</comment>
<comment xml:lang="de">QGIS-Layerdefinition</comment>
<sub-class-of type="application/xml"/>
<icon name="qgis-qlr"/>
<magic priority="50">
<match type="string" offset="0" value="&lt;!DOCTYPE qgis-layer-definition"/>
</magic>
<glob pattern="*.qlr"/>
</mime-type>

<mime-type type="application/x-qgis-composer-template">
<comment>QGIS composer template</comment>
<comment xml:lang="de">QGIS-Druckzusammenstellungsvorlage</comment>
<sub-class-of type="application/xml"/>
<icon name="qgis-qpt"/>
<magic priority="50">
<match type="string" offset="0" value="&lt;!DOCTYPE qgis"/>
</magic>
<glob pattern="*.qpt"/>
</mime-type>

<mime-type type="application/x-esri-shape">
<comment>ESRI shape file</comment>
<comment xml:lang="de">ESRI-Shapedatei</comment>
<icon name="qgis-mime"/>
<magic priority="100">
<match type="big32" offset="0" value="9994">
<match type="big32" offset="4" value="0">
<match type="big32" offset="8" value="0">
<match type="big32" offset="12" value="0">
<match type="big32" offset="16" value="0">
<match type="big32" offset="20" value="0">
<match type="big32" offset="28" value="1000"/>
</match>
</match>
</match>
</match>
</match>
</match>
</magic>
<glob pattern="*.shp"/>
<glob pattern="*.shx"/>
</mime-type>

<mime-type type="application/x-esri-crs">
<comment>ESRI coordinate reference system</comment>
<comment xml:lang="de">ESRI-Koordinatenreferenzsystem</comment>
<icon name="qgis-mime"/>
<magic>
<match type="string" offset="0" value="GEOGCS["/>
<match type="string" offset="0" value="PROJCS["/>
<match type="string" offset="0" value="LOCAL_CS["/>
</magic>
<glob pattern="*.prj"/>
</mime-type>

<mime-type type="image/tiff">
<comment>TIFF raster data</comment>
<comment xml:lang="de">TIFF-Rasterdaten</comment>
<icon name="qgis-mime"/>
<magic priority="50">
<match type="string" offset="0" value="MM">
<match type="little16" offset="2" value="42"/>
</match>
<match type="string" offset="0" value="MM">
<match type="big16" offset="2" value="42"/>
</match>
</magic>
<glob pattern="*.tiff"/>
<glob pattern="*.tif"/>
</mime-type>

<mime-type type="image/jpeg">
<comment>JPEG raster data</comment>
<comment xml:lang="de">JPEG-Rasterdaten</comment>
<icon name="qgis-mime"/>
<magic priority="50">
<match type="big16" offset="0" value="65496"/>
</magic>
<glob pattern="*.jpeg"/>
<glob pattern="*.jpg"/>
</mime-type>

<mime-type type="image/jp2">
<comment>JPEG2000 raster data</comment>
<comment xml:lang="de">JPEG2000-Rasterdaten</comment>
<icon name="qgis-mime"/>
<magic priority="50">
<match type="little32" offset="0" value="12">
<match type="string" offset="8" value="jP">
<match type="byte" offset="10" value="32">
<match type="byte" offset="11" value="32">
<match type="byte" offset="12" value="13">
<match type="byte" offset="13" value="10">
<match type="byte" offset="14" value="135">
<match type="byte" offset="13" value="10"/>
</match>
</match>
</match>
</match>
</match>
</match>
</match>
</magic>
<glob pattern="*.jp2"/>
<glob pattern="*.j2k"/>
</mime-type>

<mime-type type="application/x-raster-aig">
<comment>AIG raster data</comment>
<comment xml:lang="de">AIG-Rasterdaten</comment>
<icon name="qgis-mime"/>
<glob pattern="*.aig"/>
</mime-type>

<mime-type type="application/x-raster-ecw">
<comment>ECW raster data</comment>
<comment xml:lang="de">ECW-Rasterdaten</comment>
<icon name="qgis-mime"/>
<glob pattern="*.ecw"/>
</mime-type>

<mime-type type="application/x-raster-mrsid">
<comment>MrSID raster data</comment>
<comment xml:lang="de">MrSID-Rasterdaten</comment>
<icon name="qgis-mime"/>
<glob pattern="*.sid"/>
</mime-type>

<mime-type type="application/x-mapinfo-mif">
<comment>MapInfo file</comment>
<comment xml:lang="de">MapInfo-Datei</comment>
<icon name="qgis-mime"/>
<magic priority="51">
<match type="string" offset="0" value="VERSION">
<match type="string" offset="0:512" value="COLUMNS"/>
<match type="string" offset="0:512" value="DATA">
</match>
</match>
</magic>
<glob weight="60" pattern="*.mif"/>
</mime-type>

<!-- .mif is just not good enough -->
<mime-type type="application/x-adobe-mif">
<alias type="application/x-mif"/>
<comment>Adobe FrameMaker MIF file</comment>
<magic priority="100">
<match type="string" offset="0" value="&lt;MIFFile"/>
</magic>
<glob weight="51" pattern="*.mif"/>
</mime-type>

<mime-type type="application/vnd.google-earth.kml+xml">
<comment>Keyhole Markup Language data</comment>
<sub-class-of type="application/xml"/>
<icon name="qgis-mime"/>
<glob pattern="*.kml"/>
</mime-type>

<mime-type type="application/vnd.google-earth.kmz">
<comment>Zipped Keyhole Markup Language data</comment>
<sub-class-of type="application/zip"/>
<icon name="qgis-mime"/>
<glob pattern="*.kmz"/>
</mime-type>

<mime-type type="application/geopackage+sqlite3">
<comment>GeoPackage data</comment>
<sub-class-of type="application/vnd.sqlite3"/>
<icon name="qgis-mime"/>
<glob pattern="*.gpkg"/>
</mime-type>

</mime-info>
14 changes: 11 additions & 3 deletions qgis.desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# From: https://github.com/qgis/QGIS/blob/ltr-3_28/linux/org.qgis.qgis.desktop.in
[Desktop Entry]
Version=1.0
Type=Application
Name=qgis
Exec=qgis
Name=QGIS Desktop
GenericName=Geographic Information System
Icon=/srv/conda/envs/notebook/share/qgis/images/icons/qgis-icon-512x512.png
TryExec=qgis
Exec=qgis %F
Terminal=false
StartupNotify=false
Categories=Qt;Education;Science;Geography;
MimeType=application/x-qgis-project;application/x-qgis-project-container;application/x-qgis-layer-settings;application/x-qgis-layer-definition;application/x-qgis-composer-template;image/tiff;image/jpeg;image/jp2;application/x-raster-aig;application/x-raster-ecw;application/x-raster-mrsid;application/x-mapinfo-mif;application/x-esri-shape;application/vnd.google-earth.kml+xml;application/vnd.google-earth.kmz;application/geopackage+sqlite3;
Keywords=map;globe;postgis;wms;wfs;ogc;osgeo;
StartupWMClass=QGIS3
31 changes: 26 additions & 5 deletions start
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/bin/bash
set -euo pipefail

mkdir -p $HOME/Desktop

# Copy any .desktop files to the desktop
cp $REPO_DIR/*.desktop $HOME/Desktop/

# Set any environment variables here
# These are inherited by all processes, *except* RStudio

Expand All @@ -18,4 +13,30 @@ export DISPLAY=":1.0"
export GH_SCOPED_CREDS_CLIENT_ID="Iv1.bd27058fd393e285"
export GH_SCOPED_CREDS_APP_URL="https://github.com/apps/cryocloud-github-access"

# Add any .desktop files to the application database and desktop. This is done
# at startup-time because it's expected that a remote filesystem will be
# mounted at $HOME, which would overwrite the data if it was created at
# build-time.
APPLICATIONS_DIR="${HOME}/.local/share/applications"
DESKTOP_DIR="${HOME}/Desktop"
mkdir -p "${APPLICATIONS_DIR}"
mkdir "${DESKTOP_DIR}"
for desktop_file_path in ${REPO_DIR}/*.desktop; do
cp "${desktop_file_path}" "${APPLICATIONS_DIR}/."

# Symlink application to desktop
desktop_file_name="$(basename ${desktop_file_path})"
ln -s "${APPLICATIONS_DIR}/${desktop_file_name}" "${DESKTOP_DIR}/${desktop_file_name}"
done
update-desktop-database "${APPLICATIONS_DIR}"

# Add MIME Type data from XML files in `mime/` dir to the MIME database.
MIME_DIR="${HOME}/.local/share/mime"
MIME_PACKAGES_DIR="${MIME_DIR}/packages"
mkdir -p "${MIME_PACKAGES_DIR}"
for mime_file_path in ${REPO_DIR}/mime/*.xml; do
cp "${mime_file_path}" "${MIME_PACKAGES_DIR}/."
done
update-mime-database "${MIME_DIR}"

exec "$@"

0 comments on commit 3b59501

Please sign in to comment.