Skip to content

Commit

Permalink
Merge branch '63-improve-packaging'
Browse files Browse the repository at this point in the history
  • Loading branch information
flozz committed May 23, 2021
2 parents c168869 + c5e7bfa commit 0efe88c
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 31 deletions.
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ Running lint and tests::
Happy hacking! :)


Packaging This Software
-----------------------

If you want to package this software for a Linux distribution, here are some
useful information for you:

* You can use the ``python3 setup.py install --root /tmp/foo/bar`` command to
perform a system-wide-like install in the specified folder.

* You should remove the ``nautilus_terminal/not_packaged.py`` file from your
package. Removing this file will disable options that allow user to modify
its installation (``--install-*`` and ``--uninstall-*`` options of the
``nautilus-terminal`` command).


Supporting this project
-----------------------

Expand Down
98 changes: 71 additions & 27 deletions nautilus_terminal/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .install_nautilus_extension import uninstall_system
from .install_nautilus_extension import install_user
from .install_nautilus_extension import uninstall_user
from .install_nautilus_extension import is_packaged


_EPILOG = """
Expand Down Expand Up @@ -129,6 +130,20 @@ def __call__(self, parser, namespace, value, option_string=None):
sys.exit(0)


class DisplayPackagedMessageAction(argparse.Action):
"""Display a message for packaged Nautilus Terminal versions when the user
try to call the "installation fix" options."""

def __call__(self, parser, namespace, value, option_string=None):
print("E: You cannot perform this action:")
print(
"You installed Nautilus Terminal using a distribution package. "
"If you encounter an issue, try to reinstall it or contact "
"its maintainer."
)
sys.exit(1)


def main(args=sys.argv[1:]):
cli_parser = argparse.ArgumentParser(
prog="nautilus-terminal",
Expand All @@ -155,33 +170,62 @@ def main(args=sys.argv[1:]):
action=CheckExtensionAction,
)

cli_parser.add_argument(
"--install-system",
help="Install Nautilus Terminal extention system-wide and exit",
nargs=0,
action=InstallSystemAction,
)

cli_parser.add_argument(
"--uninstall-system",
help="Uninstall Nautilus Terminal extention system-wide and exit",
nargs=0,
action=UninstallSystemAction,
)

cli_parser.add_argument(
"--install-user",
help="Install Nautilus Terminal extention for the current user and exit",
nargs=0,
action=InstallUserAction,
)

cli_parser.add_argument(
"--uninstall-user",
help="Uninstall Nautilus Terminal extention from the current user and exit.",
nargs=0,
action=UninstallUserAction,
)
if not is_packaged():
cli_parser.add_argument(
"--install-system",
help="Install Nautilus Terminal extention system-wide and exit",
nargs=0,
action=InstallSystemAction,
)

cli_parser.add_argument(
"--uninstall-system",
help="Uninstall Nautilus Terminal extention system-wide and exit",
nargs=0,
action=UninstallSystemAction,
)

cli_parser.add_argument(
"--install-user",
help="Install Nautilus Terminal extention for the current user and exit",
nargs=0,
action=InstallUserAction,
)

cli_parser.add_argument(
"--uninstall-user",
help="Uninstall Nautilus Terminal extention from the current user and exit.",
nargs=0,
action=UninstallUserAction,
)
else:
cli_parser.add_argument(
"--install-system",
help=argparse.SUPPRESS,
nargs=0,
action=DisplayPackagedMessageAction,
)

cli_parser.add_argument(
"--uninstall-system",
help=argparse.SUPPRESS,
nargs=0,
action=DisplayPackagedMessageAction,
)

cli_parser.add_argument(
"--install-user",
help=argparse.SUPPRESS,
nargs=0,
action=DisplayPackagedMessageAction,
)

cli_parser.add_argument(
"--uninstall-user",
help=argparse.SUPPRESS,
nargs=0,
action=DisplayPackagedMessageAction,
)

if len(args) == 0:
cli_parser.parse_args(["--help"])
Expand Down
4 changes: 4 additions & 0 deletions nautilus_terminal/install_nautilus_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
GLIB_COMPILE_SCHEMA = "/usr/bin/glib-compile-schemas"


def is_packaged():
return not os.path.isfile(os.path.join(ROOT, "not_packaged.py"))


def is_system_extension_installed():
return os.path.isfile(
os.path.join(SYSTEM_EXTENSION_DIR, EXTENSION_FILE)
Expand Down
8 changes: 8 additions & 0 deletions nautilus_terminal/not_packaged.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
This file should only be present when Nautilus Terminal is installed from
sources (Github or PyPI).
If you are packaging this application for a Linux distribution, please remove
this file, it will disable all the `--install-*` and `--uninstall-*` options of
the `nautilus-terminal` command.
"""
30 changes: 26 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,39 @@
from setuptools.command.install import install as _install

from nautilus_terminal import VERSION
from nautilus_terminal.install_nautilus_extension import install_system
from nautilus_terminal.install_nautilus_extension import install_user


class install(_install):
def run(self):
_install.run(self)

if os.getuid() == 0:
is_root_user = os.getuid() == 0
is_system_install = bool(self.root) or is_root_user
is_user_install = not is_system_install
data_prefix = "%s%s/share" % (
(self.root if self.root else ""),
self.install_base,
)

print("Installation parameters:")
print(" is_root_user: %s" % str(is_root_user))
print(" is_system_install: %s" % str(is_system_install))
print(" is_user_install: %s" % str(is_user_install))
print(" data_prefix: %s" % data_prefix)

if is_system_install:
os.environ["XDG_DATA_DIR"] = data_prefix

from nautilus_terminal.install_nautilus_extension import (
install_system,
)

install_system()
else:
elif is_user_install:
from nautilus_terminal.install_nautilus_extension import (
install_user,
)

install_user()


Expand Down

0 comments on commit 0efe88c

Please sign in to comment.