File: __init__.py

package info (click to toggle)
python-spython 0.3.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 736 kB
  • sloc: python: 3,299; sh: 61; makefile: 28
file content (65 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (C) 2017-2022 Vanessa Sochat.

# This Source Code Form is subject to the terms of the
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.


from spython.logger import bot
from spython.utils import check_install, get_singularity_version

from .command import generate_bind_list, init_command, run_command
from .flags import parse_verbosity
from .generate import RobotNamer
from .logger import init_level, println
from .sutils import get_filename, get_uri, load, setenv


class Client:
    def __str__(self):
        base = "[singularity-python]"
        if hasattr(self, "simage"):
            if self.simage.image not in [None, ""]:
                base = "%s[%s]" % (base, self.simage)
        return base

    def __repr__(self):
        return self.__str__()

    def __init__(self):
        """
        The base client for singularity, will have commands added to it.
        upon init, store verbosity requested in environment MESSAGELEVEL.
        """
        self._init_level()

    def version(self):
        """
        Shortcut to get_singularity_version, takes no arguments.
        """
        return get_singularity_version()

    def _check_install(self):
        """
        Ensure that singularity is installed, and exit if not.
        """
        if check_install() is not True:
            bot.exit("Cannot find Singularity! Is it installed?")


# Image Utils
Client.load = load
Client._get_filename = get_filename
Client._get_uri = get_uri
Client.setenv = setenv

# Commands
Client._generate_bind_list = generate_bind_list
Client._init_command = init_command
Client._run_command = run_command

# Flags and Logger
Client._parse_verbosity = parse_verbosity
Client._println = println
Client._init_level = init_level
Client.RobotNamer = RobotNamer()