def patchLibEntry(self, libentry): libinfo = self._manifest['info'] libprovides = self._manifest['provides'] #uriprefix = libentry['uri'] uriprefix = "" libentry['class'] = os.path.join(uriprefix,libprovides['class']) libentry['resource'] = os.path.join(uriprefix,libprovides['resource']) libentry['translation'] = os.path.join(uriprefix,libprovides['translation']) if 'translation' in libprovides: libentry['translation'] = os.path.join(uriprefix,libprovides['translation']) libentry['encoding'] = libprovides['encoding'] if 'namespace' in libentry: if libentry['namespace'] != libprovides['namespace']: raise ConfigurationError("Mismatch between Manifest namespace and directory namespaces") else: libentry['namespace'] = libprovides['namespace'] libentry['type'] = libprovides['type'] libentry['path'] = os.path.dirname(libentry['manifest']) or '.' # from the 'info' section if 'version' in libinfo: libentry['version'] = libinfo['version'] if 'qooxdoo-versions' in libinfo: libentry['qooxdoo-versions'] = libinfo['qooxdoo-versions'] if 'sourceViewUri' in libinfo: libentry['sourceViewUri'] = libinfo['sourceViewUri'] return libentry
def combineImgMagick(self, clips, combined, orientation): montage_cmd = self._job.get("combine-images/montage-cmd", "") if not montage_cmd: raise ConfigurationError( "You need to specify a command template for the \"montage\" command (in combine-images/montage-cmd)" ) (fileDescriptor, tempPath) = tempfile.mkstemp(text=True, dir=os.curdir) temp = os.fdopen(fileDescriptor, "w") temp.write("\n".join(clips)) temp.close() cmd = montage_cmd % { "orientation": orientation, "tempfile": os.path.basename(tempPath), "combinedfile": combined } print cmd rc = os.system(cmd) os.unlink(tempPath) if rc != 0: raise RuntimeError, "The montage command (%s) failed with the following return code: %d" % ( cmd, rc)
def raiseConfigError(self, basemsg): msg = basemsg if self._fname: msg += " (%s)" % self._fname raise ConfigurationError(msg)
def _scanClassPath(self, timeOfLastScan=0): codeIdFromTree = True # switch between regex- and tree-based codeId search # Check class path classPath = os.path.join(self.path, self.classPath) if not os.path.isdir(classPath): raise ConfigurationError( "Class path from Manifest doesn't exist: %s" % self.classPath) # Check multiple namespaces if not len([d for d in os.listdir(classPath) if not d.startswith(".") ]) == 1: self._console.warn( "The class path must contain exactly one namespace; ignoring everything else: '%s'" % (classPath, )) # Check Manifest namespace matches file system nsPrefix = self.namespace.replace(".", os.sep) classNSRoot = os.path.join(classPath, nsPrefix) if not os.path.isdir(classNSRoot): raise ValueError( "Manifest namespace does not exist on file system: '%s'" % (classNSRoot)) self._console.debug("Scanning class folder...") classList = [] existClassIds = dict([(x.id, x) for x in self._classes]) # if we scanned before docs = {} # TODO: Clazz still relies on a context dict! contextdict = {} contextdict["console"] = context.console contextdict["cache"] = context.cache contextdict["jobconf"] = context.jobconf contextdict["envchecksmap"] = {} # Iterate... for root, dirs, files in filetool.walk(classNSRoot): # Filter ignored directories for ignoredDir in dirs: if self._ignoredDirEntries.match(ignoredDir): dirs.remove(ignoredDir) # Add good directories currNameSpace = root[len(classNSRoot + os.sep):] currNameSpace = currNameSpace.replace(os.sep, ".") # TODO: var name # Searching for files for fileName in files: # Ignore dot files if fileName.startswith(".") or self._ignoredDirEntries.match( fileName): continue self._console.dot() # Process path data filePath = os.path.join(root, fileName) fileRel = filePath.replace( classNSRoot + os.sep, "") # now only path fragment *afte* NS fileExt = os.path.splitext(fileName)[-1] fileStat = os.stat(filePath) fileSize = fileStat.st_size fileMTime = fileStat.st_mtime # Compute full URI from relative path fileUri = self.classUri + "/" + fileRel.replace(os.sep, "/") # Compute identifier from relative path filePathId = fileRel.replace(fileExt, "").replace(os.sep, ".") filePathId = self.namespace + "." + filePathId # e.g. "qx.core.Environment" filePathId = unidata.normalize( "NFC", filePathId) # combine combining chars: o" -> ö fileId = nsPrefix + "/" + fileRel # e.g. "qx/core/Environment.js" # check if known and fresh if (filePathId in existClassIds and fileMTime < timeOfLastScan): classList.append(existClassIds[filePathId]) #print "re-using existing", filePathId continue # re-use known class # Extract package ID filePackage = filePathId[:filePathId.rfind(".")] # Handle doc files if fileName == self._docFilename: fileFor = filePathId[:filePathId.rfind(".")] docs[filePackage] = { "relpath": fileId, "path": filePath, "encoding": self.encoding, "namespace": self.namespace, "id": filePathId, "package": filePackage, "size": fileSize } # Stop further processing continue # Ignore non-script if os.path.splitext(fileName)[-1] != ".js": continue if filePathId == "qx.core.Environment": clazz = qcEnvClass(filePathId, filePath, self, contextdict) else: clazz = Class(filePathId, filePath, self, contextdict) # Extract code ID (e.g. class name, mixin name, ...) try: if codeIdFromTree: fileCodeId = self._getCodeId(clazz) else: # Read content fileContent = filetool.read(filePath, self.encoding) fileCodeId = self._getCodeId1(fileContent) except ValueError, e: argsList = [] for arg in e.args: argsList.append(arg) argsList[0] = argsList[0] + u' (%s)' % fileName e.args = tuple(argsList) raise e # Ignore all data files (e.g. translation, doc files, ...) if fileCodeId == None: continue # Compare path and content if fileCodeId != filePathId: self._console.error( "Detected conflict between filename and classname!") self._console.indent() self._console.error("Classname: %s" % fileCodeId) self._console.error("Path: %s" % filePath) self._console.outdent() raise RuntimeError() # Store file data self._console.debug("Adding class %s" % filePathId) clazz.encoding = self.encoding clazz.size = fileSize # dependency logging uses this clazz.package = filePackage # Apiloader uses this clazz.relpath = fileId # Locale uses this clazz.m_time_ = fileStat.st_mtime classList.append(clazz)
def slice(self, source, dest_prefix, border, trim_width): #convert_cmd = "convert %s -crop %sx%s+%s+%s +repage %s" #convert_cmd = "convert %(infile)s -crop %(xoff)sx%(yoff)s+%(xorig)s+%(yorig)s +repage %(outfile)s" convert_cmd = self._job.get("slice-images/convert-cmd", "") if not convert_cmd: raise ConfigurationError( "You need to specify a command template for the \"convert\" command (in slice-images/convert-cmd)" ) source_file = source dest_file = os.path.join(os.path.dirname(source), dest_prefix) imginf = Image(source_file).getInfoMap() width, height = imginf['width'], imginf['height'] if isinstance(border, int): single_border = True elif not isinstance(border, list) or (isinstance(border, list) and not (len(border) == 4)): raise RuntimeError, "Border must be one integer or an array with four integers" else: single_border = False # Split borders and corners from source image # Single width for all borders if single_border: # top-left corner #os.system(convert_cmd % (source_file, border, border, 0, 0, dest_file + "-tl.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-tl.png", 'xoff': border, 'yoff': border, 'xorig': 0, 'yorig': 0, }) # top border #os.system(convert_cmd % (source_file, border, border, border, 0, dest_file + "-t.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-t.png", 'xoff': border, 'yoff': border, 'xorig': border, 'yorig': 0, }) # top-right corner #os.system(convert_cmd % (source_file, border, border, width-border, 0, dest_file + "-tr.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-tr.png", 'xoff': border, 'yoff': border, 'xorig': width - border, 'yorig': 0, }) # left border #os.system(convert_cmd % (source_file, border, height-2*border, 0, border, dest_file + "-l.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-l.png", 'xoff': border, 'yoff': height - 2 * border, 'xorig': 0, 'yorig': border, }) # center piece if trim_width: #os.system(convert_cmd % (source_file, min(20, width-2*border), height-2*border, border, border, dest_file + "-c.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-c.png", 'xoff': min(20, width - 2 * border), 'yoff': height - 2 * border, 'xorig': border, 'yorig': border, }) else: #os.system(convert_cmd % (source_file, width-2*border, height-2*border, border, border, dest_file + "-c.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-c.png", 'xoff': width - 2 * border, 'yoff': height - 2 * border, 'xorig': border, 'yorig': border, }) # right border #os.system(convert_cmd % (source_file, border, height-2*border, width-border, border, dest_file + "-r.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-r.png", 'xoff': border, 'yoff': height - 2 * border, 'xorig': width - border, 'yorig': border, }) # bottom-left corner #os.system(convert_cmd % (source_file, border, border, 0, height-border, dest_file + "-bl.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-bl.png", 'xoff': border, 'yoff': border, 'xorig': 0, 'yorig': height - border, }) # bottom border #os.system(convert_cmd % (source_file, border, border, border, height-border, dest_file + "-b.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-b.png", 'xoff': border, 'yoff': border, 'xorig': border, 'yorig': height - border, }) # bottom-right corner #os.system(convert_cmd % (source_file, border, border, width-border, height-border, dest_file + "-br.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-br.png", 'xoff': border, 'yoff': border, 'xorig': width - border, 'yorig': height - border, }) # Individual borders else: if border[0] > 0 and border[3] > 0: # top-left corner #os.system(convert_cmd % (source_file, border[3], border[0], 0, 0, dest_file + "-tl.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-tl.png", 'xoff': border[3], 'yoff': border[0], 'xorig': 0, 'yorig': 0, }) if border[0] > 0: # top border #os.system(convert_cmd % (source_file, width - border[3] - border[1], border[0], border[3], 0, dest_file + "-t.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-t.png", 'xoff': width - border[3] - border[1], 'yoff': border[0], 'xorig': border[3], 'yorig': 0, }) if border[0] > 0 and border[1] > 0: # top-right corner #os.system(convert_cmd % (source_file, border[1], border[0], width - border[1], 0, dest_file + "-tr.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-tr.png", 'xoff': border[1], 'yoff': border[0], 'xorig': width - border[1], 'yorig': 0, }) if border[3] > 0: # left border #os.system(convert_cmd % (source_file, border[3], height - border[0] - border[2], 0, border[0], dest_file + "-l.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-l.png", 'xoff': border[3], 'yoff': height - border[0] - border[2], 'xorig': 0, 'yorig': border[0], }) # center piece if trim_width: #os.system(convert_cmd % (source_file, min(20, width- border[3] - border[1]), height - border[0] - border[2], border[3], border[0], dest_file + "-c.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-c.png", 'xoff': min(20, width - border[3] - border[1]), 'yoff': height - border[0] - border[2], 'xorig': border[3], 'yorig': border[0], }) else: #os.system(convert_cmd % (source_file, width- border[3] - border[1], height - border[0] - border[2], border[3], border[0], dest_file + "-c.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-c.png", 'xoff': width - border[3] - border[1], 'yoff': height - border[0] - border[2], 'xorig': border[3], 'yorig': border[0], }) if border[1] > 0: # right border #os.system(convert_cmd % (source_file, border[1], height - border[0] - border[2], width - border[1], border[0], dest_file + "-r.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-r.png", 'xoff': border[1], 'yoff': height - border[0] - border[2], 'xorig': width - border[1], 'yorig': border[0], }) if border[2] > 0 and border[3] > 0: # bottom-left corner #os.system(convert_cmd % (source_file, border[3], border[2], 0, height - border[2], dest_file + "-bl.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-bl.png", 'xoff': border[3], 'yoff': border[2], 'xorig': 0, 'yorig': height - border[2], }) if border[2] > 0: # bottom border #os.system(convert_cmd % (source_file, width- border[3] - border[1], border[2], border[3], height - border[2], dest_file + "-b.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-b.png", 'xoff': width - border[3] - border[1], 'yoff': border[2], 'xorig': border[3], 'yorig': height - border[2], }) if border[2] > 0 and border[1] > 0: # bottom-right corner #os.system(convert_cmd % (source_file, border[1], border[2], width - border[1], height - border[2], dest_file + "-br.png")) os.system( convert_cmd % { 'infile': source_file, 'outfile': dest_file + "-br.png", 'xoff': border[1], 'yoff': border[2], 'xorig': width - border[1], 'yorig': height - border[2], }) # for css3, the original images are used shutil.copyfile(source_file, dest_file + ".png")
def check_class_path(classRoot): if not os.path.isdir(classRoot): raise ConfigurationError( "Class path from Manifest doesn't exist: %s" % self.classPath)