Example #1
0
def test_operating_system():
    this_os = platform_name()

    os_with_translate = common.operating_system(translate=True)
    assert len(os_with_translate) > 0
    assert os_with_translate == ("macos" if this_os == "darwin" else this_os)

    os_without_translate = common.operating_system(translate=False)
    assert len(os_without_translate) > 0
    assert os_without_translate == this_os
Example #2
0
def main(dry_run, verbose):
    """ Install Scripnix for the current user. Global configuration settings (once installed by the root user) are stored under the
        /etc/scripnix/ directory. Per-user configuration settings, including for the root user, are stored under the ~/.scripnix/ directory
        and override the global settings. The installation can be re-run repeatedly, but will not overwrite existing configuration settings
        (however file and directory permissions will be reset).

        The install-scripnix command is part of Scripnix.
    """
    def execute(fn, *args, echo):
        """ Call the given function with its arguments if this is not a dry run. If it is a dry run, or the verbose flag is set, echo the
            given text to STDOUT. By closing over these two flags within this function, the install functions are much less complicated.
        """
        if not dry_run:
            fn(*args)

        if dry_run or verbose:
            click.echo(echo)

    if dry_run:
        click.echo("{} would do the following:".format(COMMAND_NAME))
    elif verbose:
        click.echo("{} is performing the following:".format(COMMAND_NAME))

    if is_root_user():
        install_global(execute,
                       config_path=ROOT_CONFIG_DIR,
                       os_name=operating_system())

    install_per_user(execute, config_path=USER_CONFIG_DIR)
Example #3
0
def test_valid_command_name():
    command = command_name(0)
    assert "python" in command or "py.test" in command

    command = command_name(os.getpid())
    assert "python" in command or "py.test" in command

    command = command_name(1)
    assert command in (["launchd"] if operating_system() == "macos" else
                       ["init", "systemd"])
Example #4
0
def test_install_global():
    def execute(fn, *args, echo):
        fn(*args)
        _ = echo  # noqa: F841

    with CliRunner().isolated_filesystem():
        # Run twice to exercise both paths of the file existence check.
        install_global(execute,
                       config_path="./test",
                       os_name=operating_system())
        install_global(execute,
                       config_path="./test",
                       os_name=operating_system())

        _check_exists_with_mode(
            ("./test", 0o42755), ("./test/archive-paths", 0o42750),
            ("./test/archive-exclusions", 0o100640),
            ("./test/conf.bash", 0o100644), ("./test/README", 0o100444),
            ("./test/sconf.bash", 0o100640),
            ("./test/scripnix-" + __version__, 0o100000))

        # Test for presence of archive-paths/ symlinks.
        archive_paths_path = "./test/archive-paths"
        assert len(os.listdir(archive_paths_path)) >= 6

        for name in os.listdir(archive_paths_path):
            assert name.startswith(hostname())
            assert os.path.islink(os.path.join(archive_paths_path, name))

        _check_file_contents(
            ("./test/archive-exclusions", r"^\/var\/archive$"),
            ("./test/conf.bash",
             r"^# Global configuration setting overrides for conf\.bash\.$"),
            ("./test/README", r"^Global Scripnix configuration settings\.$"),
            ("./test/sconf.bash",
             r"^# Global configuration setting overrides for sconf\.bash\.$"))
Example #5
0
import grp
import os
import pwd
import stat
import subprocess

import click

from scripnix import __version__
from scripnix.util.command import common_command_and_options
from scripnix.util.common import hostname, is_root_user, operating_system, USER_CONFIG_DIR, ROOT_CONFIG_DIR

COMMAND_NAME = "install-scripnix"

RC_PATH_CHOICES = ("~/.bashrc", "~/.bash_profile",
                   "~/.profile") if operating_system() == "macos" else (
                       "~/.profile", "~/.bashrc")
RC_PATHS = list(map(os.path.expanduser, RC_PATH_CHOICES))


def install_global(execute, config_path, os_name):
    """ Install global Scripnix configuration settings.
    """
    # mkdir /etc/scripnix
    if not os.path.isdir(config_path):
        execute(os.mkdir, config_path, echo="mkdir {}".format(config_path))

    execute(os.chmod,
            config_path,
            stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP
            | stat.S_IXGRP | stat.S_ISGID | stat.S_IROTH | stat.S_IXOTH,
Example #6
0
def main(no_translate):
    """ Return the operating system platform name.

        The os-name command is part of Scripnix.
    """
    click.echo(operating_system(not no_translate))