def _computeResourceUri(self, lib, resourcePath, rType="class", appRoot=None):
        '''computes a complete resource URI for the given resource type rType, 
           from the information given in lib and, if lib doesn't provide a
           general uri prefix for it, use appRoot and lib path to construct
           one'''

        if 'uri' in lib:
            libBaseUri = OsPath(lib['uri'])
        elif appRoot:
            libBaseUri = OsPath(Path.rel_from_to(self._config.absPath(appRoot), lib['path']))
        else:
            raise RuntimeError, "Need either lib['uri'] or appRoot, to calculate final URI"
        libBaseUri = Uri(libBaseUri.toUri())

        if rType in lib:
            libInternalPath = OsPath(lib[rType])
        else:
            raise RuntimeError, "No such resource type: \"%s\"" % rType

        # process the second part of the target uri
        uri = libInternalPath.join(resourcePath)
        uri = Uri(uri.toUri())

        libBaseUri.ensureTrailingSlash()
        uri = libBaseUri.join(uri)

        return uri
Esempio n. 2
0
        def packageUrisToJS(packages, version):

            allUris = []
            for packageId, package in enumerate(packages):
                packageUris = []
                if package.file: # build
                    namespace = "__out__"
                    fileId    = package.file
                    relpath    = OsPath(fileId)
                    shortUri   = Uri(relpath.toUri())
                    entry      = "%s:%s" % (namespace, shortUri.encodedValue())
                    packageUris.append(entry)
                    package.files.append(entry)  # TODO: make package.file obsolete
                elif package.files:  # hybrid
                    packageUris = package.files
                else: # "source" :
                    for clazz in package.classes:
                        namespace  = self._classes[clazz].library.namespace
                        relpath    = OsPath(self._classes[clazz].relpath)
                        shortUri   = Uri(relpath.toUri())
                        entry      = "%s:%s" % (namespace, shortUri.encodedValue())
                        packageUris.append(entry)
                        package.files.append(entry)  # TODO: this should done be elsewhere?!
                allUris.append(packageUris)

            return allUris
Esempio n. 3
0
    def _computeResourceUri(self, lib, resourcePath, rType="class", appRoot=None):
        '''computes a complete resource URI for the given resource type rType, 
           from the information given in lib and, if lib doesn't provide a
           general uri prefix for it, use appRoot and lib path to construct
           one'''

        if 'uri' in lib:
            libBaseUri = Uri(lib['uri'])
        elif appRoot:
            libBaseUri = Uri(Path.rel_from_to(self._config.absPath(appRoot), lib['path']))
        else:
            raise RuntimeError, "Need either lib['uri'] or appRoot, to calculate final URI"
        #libBaseUri = Uri(libBaseUri.toUri())

        if rType in lib:
            libInternalPath = OsPath(lib[rType])
        else:
            raise RuntimeError, "No such resource type: \"%s\"" % rType

        # process the second part of the target uri
        uri = libInternalPath.join(resourcePath)
        uri = Uri(uri.toUri())

        libBaseUri.ensureTrailingSlash()
        uri = libBaseUri.join(uri)

        return uri
Esempio n. 4
0
        def packageUrisToJS1(packages, version, namespace=None):
            # Translate URI data to JavaScript
            # using Package objects

            if version == "build" and not namespace:
                # TODO: gosh, the next is an ugly hack!  
                # all name spaces point to the same paths in the libinfo struct, so any of them will do
                #namespace  = self._resourceHandler._genobj._namespaces[0]
                namespace  = self.getAppName()
            
            allUris = []
            for packageId, package in enumerate(packages):
                packageUris = []
                if package.file:
                    namespace = "__out__"
                    fileId    = package.file
                    relpath    = OsPath(fileId)
                    shortUri   = Uri(relpath.toUri())
                    packageUris.append("%s:%s" % (namespace, shortUri.encodedValue()))
                else: # "source" :
                    for clazz in package.classes:
                        namespace  = self._classes[clazz]["namespace"]
                        relpath    = OsPath(self._classes[clazz]["relpath"])
                        shortUri   = Uri(relpath.toUri())
                        packageUris.append("%s:%s" % (namespace, shortUri.encodedValue()))


                allUris.append(packageUris)
            return allUris
            def compileAndAdd(compiledClasses, packageUris):
                compiled = compileClasses(compiledClasses, compOptions)
                filename = compiledFilename(compiled)
                self.writePackage(compiled, filename, script)
                filename = OsPath(os.path.basename(filename))
                shortUri = Uri(filename.toUri())
                packageUris.append("%s:%s" % ("__out__", shortUri.encodedValue()))

                return packageUris
Esempio n. 6
0
            def compileAndAdd(compiledClasses, packageUris):
                compiled = compileClasses(compiledClasses, compOptions)
                filename = compiledFilename(compiled)
                self.writePackage(compiled, filename, script)
                filename = OsPath(os.path.basename(filename))
                shortUri = Uri(filename.toUri())
                packageUris.append("%s:%s" %
                                   ("__out__", shortUri.encodedValue()))

                return packageUris
Esempio n. 7
0
    def _computeResourceUri(self, lib, resourcePath, rType="class", appRoot=None):

        if 'uri' in lib:
            libBaseUri = Uri(lib['uri'])
        elif appRoot:
            libBaseUri = Uri(Path.rel_from_to(self._config.absPath(appRoot), lib['path']))
        else:
            raise RuntimeError, "Need either lib['uri'] or appRoot, to calculate final URI"
        #libBaseUri = Uri(libBaseUri.toUri())

        if rType in lib:
            libInternalPath = OsPath(lib[rType])
        else:
            raise RuntimeError, "No such resource type: \"%s\"" % rType

        # process the second part of the target uri
        uri = libInternalPath.join(resourcePath)
        uri = Uri(uri.toUri())

        libBaseUri.ensureTrailingSlash()
        uri = libBaseUri.join(uri)
        # strip dangling "/", e.g. when we have no resourcePath
        uri.ensureNoTrailingSlash()

        return uri
Esempio n. 8
0
        def compileAndWritePackage(package, compConf):
            def compiledFilename(compiled):
                hash_ = sha.getHash(compiled)[:12]
                fname = self._fileNameWithHash(script.baseScriptPath, hash_)
                return fname

            def compileAndAdd(compiledClasses, packageUris):
                compiled = compileClasses(compiledClasses, compOptions)
                filename = compiledFilename(compiled)
                self.writePackage(compiled, filename, script)
                filename = OsPath(os.path.basename(filename))
                shortUri = Uri(filename.toUri())
                packageUris.append("%s:%s" %
                                   ("__out__", shortUri.encodedValue()))

                return packageUris

            # ------------------------------------
            packageUris = []
            compiledClasses = []
            optimize = compConf.get("code/optimize", [])
            sourceFilter = ClassMatchList(compConf.get("code/except", []))
            compOptions = CompileOptions(optimize=optimize)

            ##
            # This somewhat overlaps with packageUrisToJS
            package_classes = [
                y for x in package.classes for y in script.classesObj
                if y.id == x
            ]  # TODO: i need to make package.classes [Class]!
            for clazz in package_classes:
                if sourceFilter.match(clazz.id):
                    if compiledClasses:
                        # treat compiled classes so far
                        packageUris = compileAndAdd(compiledClasses,
                                                    packageUris)
                        compiledClasses = []  # reset the collection
                    # for a source class, just include the file uri
                    clazzRelpath = clazz.id.replace(".", "/") + ".js"
                    relpath = OsPath(clazzRelpath)
                    shortUri = Uri(relpath.toUri())
                    packageUris.append(
                        "%s:%s" %
                        (clazz.library.namespace, shortUri.encodedValue()))
                else:
                    compiledClasses.append(clazz)
            else:
                # treat remaining to-be-compiled classes
                if compiledClasses:
                    packageUris = compileAndAdd(compiledClasses, packageUris)

            package.files = packageUris

            return package
Esempio n. 9
0
            def compileAndAdd(compiledClasses, packageUris, prelude='', wrap=''):
                compiled = compileClasses(compiledClasses, compOptions, log_progress)
                if wrap:
                    compiled = wrap % compiled
                if prelude:
                    compiled = prelude + compiled
                filename = compiledFilename(compiled)
                self.writePackage(compiled, filename, script)
                filename = OsPath(os.path.basename(filename))
                shortUri = Uri(filename.toUri())
                entry = "%s:%s" % ("__out__", shortUri.encodedValue())
                packageUris.append(entry)

                return packageUris
        def compileAndWritePackage(package, compConf):

            def compiledFilename(compiled):
                hash_ = sha.getHash(compiled)[:12]
                fname = self._fileNameWithHash(script.baseScriptPath, hash_)
                return fname

            def compileAndAdd(compiledClasses, packageUris):
                compiled = compileClasses(compiledClasses, compOptions)
                filename = compiledFilename(compiled)
                self.writePackage(compiled, filename, script)
                filename = OsPath(os.path.basename(filename))
                shortUri = Uri(filename.toUri())
                packageUris.append("%s:%s" % ("__out__", shortUri.encodedValue()))

                return packageUris

            # ------------------------------------
            packageUris = []
            compiledClasses = []
            optimize = compConf.get("code/optimize", [])
            sourceFilter = ClassMatchList(compConf.get("code/except", []))
            compOptions  = CompileOptions(optimize=optimize)

            ##
            # This somewhat overlaps with packageUrisToJS
            package_classes = [y for x in package.classes for y in script.classesObj if y.id == x] # TODO: i need to make package.classes [Class]!
            for clazz in package_classes:
                if sourceFilter.match(clazz.id):
                    if compiledClasses:
                        # treat compiled classes so far
                        packageUris = compileAndAdd(compiledClasses, packageUris)
                        compiledClasses = []  # reset the collection
                    # for a source class, just include the file uri
                    clazzRelpath = clazz.id.replace(".", "/") + ".js"
                    relpath  = OsPath(clazzRelpath)
                    shortUri = Uri(relpath.toUri())
                    packageUris.append("%s:%s" % (clazz.library.namespace, shortUri.encodedValue()))
                else:
                    compiledClasses.append(clazz)
            else:
                # treat remaining to-be-compiled classes
                if compiledClasses:
                    packageUris = compileAndAdd(compiledClasses, packageUris)

            package.files = packageUris

            return package
Esempio n. 11
0
            def packageUrisToJS(packages, version):

                allUris = []
                for packageId, package in enumerate(packages):
                    packageUris = []
                    if package.file: # build
                        namespace = "__out__"
                        fileId    = package.file
                        relpath    = OsPath(fileId)
                        shortUri   = Uri(relpath.toUri())
                        packageUris.append("%s:%s" % (namespace, shortUri.encodedValue()))
                    else: # "source" :
                        for clazz in package.classes:
                            namespace  = self._classes[clazz]["namespace"]
                            relpath    = OsPath(self._classes[clazz]["relpath"])
                            shortUri   = Uri(relpath.toUri())
                            packageUris.append("%s:%s" % (namespace, shortUri.encodedValue()))
                    allUris.append(packageUris)

                return allUris
Esempio n. 12
0
            def packageUrisToJS1(packages, version, namespace=None):
                # Translate URI data to JavaScript
                
                allUris = []
                for packageId, package in enumerate(packages):
                    packageUris = []
                    for fileId in package:

                        if version == "build":
                            # TODO: gosh, the next is an ugly hack!
                            #namespace  = self._resourceHandler._genobj._namespaces[0]  # all name spaces point to the same paths in the libinfo struct, so any of them will do
                            if not namespace:
                                namespace  = script.namespace  # all name spaces point to the same paths in the libinfo struct, so any of them will do
                            relpath    = OsPath(fileId)
                        else:
                            namespace  = self._classes[fileId]["namespace"]
                            relpath    = OsPath(self._classes[fileId]["relpath"])

                        shortUri = Uri(relpath.toUri())
                        packageUris.append("%s:%s" % (namespace, shortUri.encodedValue()))
                    allUris.append(packageUris)

                return allUris
Esempio n. 13
0
            def packageUrisToJS1(packages, version, namespace=None):
                # Translate URI data to JavaScript
                
                allUris = []
                for packageId, package in enumerate(packages):
                    packageUris = []
                    for fileId in package:

                        if version == "build":
                            # TODO: gosh, the next is an ugly hack!
                            #namespace  = self._resourceHandler._genobj._namespaces[0]  # all name spaces point to the same paths in the libinfo struct, so any of them will do
                            if not namespace:
                                namespace  = script.namespace  # all name spaces point to the same paths in the libinfo struct, so any of them will do
                            relpath    = OsPath(fileId)
                        else:
                            namespace  = self._classes[fileId]["namespace"]
                            relpath    = OsPath(self._classes[fileId]["relpath"])

                        shortUri = Uri(relpath.toUri())
                        packageUris.append("%s:%s" % (namespace, shortUri.encodedValue()))
                    allUris.append(packageUris)

                return allUris
Esempio n. 14
0
    def _computeResourceUri(self, lib_, resourcePath, rType="class", appRoot=None):

        # i still use dict-type lib representation to create _output_ pseudo-lib
        if isinstance(lib_, generator.resource.Library.Library):
            lib = {
                'class' : lib_.classPath,
                'uri'   : lib_.uri,
                'path'  : lib_.path,
                'resource' : lib_.resourcePath,
            }
        else:
            lib = lib_

        if 'uri' in lib and lib['uri'] is not None:
            libBaseUri = Uri(lib['uri'])
        elif appRoot:
            libBaseUri = Uri(Path.rel_from_to(self._config.absPath(appRoot), lib['path']))
        else:
            raise RuntimeError, "Need either lib.uri or appRoot, to calculate final URI"
        #libBaseUri = Uri(libBaseUri.toUri())

        if rType in lib:
            libInternalPath = OsPath(lib[rType])
        else:
            raise RuntimeError, "No such resource type: \"%s\"" % rType

        # process the second part of the target uri
        uri = libInternalPath.join(resourcePath)
        uri = Uri(uri.toUri())

        libBaseUri.ensureTrailingSlash()
        uri = libBaseUri.join(uri)
        # strip dangling "/", e.g. when we have no resourcePath
        uri.ensureNoTrailingSlash()

        return uri
Esempio n. 15
0
            def packageUrisToJS(packages, version):

                allUris = []
                for packageId, package in enumerate(packages):
                    packageUris = []
                    if package.file: # build
                        namespace = "__out__"
                        fileId    = package.file
                        relpath    = OsPath(fileId)
                        shortUri   = Uri(relpath.toUri())
                        packageUris.append("%s:%s" % (namespace, shortUri.encodedValue()))
                    else: # "source" :
                        for clazz in package.classes:
                            namespace  = self._classes[clazz]["namespace"]
                            relpath    = OsPath(self._classes[clazz]["relpath"])
                            shortUri   = Uri(relpath.toUri())
                            packageUris.append("%s:%s" % (namespace, shortUri.encodedValue()))
                    allUris.append(packageUris)

                return allUris
Esempio n. 16
0
        def compileAndWritePackage(package, compConf, allClassVariants):

            def compiledFilename(compiled):
                hash_ = sha.getHash(compiled)[:12]
                fname = self._resolveFileName(script.baseScriptPath, script.variants, {}, "")
                fname = self._fileNameWithHash(fname, hash_)
                return fname

            def compileAndAdd(compiledClasses, packageUris, prelude='', wrap=''):
                compiled = compileClasses(compiledClasses, compOptions, log_progress)
                if wrap:
                    compiled = wrap % compiled
                if prelude:
                    compiled = prelude + compiled
                filename = compiledFilename(compiled)
                self.writePackage(compiled, filename, script)
                filename = OsPath(os.path.basename(filename))
                shortUri = Uri(filename.toUri())
                entry = "%s:%s" % ("__out__", shortUri.encodedValue())
                packageUris.append(entry)

                return packageUris

            # ------------------------------------
            packageUris = []
            optimize = compConf.get("code/optimize", [])
            format_   = compConf.get("code/format", False)
            variantSet= script.variants
            sourceFilter = ClassMatchList(compConf.get("code/except", []))
            compOptions  = CompileOptions(optimize=optimize, variants=variantSet, _format=format_)
            compOptions.allClassVariants = allClassVariants

            ##
            # This somewhat overlaps with packageUrisToJS
            compiledClasses = []
            packageData = getPackageData(package)
            packageData = ("qx.$$packageData['%s']=" % package.id) + packageData
            package_classes = [y for x in package.classes for y in script.classesObj if y.id == x] # TODO: i need to make package.classes [Class]!

            #self._console.info("Package #%s:" % package.id, feed=False)
            len_pack_classes = len(package_classes)
            # helper log function, to log progress here, but also in compileClasses()
            def log_progress(c=[0]):
                c[0]+=1
                #self._console.progress(c[0],len_pack_classes)
                self._console.dot()

            for pos,clazz in enumerate(package_classes):
                if sourceFilter.match(clazz.id):
                    package.has_source = True
                    if packageData or compiledClasses:
                        # treat compiled classes so far
                        packageUris = compileAndAdd(compiledClasses, packageUris, packageData)
                        compiledClasses = []  # reset the collection
                        packageData = ""
                    # for a source class, just include the file uri
                    clazzRelpath = clazz.id.replace(".", "/") + ".js"
                    relpath  = OsPath(clazzRelpath)
                    shortUri = Uri(relpath.toUri())
                    entry    = "%s:%s" % (clazz.library.namespace, shortUri.encodedValue())
                    packageUris.append(entry)
                    log_progress()
                else:
                    compiledClasses.append(clazz)
            else:
                # treat remaining to-be-compiled classes
                if compiledClasses:
                    closureWrap = ''
                    if isClosurePackage(package, bootPackageId(script)):
                        closureWrap = u'''qx.Part.$$notifyLoad("%s", function() {\n%%s\n});''' % package.id
                    packageUris = compileAndAdd(compiledClasses, packageUris, packageData, closureWrap)

            package.files = packageUris
            return package