Esempio n. 1
0
    def _process_project_dir(self):
        project_dir = self.devenvconf["project_dir"]
        project_dir = self._eval_in_shell(project_dir)

        if not isinstance(project_dir, str):
            raise WrongOptionType("project_dir", str)
        self._add_volume(project_dir)
Esempio n. 2
0
    def _process_gdb(self):
        gdb = self.devenvconf["gdb"]

        if not(gdb, bool):
            raise WrongOptionType("gdb", bool)

        if gdb:
            # self._add_cap("SYS_ADMIN")
            self._add_cap("SYS_PTRACE")  # TODO:
Esempio n. 3
0
    def _process_resources(self):
        resources = self.devenvconf["resources"]

        if not isinstance(resources, dict):
            raise WrongOptionType("project_dir", dict)

        if "directories" in resources:
            if not isinstance(resources["directories"], list):
                raise WrongOptionType("directories", list)
            for directory in resources["directories"]:
                directory = self._eval_in_shell(directory)
                self._add_volume(directory)

        if "files" in resources:
            if not isinstance(resources["files"], list):
                raise WrongOptionType("files", list)
            for file in resources["files"]:
                file = self._eval_in_shell(file)
                self._add_volume(file, is_file=True)
Esempio n. 4
0
    def _process_resources(self):
        resources = self.devenvconf["resources"]

        if type(resources) is not dict:
            raise WrongOptionType("project_dir", dict)

        if "directories" in resources:
            if type(resources["directories"]) is not list:
                raise WrongOptionType("directories", list)
            for dir in resources["directories"]:
                dir = self._eval_in_shell(dir)
                self._add_volume(dir)

        if "files" in resources:
            if type(resources["files"]) is not list:
                raise WrongOptionType("files", list)
            for file in resources["files"]:
                file = self._eval_in_shell(file)
                self._add_volume(file, is_file=True)
Esempio n. 5
0
    def _process_matlab(self):
        matlab = self.devenvconf["matlab"]
        
        if not isinstance(matlab, dict):
            raise WrongOptionType("matlab", dict)

        try:
            self._child_must_exist(matlab, "folder", str)
            self._child_must_exist(matlab, "dotdir", str)

            matlabfolder = self._eval_in_shell(matlab["folder"])
            matlabdotdir = self._eval_in_shell(matlab["dotdir"])

            if not pathlib.Path(matlabfolder).exists():
                raise Exception(
                    "Matlab folder '" + matlabfolder + "'does not exist")

            self._add_volume(matlabfolder + ":/usr/local/MATLAB:rw")
            self._add_volume(matlabdotdir)
            self._add_environment_var("Matlab_ROOT_DIR=/usr/local/MATLAB")

            if "mac" in matlab:
                mac = self._eval_in_shell(matlab["mac"])

                if not isinstance(mac, str):
                    raise WrongOptionType("mac", str)
                if self._is_mac_address(mac):
                    self._set_mac(mac)
                else:
                    macaddr = self._getmac(mac)
                    self._set_mac(macaddr)

        except MissingOption:
            print("While processing 'user' element")
            raise
            sys.exit()
        except WrongOptionType:
            print("While processing 'user' element")
            raise
            sys.exit()
Esempio n. 6
0
    def _process_init(self):
        init = self.devenvconf["init"]
        init = self._eval_in_shell(init)

        if not isinstance(init, str):
            raise WrongOptionType("init", str)

        if init == "systemd":
            self._set_init("/sbin/init")
            self._add_volume("/sys/fs/cgroup")
            self._add_tmpfs("/run")  # TODO: check if duplicate
            self._add_tmpfs("/run/lock")
            self._add_cap("SYS_ADMIN")
            self._set_stopsignal("SIGRTMIN+3")
Esempio n. 7
0
    def _process_gpu(self):
        gpu = self.devenvconf["gpu"]
        gpu = self._eval_in_shell(gpu)

        if not isinstance(gpu, str):
            raise WrongOptionType("gpu", str)

        if gpu == "intel":
            self._add_device("/dev/dri")
            self._add_volume("/dev/shm")
            self._set_runtime("runc")
        elif gpu == "nvidia":
            self._add_device("/dev/dri")
            self._set_runtime("nvidia")
        else:
            raise Exception("gpu '" + gpu + "' not supported")
Esempio n. 8
0
    def _process_x11(self):
        x11 = self.devenvconf["x11"]
        x11 = self._eval_in_shell(x11)

        if not isinstance(x11, str):
            raise WrongOptionType("x11", str)

        if x11 == "xhost":
            self._add_volume("/tmp/.X11-unix")
            self._add_environment_var("DISPLAY")
            # TODO: any better method? Such as a pre-start hook?
            #       Split docker create and docker start?
            if subprocess.call("xhost +si:locahost:" + getpass.getuser()) != 0:
                raise Exception("Failed to grant current user the xhost rights")

        elif x11 == "xauth":
            # Create xauthority file
            self._create_xauth(self._get_xauth_filename())
            self._add_volume(self._get_xauth_filename(), is_file=True)
            self._add_volume("/tmp/.X11-unix")
            self._add_environment_var("DISPLAY")
            self._add_environment_var("XAUTHORITY=" + self._get_xauth_filename())
Esempio n. 9
0
    def _process_git(self):
        git = self.devenvconf["git"]

        if not isinstance(git, dict):
            raise WrongOptionType("git", dict)

        try:
            self._child_must_exist(git, "username", str)
            self._child_must_exist(git, "email", str)

            git_username = self._eval_in_shell(git["username"])
            git_email = self._eval_in_shell(git["email"])

            self._add_environment_var("GIT_USER_NAME=" + git_username)
            self._add_environment_var("GIT_USER_EMAIL=" + git_email)
            # TODO: gpg
        except MissingOption:
            print("While processing 'git' element")
            raise
            sys.exit()
        except WrongOptionType:
            print("While processing 'git' element")
            raise
            sys.exit()
Esempio n. 10
0
 def _child_must_exist(root, option, typeid=None):
     if option not in root:
         raise MissingOption(option)
     if typeid is not None:
         if not isinstance(root[option], typeid):
             raise WrongOptionType(option, typeid)
Esempio n. 11
0
 def _child_must_exist(self, root, option, typeid=None):
     if option not in root:
         raise MissingOption(option)
     if typeid is not None:
         if type(root[option]) is not typeid:
             raise WrongOptionType(option, typeid)