Skip to content

Commit

Permalink
improved menuinst (#2281)
Browse files Browse the repository at this point in the history
moved the menuinst to the conda-build process
  • Loading branch information
ReimarBauer authored May 14, 2024
1 parent bc9b5c5 commit b0032d2
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 135 deletions.
Binary file removed Menu/mss.ico
Binary file not shown.
10 changes: 0 additions & 10 deletions Menu/msui_shortcut.json

This file was deleted.

12 changes: 5 additions & 7 deletions localbuild/bld.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
set MENU_DIR=%PREFIX%\Menu
if not exist %MENU_DIR% mkdir %MENU_DIR%
if errorlevel 1 exit 1
copy %SRC_DIR%\Menu\msui_shortcut.json %MENU_DIR%\msui_shortcut.json
if errorlevel 1 exit 1
copy %SRC_DIR%\Menu\mss.ico %MENU_DIR%\mss.ico
if errorlevel 1 exit 1
mkdir "%PREFIX%\Menu"
copy /Y "%RECIPE_DIR%\menu.json" "%PREFIX%\Menu\%PKG_NAME%_menu.json"
copy /Y "%RECIPE_DIR%\msui.ico" "%PREFIX%\Menu\msui.ico"

; conda-build issue 5311, currently we can't build for windows with pip install
%PYTHON% setup.py install --single-version-externally-managed --record record.txt
if errorlevel 1 exit 1
7 changes: 7 additions & 0 deletions localbuild/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

mkdir -p "${PREFIX}/Menu"
cp "${RECIPE_DIR}/menu.json" "${PREFIX}/Menu/${PKG_NAME}_menu.json"
cp "${RECIPE_DIR}/msui.png" "${PREFIX}/Menu/msui.png"

"${PYTHON}" -m pip install . --no-deps -vv
54 changes: 54 additions & 0 deletions localbuild/menu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "https://schemas.conda.io/menuinst-1.schema.json",
"menu_name": "Mission Support System",
"menu_items": [
{
"name": "MSUI ({{ ENV_NAME }})",
"description": "Mission Support System MSUI",
"activate": true,
"icon": "{{ MENU_DIR }}/msui.{{ ICON_EXT }}",
"command": [
"{{ PYTHON }}",
"{{ PREFIX }}/bin/msui"
],
"platforms": {
"win": {
"command": [
"{{ PYTHON }}",
"{{ SCRIPTS_DIR }}/msui-script.py"
],
"file_extensions": [".menuinst"]
},
"linux": {
"Categories": ["Internet", "Science"],
"Keywords": ["documentation", "information"],
"StartupNotify": true,
"MimeType": ["application/x-menuinst"],
"glob_patterns": {
"application/x-menuinst": "*.menuinst"
}
},
"osx": {
"CFBundleDocumentTypes": [
{
"CFBundleTypeName": "org.conda.menuinst.msui",
"CFBundleTypeRole": "Viewer",
"LSItemContentTypes": ["org.conda.menuinst.main-file-uti"],
"LSHandlerRank": "Default"
}
],
"UTExportedTypeDeclarations": [
{
"UTTypeConformsTo": ["public.data", "public.content"],
"UTTypeIdentifier": "org.conda.menuinst.main-file-uti",
"UTTypeTagSpecification": {
"public.filename-extension": ["menuinst"]
}
}
]
}
}
}
]
}
20 changes: 12 additions & 8 deletions localbuild/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% set version = "alpha" %}


package:
name: mss
version: {{ version }}
Expand All @@ -9,25 +8,24 @@ source:
path: ../

build:
skip: true # [py<310]
number: 1000
script: "{{ PYTHON }} -m pip install . --no-deps -vv" # [not win]

requirements:
build:
- python
- pip
- setuptools
- future
- menuinst >=2.0.2
host:
- python
- setuptools
- pip
- menuinst # [win]
- future
run:
- python
- future
- defusedxml
- menuinst # [win]
- basemap >=1.3.3
- chameleon
- execnet
Expand Down Expand Up @@ -83,11 +81,13 @@ requirements:
- flask-wtf
- email_validator
- keyring
- dbus-python
- dbus-python # [not win]
- python-slugify
- flask-login
- pysaml2
- libxmlsec1 # [not win]
run_constrained:
- menuinst >=2.0.2

test:
imports:
Expand All @@ -97,18 +97,22 @@ test:
- mswms_demodata -h
- msui -h
- mscolab -h
- mssautoplot --help
- msidp -h # [not win]

about:
summary: 'A web service based tool to plan atmospheric research flights.'
summary: 'A client/server application developed in the community to collaboratively create flight plans based on model data.'
home: https://github.com/Open-MSS/MSS
license: "Apache-2.0"
license_family: "APACHE"
license_file: LICENSE
description: |
MSS - Mission Support System
http://www.geosci-model-dev.net/5/55/2012/gmd-5-55-2012.pdf
Documentation:
* https://mss.rtfd.io
* https://gmd.copernicus.org/articles/15/8983/2022/gmd-15-8983-2022.pdf
* http://www.geosci-model-dev.net/5/55/2012/gmd-5-55-2012.pdf
Software for planning research Aircraft Missions.
For discussion of the possibilites of the research flights,
Expand Down
Binary file added localbuild/msui.ico
Binary file not shown.
Binary file added localbuild/msui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions localbuild/post-link.sh

This file was deleted.

7 changes: 0 additions & 7 deletions localbuild/pre-unlink.sh

This file was deleted.

15 changes: 0 additions & 15 deletions mslib/msui/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,3 @@
logging.error('"%s" can''t be created', MSS_AUTOPLOT)

AUTH_LOGIN_CACHE = {}

POSIX = {"application_destination": os.path.join(HOME, ".local/share/applications/msui{}.desktop"),
"icon_destination": os.path.join(HOME, ".local/share/icons/hicolor/{}/apps/mss-logo{}.png"),
"desktop": """[Desktop Entry]
Name=msui {}
Comment=A web service based tool to plan atmospheric research flights (mission support system).
Keywords=documentation;information;
Exec={}
Icon={}
Type=Application
Categories=Science;Education;
StartupNotify=true
X-GNOME-SingleWindow=false
X-Ubuntu-Gettext-Domain=msui
"""}
52 changes: 5 additions & 47 deletions mslib/msui/msui.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
"""

import argparse
import hashlib
import logging
import os
import platform
import shutil
import sys
import fs

Expand All @@ -53,22 +51,17 @@


def main(tutorial_mode=False):
try:
prefix = os.environ["CONDA_DEFAULT_ENV"]
except KeyError:
prefix = ""
app_prefix = prefix
if prefix:
app_prefix = f"-{prefix}"
icon_hash = hashlib.md5('.'.join([__version__, app_prefix]).encode('utf-8')).hexdigest()
"""
Entry point of the msui program.
@param tutorial_mode: Specifies whether the program should run in tutorial mode or not.
"""
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--version", help="show version", action="store_true", default=False)
parser.add_argument("--debug", help="show debugging log messages on console", action="store_true", default=False)
parser.add_argument("--logfile", help="Specify logfile location. Set to empty string to disable.", action="store",
default=os.path.join(constants.MSUI_CONFIG_PATH, "msui.log"))
parser.add_argument("-m", "--menu", help="adds msui to menu", action="store_true", default=False)
parser.add_argument("-d", "--deinstall", help="removes msui from menu", action="store_true", default=False)
parser.add_argument("--update", help="Updates MSS to the newest version", action="store_true", default=False)

args = parser.parse_args()
Expand All @@ -93,41 +86,6 @@ def main(tutorial_mode=False):

setup_logging(args)

if args.menu:
# Experimental feature to get msui into application menu
if platform.system() == "Linux":
icon_size = '48x48'
src_icon_path = icons(icon_size)
icon_destination = constants.POSIX["icon_destination"].format(icon_size, icon_hash)
dirname = os.path.dirname(icon_destination)
if not os.path.exists(dirname):
os.makedirs(dirname)
shutil.copyfile(src_icon_path, icon_destination)
desktop = constants.POSIX["desktop"]
application_destination = constants.POSIX["application_destination"].format(app_prefix)
dirname = os.path.dirname(application_destination)
if not os.path.exists(dirname):
os.makedirs(dirname)
if prefix:
prefix = f"({prefix})"
desktop = desktop.format(prefix,
os.path.join(sys.prefix, "bin", "msui"),
icon_destination)
with open(application_destination, 'w') as f:
f.write(desktop)
logging.info("menu entry created")
sys.exit()
if args.deinstall:
application_destination = constants.POSIX["application_destination"].format(app_prefix)
if os.path.exists(application_destination):
os.remove(application_destination)
icon_size = '48x48'
icon_destination = constants.POSIX["icon_destination"].format(icon_size, icon_hash)
if os.path.exists(icon_destination):
os.remove(icon_destination)
logging.info("menu entry removed")
sys.exit()

logging.info("MSS Version: %s", __version__)
logging.info("Python Version: %s", sys.version)
logging.info("Platform: %s (%s)", platform.platform(), platform.architecture())
Expand Down
18 changes: 1 addition & 17 deletions tests/_test_msui/test_msui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,25 @@
import mock
import os
import fs
import platform
import argparse
import pytest
from urllib.request import urlopen
from PyQt5 import QtWidgets, QtTest
from mslib import __version__
from tests.constants import ROOT_DIR, POSIX, MSUI_CONFIG_PATH
from tests.constants import ROOT_DIR, MSUI_CONFIG_PATH
from mslib.msui import msui
from mslib.msui import msui_mainwindow as msui_mw
from tests.utils import ExceptionMock
from mslib.utils.config import read_config_file


@mock.patch("mslib.msui.msui.constants.POSIX", POSIX)
def test_main():
with pytest.raises(SystemExit) as pytest_wrapped_e:
with mock.patch("mslib.msui.msui.argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(version=True)):
msui.main()
assert pytest_wrapped_e.typename == "SystemExit"

if platform.system() == "Linux":
with pytest.raises(SystemExit) as pytest_wrapped_e:
with mock.patch("mslib.msui.msui.argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(version=False, update=False, menu=True,
deinstall=False, debug=False, logfile="log.log")):
msui.main()
assert pytest_wrapped_e.typename == "SystemExit"
with pytest.raises(SystemExit) as pytest_wrapped_e:
with mock.patch("mslib.msui.msui.argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(version=False, update=False, menu=False,
deinstall=True, debug=False, logfile="log.log")):
msui.main()
assert pytest_wrapped_e.typename == "SystemExit"


class Test_MSS_TutorialMode:
@pytest.fixture(autouse=True)
Expand Down
15 changes: 0 additions & 15 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,3 @@
MSCOLAB_URL = "http://localhost:8083"
# mscolab test server's url
MSCOLAB_URL_TEST = "http://localhost:8084"

POSIX = {"application_destination": os.path.join(ROOT_DIR, ".local/share/applications/msui{}.desktop"),
"icon_destination": os.path.join(ROOT_DIR, ".local/share/icons/hicolor/{}/apps/mss-logo{}.png"),
"desktop": """[Desktop Entry]
Name=msui {}
Comment=A web service based tool to plan atmospheric research flights (mission support system).
Keywords=documentation;information;
Exec={}
Icon={}
Type=Application
Categories=Science;Education;
StartupNotify=true
X-GNOME-SingleWindow=false
X-Ubuntu-Gettext-Domain=msui
"""}

0 comments on commit b0032d2

Please sign in to comment.