Skip to content

Commit c2aa99e

Browse files
committed
include full executable path for create_desktop_entry, handle missing setup wizard modules
1 parent d1002a5 commit c2aa99e

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

ninfs/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
# You can find the full license text in LICENSE.md in the root of this project.
66

77
from os.path import dirname, realpath
8-
from sys import argv, exit, path, version_info
8+
from sys import argv, exit, path
99

1010
# path fun times
1111
path.insert(0, dirname(realpath(__file__)))
1212

13-
from main import exit_print_types, mount
13+
from main import exit_print_types, mount, print_version
1414
if len(argv) < 2:
15+
print_version()
1516
exit_print_types()
1617

1718
if argv[1] == '--install-desktop-entry':

ninfs/gui/wizardcontainer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,14 @@ def c():
9494
self.type_selector_var = type_selector_var
9595

9696
def next_pressed(self):
97-
next_base = wizard_bases[self.current_type]
98-
self.wizardcontainer.change_frame(next_base)
97+
try:
98+
next_base = wizard_bases[self.current_type]
99+
except KeyError:
100+
mb.showerror('Derp', 'For some reason this type does not have a setup wizard module.\n'
101+
'Unfortunately this means you have to use it through the command line for now.')
102+
self.wizardcontainer.destroy()
103+
else:
104+
self.wizardcontainer.change_frame(next_base)
99105

100106

101107
class WizardMountAdvancedOptions(tk.Toplevel):

ninfs/main.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from inspect import cleandoc
1111
from os import environ, makedirs
1212
from os.path import basename, dirname, expanduser, join as pjoin, realpath
13-
from sys import exit, argv, path, platform, hexversion, version_info
13+
from sys import exit, argv, path, platform, hexversion, version_info, executable
1414

1515
_path = dirname(realpath(__file__))
1616
if _path not in path:
@@ -19,13 +19,23 @@
1919
import mountinfo
2020

2121
windows = platform in {'win32', 'cygwin'}
22+
macos = platform == 'darwin'
2223

2324
python_cmd = 'py -3' if windows else 'python3'
2425

2526
if hexversion < 0x030800F0:
2627
exit('Python {0[0]}.{0[1]}.{0[2]} is not supported. Please use Python 3.8.0 or later.'.format(version_info))
2728

2829

30+
def print_version():
31+
from __init__ import __version__
32+
pyver = '{0[0]}.{0[1]}.{0[2]}'.format(version_info)
33+
if version_info[3] != 'final':
34+
pyver += '{0[3][0]}{0[4]}'.format(version_info)
35+
# this should stay as str.format, so it runs on older versions
36+
print('ninfs v{0} on Python {1} - https://github.com/ihaveamac/ninfs'.format(__version__, pyver))
37+
38+
2939
def exit_print_types():
3040
print('Please provide a mount type as the first argument.')
3141
print('Available mount types:')
@@ -35,6 +45,10 @@ def exit_print_types():
3545
for item in items:
3646
info = mountinfo.get_type_info(item)
3747
print(f' - {item}: {info["name"]} ({info["info"]})')
48+
print()
49+
print('Additional options:')
50+
print(' --version print version')
51+
print(' --install-desktop-entry [PREFIX] create desktop entry (for Linux)')
3852
exit(1)
3953

4054

@@ -45,12 +59,7 @@ def mount(mount_type: str, return_doc: bool = False) -> int:
4559

4660
if mount_type in {'-v', '--version'}:
4761
# this kinda feels wrong...
48-
from __init__ import __version__
49-
pyver = '{0[0]}.{0[1]}.{0[2]}'.format(version_info)
50-
if version_info[3] != 'final':
51-
pyver += '{0[3][0]}{0[4]}'.format(version_info)
52-
# this should stay as str.format so it runs on older versions
53-
print('ninfs v{0} on Python {1} - https://github.com/ihaveamac/ninfs'.format(__version__, pyver))
62+
print_version()
5463
return 0
5564

5665
# noinspection PyProtectedMember
@@ -75,6 +84,7 @@ def mount(mount_type: str, return_doc: bool = False) -> int:
7584
pass
7685

7786
if mount_type not in mountinfo.types and mount_type not in mountinfo.aliases:
87+
print_version()
7888
exit_print_types()
7989

8090
module = import_module('mount.' + mountinfo.aliases.get(mount_type, mount_type))
@@ -100,11 +110,14 @@ def mount(mount_type: str, return_doc: bool = False) -> int:
100110

101111

102112
def create_desktop_entry(prefix: str = None):
103-
desktop_file = cleandoc('''
113+
if windows or macos:
114+
print('This command is not supported for Windows or macOS.')
115+
return
116+
desktop_file = cleandoc(f'''
104117
[Desktop Entry]
105118
Name=ninfs
106119
Comment=Mount Nintendo contents
107-
Exec=python3 -mninfs gui
120+
Exec="{executable}" -mninfs gui
108121
Terminal=true
109122
Type=Application
110123
Icon=ninfs

0 commit comments

Comments
 (0)