Пример #1
0
    def downloadInfo(self, successCallback, failureCallback):
        '''
        executes version info download in separate thread, 
        then runs callback in main thread when download completes or fails
        '''

        import maya.utils
        import urllib2
        import urllib
        import json
        import threading

        mayaVersion = str(self.roundMayaVersion(Utils.getMayaVersion()))

        resource = "ngSkinTools-v1-" + Utils.getOs() + "-maya" + mayaVersion
        endpoint = "https://versiondb.ngskintools.com/releases/" + resource + "?" + urllib.urlencode(
            {
                'currentVersion': version.pluginVersion(),
                'buildWatermark': version.buildWatermark(),
                'uniqueClientId': version.uniqueClientId(),
            })

        def runnerFunc():
            try:
                result = urllib2.urlopen(endpoint).read()
                maya.utils.executeDeferred(successCallback, json.loads(result))
            except Exception, err:
                maya.utils.executeDeferred(failureCallback, str(err))
Пример #2
0
    def getRlmHostId(self):
        '''
        executes RLM host id and returns the result
        '''
        import subprocess
        import os.path as path
        toolsPath = path.abspath(
            path.join(path.dirname(__file__), "..", "tools"))

        operatingSystem = Utils.getOs()

        isLinux = operatingSystem == "linux"
        isOsx = operatingSystem == 'mac'
        useTemporaryExecutable = isLinux or isOsx

        rlmHostId = "rlmhostid.exe"
        if isLinux:
            rlmHostId = "rlmhostid-linux"
        if isOsx:
            rlmHostId = "rlmhostid-osx"

        executeCommand = [path.join(toolsPath, rlmHostId)]
        executeCommand.append("-q")

        if useTemporaryExecutable:
            # some instalation methods (extracting a zip) might not set the executable flags,
            # and we are probably better of just making a temporary executable with proper flags
            # ...and we've just discovered that the executable needs to be called exactly "rlmhostid"
            import tempfile, shutil, os
            temporaryDirectory = tempfile.mkdtemp()
            temporaryExecutable = os.path.join(temporaryDirectory, "rlmhostid")

            shutil.copy2(executeCommand[0], temporaryExecutable)
            executeCommand[0] = temporaryExecutable
            os.chmod(executeCommand[0], 0777)

        try:
            result = subprocess.check_output(executeCommand,
                                             stdin=subprocess.PIPE).strip()
        finally:
            if useTemporaryExecutable:
                os.unlink(temporaryExecutable)
                os.rmdir(temporaryDirectory)

        # rlmhostid returns zero even in case of errors; rely on the output to detect execution errors
        if "rlmhostid" in result:  # probably some kind of errors showing tool usage
            raise Exception("rlmhostid failed to execute.")
        return result