Exemplo n.º 1
0
    def isRunnable(self, entry_point=None): # fold>>
        """
        @description checks runnability conditions.
        @description A package is runnable for a given entry point when the following conditions are met:
        @description  - there is an executable group with that entry point
        @description  - the executable exists for the current platform and is executable
        @description  - if an interpreter is declared, the interpreter can be found and is executable
        """

        if self.__is_zipped:
            self._unpack()

        # if we have no executables, it is quickly said
        if len(self.__manifest.executableGroupList()) == 0: 
            return False
        
        # try with the default entry point if not provided
        if entry_point is None:
            entry_point = self.defaultExecutableGroupEntryPoint()
            # no default? then we know the answer
            if entry_point is None:
                return False
        executable_group = self.__manifest.executableGroup(entry_point)
        if executable_group is None:
            return False
            
        # try with the executable for the current platform. If not found, try with something that is supported
        executable = executable_group.executable(Platform.currentPlatform())

        if executable is None:
            # try to see if there's an executable that can run on this platform
            for exe in executable_group.executableList():
                if Platform.isCompatibleWith(exe.platform()):
                    executable = exe
                    break

        # still none? we rest our case
        if executable is None:
            return False
       
        # check for the existence of the file as specified in the path
        executable_absolute_path = _computeExecutableAbsolutePath(self.rootDir(), executable.path(), executable.pathType(), executable.platform())
        if not os.path.exists(executable_absolute_path):
            return False

        # check if the executable is interpreted, and in this case, if the interpreter can be found and executed
        interpreter = executable.interpreter()
        if interpreter is not None:
            interpreter_path=_which(interpreter)
            if interpreter_path is None:
                return False
            if not _isExecutable(interpreter_path):
                return False
        else:
           # not interpreted, check the executability of the file itself 
            if not _isExecutable(executable_absolute_path):
                return False

        # looks like there are chances it can be executable, after all
        return True 
Exemplo n.º 2
0
    def runEntryPoint(self, entry_point, arguments=None, environment=None): # fold>>
        """
        @description runs the platform specific executable with a given entry poin, or a compatible 
        @description platform specific/aspecific code under the same entry point.
        @description The function never returns. The executable runs with an execve call which
        @description replaces the current executable with the new executable. If you want to fork, you
        @description have to do it before calling run()
        """ 
        if self.__is_zipped:
            self._unpack()

        if not self.isRunnable(entry_point):
            raise NotRunnableException("Entry point "+entry_point+" is not runnable.")
      
        if arguments is None:
            arguments=[]
        if environment is None:
            environment = os.environ

        # add the environment variable containing the package base directory.
        # we use this and not os.setenv because os.setenv does not export to child processes.
        environment["PACKAGE_ROOT_DIR"]=self.rootDir()
        environment["CN_ROOT_DIR"]=self.rootDir()
        environment["CN_ENTRY_POINT"] = entry_point

        # FIXME: this code is heavily repeated. refactor it out!
        executable_group = self.__manifest.executableGroup(entry_point)
        executable = executable_group.executable(Platform.currentPlatform())
        if executable is None:
            # try to see if there's an executable that can run on this platform
            for exe in executable_group.executableList():
                if Platform.isCompatibleWith(exe.platform()):
                    executable = exe
                    break

        environment["CN_RUN_ARCH"]=executable.platform() 
        executable_absolute_path = _computeExecutableAbsolutePath(self.rootDir(), executable.path(), executable.pathType(), executable.platform())

        interpreter = executable.interpreter()
        if interpreter is not None:
            interpreter_path=_which(interpreter)
            os.execve(interpreter_path, [interpreter_path, executable_absolute_path]+list(arguments), environment)
        else:
            os.execve(executable_absolute_path,[executable_absolute_path]+list(arguments), environment)
Exemplo n.º 3
0
    def executableAbsolutePath(self, entry_point): # fold>>
        if self.__is_zipped:
            self._unpack()
        platform = Platform.currentPlatform()
        
        group = self.__manifest.executableGroup(entry_point)

        if group is None:
            return None

        executable = group.executable(platform)

        if executable is not None:
            return _computeExecutableAbsolutePath(self.rootDir(), executable.path(), executable.pathType(), platform)

        # look for something compatible
        for executable in group.executableList():
            if Platform.isCompatibleWith(executable.platform()):
                return _computeExecutableAbsolutePath(self.rootDir(), executable.path(), executable.pathType(), executable.platform())

        return None
Exemplo n.º 4
0
    def resourceAbsolutePath(self, entry_point): # fold>>
        if self.__is_zipped:
            self._unpack()
        platform = Platform.currentPlatform()

        group = self.__manifest.resourceGroup(entry_point)

        if group is None:
            return None

        resource = group.resource(platform)

        if resource is not None:
            return _computeResourceAbsolutePath(self.rootDir(), resource.path(), resource.pathType(), platform)

        # look for something compatible
        for resource in group.resourceList():
            if Platform.isCompatibleWith(resource.platform()):
                return _computeResourceAbsolutePath(self.rootDir(), resource.path(), resource.pathType(), resource.platform())

        return None