def _deployResources(cls): """ On windows the resource folder data is stored within the application install directory. However, due to permissions issues, certain file types cannot be accessed from that directory without causing the program to crash. Therefore, the stored resources must be expanded into the user's AppData/Local folder. The method checks the currently deployed resources folder and deploys the stored resources if the existing resources either don't exist or don't match the currently installed version of the program. """ if not OsUtils.isWindows() or not PyGlassEnvironment.isDeployed: return False storagePath = PyGlassEnvironment.getInstallationPath('resource_storage', isDir=True) storageStampPath = FileUtils.makeFilePath(storagePath, 'install.stamp') resourcePath = PyGlassEnvironment.getRootResourcePath(isDir=True) resourceStampPath = FileUtils.makeFilePath(resourcePath, 'install.stamp') try: resousrceData = JSON.fromFile(resourceStampPath) storageData = JSON.fromFile(storageStampPath) if resousrceData['CTS'] == storageData['CTS']: return False except Exception as err: pass SystemUtils.remove(resourcePath) FileUtils.mergeCopy(storagePath, resourcePath) return True
def _copyResourceFolder(self, sourcePath, parts): targetPath = FileUtils.createPath(self._targetPath, *parts, isDir=True) WidgetUiCompiler(sourcePath).run() if self._verbose: self._log.write('COPYING: %s -> %s' % (sourcePath, targetPath)) return FileUtils.mergeCopy(sourcePath, targetPath)
def _copyV4SupportLib(self): v4Path = self._owner.mainWindow.getAndroidSDKPath(*AndroidCompiler._V4_SUPPORT_LIB, isDir=True) for item in os.listdir(v4Path): itemPath = FileUtils.createPath(v4Path, item, isDir=True) self._copyMerges.append( FileUtils.mergeCopy(itemPath, self.getTargetPath('android', 'src'), False) )
def _deployIcons(cls, sourcePath, targetPath, record): merges = record['merges'] dirs = record['dirs'] itemNames = record['itemNames'] icons = record['icons'] merges.append(FileUtils.mergeCopy(sourcePath, targetPath)) dirs.append(sourcePath) itemNames.append('icons') for item in os.listdir(targetPath): size = item.split('_')[-1].split('.')[0] icons.append({'size':size, 'name':item})
def deployExternalIncludes(cls, flexProjectData): """ Deploys all of the external includes file and folders to the platform-specific project bin folder for use in packaging or debugging. Returns a list of FileLists for each copy operation that occurred so that the deploy operation can be undone later. """ dirs = [] files = [] merges = [] itemNames = [] out = {'dirs':dirs, 'files':files, 'merges':merges, 'itemNames':itemNames, 'icons':[]} sets = flexProjectData #------------------------------------------------------------------------------------------- # ICONS # Cascade through the various locations where icons may reside for a given platform # and copy the preferred location to the bin for compilation. iconTargetPath = FileUtils.createPath(sets.platformBinPath, 'icons', isDir=True) #--- Platform[Specific] | Build-Type[Specific] ---# iconPath = FileUtils.createPath( sets.platformProjectPath, 'icons', sets.buildTypeFolderName, isDir=True) #--- Platform[Specific] | Build-Type[Generic] ---# if not os.path.exists(iconPath): iconPath = FileUtils.createPath(sets.platformProjectPath, 'icons', isDir=True) #--- Platform[Generic] | Build-Type[Specific] ---# if not os.path.exists(iconPath): iconPath = FileUtils.createPath( sets.projectPath, 'icons', sets.buildTypeFolderName, isDir=True) #--- Platform[Generic] | Build-Type[Generic] ---# if not os.path.exists(iconPath): iconPath = FileUtils.createPath(sets.projectPath, 'icons', isDir=True) # If an icon path exists, copy those files to the target path for inclusion if os.path.exists(iconPath): cls._deployIcons(iconPath, iconTargetPath, out) cls.updateAppIconList(sets.appDescriptorPath, out['icons']) #------------------------------------------------------------------------------------------- # INCLUDES FOLDER # Copy everything in the includes directory with the generic includes first and then # the platform-specific includes merged in (potentially overwriting general files # in the process if there is a naming collision. This allows for platform specific # file overrides when desirable. #--- Generic Includes ---# includesPath = sets.externalIncludesPath if os.path.exists(includesPath): for item in os.listdir(includesPath): if item.startswith('.'): continue source = FileUtils.createPath(includesPath, item) merges.append(FileUtils.mergeCopy( source, FileUtils.createPath(sets.platformBinPath, item))) if os.path.isdir(source): dirs.append(source) else: files.append(source) itemNames.append(item) #--- Specific Includes ---# includesPath = sets.platformExternalIncludesPath if not includesPath or not os.path.exists(includesPath): return out for item in os.listdir(includesPath): if item.startswith('.'): continue source = FileUtils.createPath(includesPath, item) merges.append(FileUtils.mergeCopy( source, FileUtils.createPath(sets.platformBinPath, item))) if os.path.isdir(source): dirs.append(source) else: files.append(source) itemNames.append(item) return out
def _runImpl(self): if not os.path.exists(self.targetWebRootPath): os.makedirs(self.targetWebRootPath) for staticPath in self.get('STATIC_PATHS', []): self._staticPaths.append(FileUtils.createPath( self.sourceWebRootPath, *staticPath.strip(u'/').split(u'/'))) #------------------------------------------------------------------------------------------- # COPY FILES # Copies files from the source folders to the target root folder, maintaining folder # structure in the process FileUtils.walkPath(self.sourceWebRootPath, self._copyWalker) #--- COMMON FILES ---# copies = [ (u'StaticFlow Javascript', 'web/js', 'js/sflow'), (u'StaticFlow CSS', 'web/css', 'css/sflow') ] for item in copies: source = FileUtils.createPath( StaticFlowEnvironment.rootResourcePath, *item[1].split('/'), isDir=True) target = FileUtils.createPath( self.targetWebRootPath, *item[2].split('/'), isDir=True) if os.path.exists(target): SystemUtils.remove(target) targetFolder = FileUtils.createPath(target, '..', isDir=True) if not os.path.exists(targetFolder): os.makedirs(targetFolder) fileList = FileUtils.mergeCopy(source, target) for path, data in fileList.files.iteritems(): SiteProcessUtils.copyToCdnFolder( path, self, FileUtils.getUTCModifiedDatetime(source)) self.writeLogSuccess(u'COPIED', u'%s | %s -> %s' % ( item[0], source.rstrip(os.sep), target.rstrip(os.sep) )) #------------------------------------------------------------------------------------------- # COMPILE # Compiles source files to the target root folder currentPath = os.curdir os.path.walk(self.sourceWebRootPath, self._compileWalker, None) os.chdir(currentPath) #------------------------------------------------------------------------------------------- # CREATE PAGE DEFS # Creates the page data files that define the pages to be generated os.path.walk(self.sourceWebRootPath, self._htmlDefinitionWalker, None) self._pages.process() self._sitemap.write() self._robots.write() for rssGenerator in self._rssGenerators: rssGenerator.write() self._writeGoogleFiles() #------------------------------------------------------------------------------------------- # CLEANUP # Removes temporary and excluded file types from the target root folder os.path.walk(self.targetWebRootPath, self._cleanupWalker, dict()) return True
def _compileImpl(self): sets = self._settings os.chdir(sets.projectPath) adtPath = self.getAirPath('bin', 'adt', isFile=True) swcRootPath = FileUtils.createPath(sets.projectPath, 'swc', isDir=True) buildPath = FileUtils.createPath(sets.projectPath, 'build', isDir=True) SystemUtils.remove(buildPath) os.makedirs(buildPath) sets.setPlatform(FlexProjectData.DEFAULT_PLATFORM) swcPath = FileUtils.createPath( swcRootPath, sets.getSetting('FOLDER'), sets.getSetting('FILENAME') + '.swc', isFile=True) cmd = [adtPath, '-package', '-target', 'ane', sets.getSetting('FILENAME') + '.ane', 'extension.xml', '-swc', swcPath] platforms = [ (FlexProjectData.DEFAULT_PLATFORM, 'default', None), (FlexProjectData.ANDROID_PLATFORM, 'Android-ARM', 'jar'), (FlexProjectData.IOS_PLATFORM, 'iPhone-ARM', 'a'), (FlexProjectData.WINDOWS_PLATFORM, 'Windows-x86', None), (FlexProjectData.MAC_PLATFORM, 'MacOS-x86', None)] platformsData = [] for platformDef in platforms: if not sets.setPlatform(platformDef[0]): continue platformFolder = sets.getSetting('FOLDER') platformBuildPath = FileUtils.createPath(buildPath, platformFolder, isDir=True, noTail=True) os.makedirs(platformBuildPath) # LIBRARY.SWF SystemUtils.copy( FileUtils.createPath( sets.projectPath, 'swc', platformFolder, 'extracted', 'library.swf', isFile=True), FileUtils.createPath(platformBuildPath, 'library.swf', isFile=True) ) # NATIVE LIBRARY nativeLibrary = sets.getSetting('NATIVE_LIBRARY') if nativeLibrary: SystemUtils.copy( FileUtils.createPath(sets.projectPath, platformFolder, nativeLibrary, isFile=True), FileUtils.createPath(buildPath, platformFolder, nativeLibrary, isFile=True)) # Android RES folder if platformDef[0] == FlexProjectData.ANDROID_PLATFORM: FileUtils.mergeCopy( FileUtils.createPath(sets.projectPath, platformFolder, 'res', isDir=True), FileUtils.createPath(buildPath, platformFolder, 'res', isDir=True)) cmd.extend(['-platform', platformDef[1]]) optionsPath = FileUtils.createPath( sets.projectPath, platformFolder, 'platform.xml', isFile=True, noTail=True) if os.path.exists(optionsPath): cmd.extend(['-platformoptions', '"%s"' % optionsPath]) cmd.extend(['-C', platformBuildPath, '.']) data = dict( nativeLibrary=nativeLibrary, definition=platformDef, folder=platformFolder, initializer=sets.getSetting('INITIALIZER'), finalizer=sets.getSetting('FINALIZER')) platformsData.append(data) self._createExtensionDescriptor(platformsData) result = self.executeCommand(cmd, 'PACKAGING ANE') # Cleanup deployed library.swf files SystemUtils.remove(buildPath) if result: self._log.write('PACKAGING FAILED') return False self._log.write('PACKAGED SUCCEEDED') return True
def _compileImpl(self): #------------------------------------------------------------------------------------------- # CHECK IF ANDROID PROJECT FILES EXIST createLibrary = False if not os.path.exists(self.getTargetPath('android')): os.makedirs(self.getTargetPath('android')) createLibrary = True if not createLibrary: for item in ['build.xml', 'AndroidManifest.xml']: if not os.path.exists(self.getTargetPath('android', item)): createLibrary = True break #------------------------------------------------------------------------------------------- # CREATE/UPDATE ANDROID PROJECT cmd = ['"%s%s"' % ( self._owner.mainWindow.getAndroidSDKPath('tools', 'android', isFile=True), '.bat' if PyGlassEnvironment.isWindows() else '') ] if createLibrary: messageHeader = 'CREATING ANDROID PROJECT' cmd += [ 'create', 'project', '--activity', self._settings.targetName, '--package', self._settings.ident ] else: messageHeader = 'UPDATING ANDROID PROJECT' cmd += ['update', 'project'] cmd += [ '--target', '"android-%s"' % str(self._settings.androidTargetVersion), '--name', self._settings.targetName, '--path', self.getTargetPath() + 'android' ] if self.executeCommand(cmd, messageHeader): self._log.write('FAILED: ANDROID PROJECT MODIFICATIONS') return False self._log.write('SUCCESS: UPDATE COMPLETE') self._log.write('JDK PATH: ' + self._owner.mainWindow.getJavaJDKPath()) #------------------------------------------------------------------------------------------- # CLEAN PROJECT FOR FRESH COMPILATION batchCmd = [ 'set JAVA_HOME=%s' % self._owner.mainWindow.getJavaJDKPath(), 'cd "%s"' % (self.getTargetPath() + 'android'), 'set errorlevel=', '%s %s' % (self._owner.mainWindow.getJavaAntPath('bin', 'ant.bat'), 'clean') ] if self.executeBatchCommand(batchCmd, messageHeader='CLEANING ANDROID PROJECT'): self._log.write('FAILED: PROJECT CLEANUP') return False self._log.write('SUCCESS: PROJECT CLEANED') #------------------------------------------------------------------------------------------- # COPY SUPPORT LIBRARIES if 'V4_SUPPORT' in self._settings.androidLibIncludes: self._log.write('Including Android V4 Support library...') self._copyV4SupportLib() #------------------------------------------------------------------------------------------- # COMPILE APK libsPath = self.getTargetPath('android', 'libs') if not os.path.exists(libsPath): os.makedirs(libsPath) for item in AndroidCompiler.FLASH_LIBS: shutil.copy2( self.getAirPath('lib', 'android', item), self.getTargetPath('android', 'libs', item) ) batchCmd = [ 'set JAVA_HOME=%s' % self._owner.mainWindow.getJavaJDKPath(), 'cd "%s"' % (self.getTargetPath() + 'android'), 'set errorlevel=', '%s %s' % ( self._owner.mainWindow.getJavaAntPath('bin', 'ant.bat'), 'debug' if self._settings.debug else 'release' ) ] if self.executeBatchCommand(batchCmd, messageHeader='COMPILING ANDROID APK'): self._log.write('FAILED: APK COMPILATION') return False self._log.write('SUCCESS: APK COMPILED') #------------------------------------------------------------------------------------------- # INCLUDE EXTERNAL JAR LIBRARIES libSources = [] libsPath = self.getTargetPath('android', 'libs') ignores = AndroidCompiler.FLASH_LIBS + AndroidCompiler.IGNORE_LIBS for item in os.listdir(libsPath): if item in ignores or not item.endswith('.jar'): continue libSources.append(item) if libSources: libSrcPath = self.getTargetPath('android', 'lib-src') if os.path.exists(libSrcPath): shutil.rmtree(libSrcPath) os.makedirs(libSrcPath) for item in libSources: src = libsPath + item dest = self.getTargetPath('android', 'lib-temp') if os.path.exists(dest): shutil.rmtree(dest) os.makedirs(dest) z = zipfile.ZipFile(src) z.extractall(path=dest) metaInfPath = self.getTargetPath('android', 'lib-temp', 'META-INF') if os.path.exists(metaInfPath): shutil.rmtree(metaInfPath) FileUtils.mergeCopy(dest, libSrcPath) shutil.rmtree(dest) for item in os.listdir(libSrcPath): shutil.copytree( libSrcPath + item, self.getTargetPath('android', 'bin', 'classes') + item ) if os.path.exists(libSrcPath): shutil.rmtree(libSrcPath) #------------------------------------------------------------------------------------------- # CREATE JAR FILE batchCmd = [ 'set JAVA_HOME=%s' % self._owner.mainWindow.getJavaJDKPath(), 'cd "%s"' % self.getTargetPath('android', 'bin'), 'set errorlevel=', '"%s" cvf %s -C %s .' % ( self._owner.mainWindow.getJavaJDKPath('bin', 'jar.exe'), self.getTargetPath('bin', 'android', self._settings.targetName + '.jar'), self.getTargetPath('android', 'bin') + 'classes' ) ] if self.executeBatchCommand(batchCmd, messageHeader='COMPILING ANDROID JAR'): self._log.write('FAILED: JAR COMPILATION') return False self._log.write('SUCCESS: JAR COMPILED') #------------------------------------------------------------------------------------------- # COPY RESOURCES TO BIN binResourcePath = self.getTargetPath('bin', 'android', 'res') if os.path.exists(binResourcePath): shutil.rmtree(binResourcePath) shutil.copytree(self.getTargetPath('android', 'res'), binResourcePath) self._log.write('SUCCESS: RESOURCES DEPLOYED') return True