def run(self): """Doc...""" # Create the bin directory where the output will be stored if it does not already exist binPath = self.getBinPath(isDir=True) if not os.path.exists(binPath): os.makedirs(binPath) # Remove any folders created by previous build attempts for d in self._CLEANUP_FOLDERS: path = os.path.join(binPath, d) if os.path.exists(path): shutil.rmtree(path) os.chdir(binPath) ResourceCollector(self, verbose=True).run() cmd = [ FileUtils.makeFilePath(sys.prefix, 'bin', 'python'), '"%s"' % self._createSetupFile(binPath), OsUtils.getPerOsValue('py2exe', 'py2app'), '>', '"%s"' % self.getBinPath('setup.log', isFile=True)] print('[COMPILING]: Executing %s' % OsUtils.getPerOsValue('py2exe', 'py2app')) print('[COMMAND]: %s' % ' '.join(cmd)) result = SystemUtils.executeCommand(cmd, remote=False, wait=True) if result['code']: print('COMPILATION ERROR:') print(result['out']) print(result['error']) return False if self.appFilename and OsUtils.isWindows(): name = self.applicationClass.__name__ source = FileUtils.createPath(binPath, 'dist', name + '.exe', isFile=True) dest = FileUtils.createPath(binPath, 'dist', self.appFilename + '.exe', isFile=True) os.rename(source, dest) if OsUtils.isWindows() and not self._createWindowsInstaller(binPath): print('Installer Creation Failed') return False elif OsUtils.isMac() and not self._createMacDmg(binPath): print('DMG Creation Failed') return False # Remove the resources path once compilation is complete resourcePath = FileUtils.createPath(binPath, 'resources', isDir=True) SystemUtils.remove(resourcePath) buildPath = FileUtils.createPath(binPath, 'build', isDir=True) SystemUtils.remove(buildPath) FileUtils.openFolderInSystemDisplay(binPath) return True
def checkEnvFile(cls, target, otherPaths=None): """Doc...""" pathSep = OsUtils.getPerOsValue(';', ':') additions = cls._getSourcePaths(otherPaths=otherPaths) with open(target, 'r') as f: contents = f.read() result = cls._PYTHON_PATH_PATTERN.search(contents) if not result: return False paths = result.groupdict()['paths'].split(pathSep) for addition in additions: found = False for p in paths: p = FileUtils.cleanupPath(p, noTail=True) if p == FileUtils.cleanupPath(addition.folderPath, noTail=True): found = True break if not found: return False return True
def checkEnvFile(cls, target, otherPaths =None): """Doc...""" pathSep = OsUtils.getPerOsValue(';', ':') additions = cls._getSourcePaths(otherPaths=otherPaths) with open(target, 'r') as f: contents = f.read() result = cls._PYTHON_PATH_PATTERN.search(contents) if not result: return False paths = result.groupdict()['paths'].split(pathSep) for addition in additions: found = False for p in paths: p = FileUtils.cleanupPath(p, noTail=True) if p == FileUtils.cleanupPath(addition.folderPath, noTail=True): found = True break if not found: return False return True
def modifyEnvFile(cls, target, install =True, test =False, otherPaths =None): """Doc...""" pathSep = OsUtils.getPerOsValue(';', ':') removals = [] entries = cls._getSourcePaths(otherPaths=otherPaths) additions = entries + [] with open(target, 'r') as f: contents = f.read().strip() result = cls._PYTHON_PATH_PATTERN.search(contents) if not result: if install and not test: with open(target, 'w') as f: f.write( (contents + '\n' if contents else '') + 'PYTHONPATH=' + cls._joinPathEntries(additions) ) return cls.MAYA_ENV_MODIFIED_RESULT_NT(additions if install else [], removals) paths = result.groupdict()['paths'].strip() paths = paths.split(pathSep) if paths else [] if not paths and not install: return cls.MAYA_ENV_MODIFIED_RESULT_NT([], []) index = 0 while index < len(paths): # Stop if no more additions remain if not additions: break p = FileUtils.cleanupPath(paths[index], noTail=True) # If path already exists don't add it again pathMatch = cls._hasPath(p, additions) if pathMatch: additions.remove(pathMatch) # If uninstalling add to removals if not install: removals.append(pathMatch) paths.remove(p) else: index += 1 continue elif not install: index += 1 continue for entry in entries: testPath = FileUtils.createPath(p, entry.rootName, noTail=True) if os.path.exists(testPath): paths.remove(p) index += 1 for entry in additions: paths.append(entry.folderPath) insertion = ('PYTHONPATH=' + pathSep.join(paths) + '\n') if paths else '' contents = contents[:result.start()] + insertion + contents[result.end():] result = cls.MAYA_ENV_MODIFIED_RESULT_NT(additions if install else [], removals) if test: return result with open(target, 'w') as f: f.write(contents) return result
def _joinPathEntries(cls, entries): out = [] for entry in entries: out.append(entry.folderPath) return OsUtils.getPerOsValue(';', ':').join(out)
def modifyEnvFile(cls, target, install =True, test =False): """Doc...""" pathSep = OsUtils.getPerOsValue(u';', u':') nimblePath = FileUtils.createPath( FileUtils.getDirectoryOf(nimble.__file__), '..', isDir=True, noTail=True) pyaidPath = FileUtils.createPath( FileUtils.getDirectoryOf(pyaid.__file__), '..', isDir=True, noTail=True) pyglassPath = FileUtils.createPath( FileUtils.getDirectoryOf(pyglass.__file__), '..', isDir=True, noTail=True) removals = [] additions = [nimblePath] if not StringUtils.matches(pyaidPath, additions): additions.append(pyaidPath) if not StringUtils.matches(pyglassPath, additions): additions.append(pyglassPath) with open(target, 'r') as f: contents = f.read() result = cls._PYTHON_PATH_PATTERN.search(contents) if not result: if install: contents += (u'\n' if contents else u'') + u'PYTHONPATH=' + pathSep.join(additions) else: return cls.MAYA_ENV_MODIFIED_RESULT_NT([], []) else: paths = result.groupdict()['paths'].split(pathSep) index = 0 while index < len(paths): if not additions: break p = paths[index] # If path already exists don't add it again if p in additions: additions.remove(p) if not install: removals.append(p) paths.remove(p) else: index += 1 continue elif not install: index += 1 continue # Remove unrecognized paths that import nimble, pyaid, or pyglass testPaths = [ FileUtils.createPath(p, u'nimble', isDir=True), FileUtils.createPath(p, u'pyaid', isDir=True), FileUtils.createPath(p, u'pyglass', isDir=True) ] for test in testPaths: if os.path.exists(test): paths.remove(p) continue index += 1 paths += additions contents = contents[:result.start()] + u'PYTHONPATH=' + pathSep.join(paths) \ + u'\n' + contents[result.end():] result = cls.MAYA_ENV_MODIFIED_RESULT_NT(additions if install else [], removals) if test: return result with open(target, 'w') as f: f.write(contents) return result
def modifyEnvFile(cls, target, install=True, test=False, otherPaths=None): """Doc...""" pathSep = OsUtils.getPerOsValue(';', ':') removals = [] entries = cls._getSourcePaths(otherPaths=otherPaths) additions = entries + [] with open(target, 'r') as f: contents = f.read().strip() result = cls._PYTHON_PATH_PATTERN.search(contents) if not result: if install and not test: with open(target, 'w') as f: f.write((contents + '\n' if contents else '') + 'PYTHONPATH=' + cls._joinPathEntries(additions)) return cls.MAYA_ENV_MODIFIED_RESULT_NT( additions if install else [], removals) paths = result.groupdict()['paths'].strip() paths = paths.split(pathSep) if paths else [] if not paths and not install: return cls.MAYA_ENV_MODIFIED_RESULT_NT([], []) index = 0 while index < len(paths): # Stop if no more additions remain if not additions: break p = FileUtils.cleanupPath(paths[index], noTail=True) # If path already exists don't add it again pathMatch = cls._hasPath(p, additions) if pathMatch: additions.remove(pathMatch) # If uninstalling add to removals if not install: removals.append(pathMatch) paths.remove(p) else: index += 1 continue elif not install: index += 1 continue for entry in entries: testPath = FileUtils.createPath(p, entry.rootName, noTail=True) if os.path.exists(testPath): paths.remove(p) index += 1 for entry in additions: paths.append(entry.folderPath) insertion = ('PYTHONPATH=' + pathSep.join(paths) + '\n') if paths else '' contents = contents[:result.start()] + insertion + contents[result.end( ):] result = cls.MAYA_ENV_MODIFIED_RESULT_NT(additions if install else [], removals) if test: return result with open(target, 'w') as f: f.write(contents) return result