Beispiel #1
0
    def processAnimations(self):
        """Processes jasyanimation files to merge animation data into asset registry."""

        assets = self.__assets
        configs = [fileId for fileId in assets if assets[fileId].isImageAnimationConfig()]

        if configs:
            Console.info("Processing %s...", Console.colorize("%s animations", "magenta") % len(configs))

        Console.indent()
        for fileId in configs:
            Console.debug("Processing %s...", fileId)

            asset = assets[fileId]
            base = os.path.dirname(fileId)

            try:
                config = asset.getParsedObject()
            except ValueError as err:
                raise UserError("Could not parse jasyanimation at %s: %s" % (fileId, err))

            for relPath in config:
                imageId = "%s/%s" % (base, relPath)
                data = config[relPath]

                if imageId not in assets:
                    raise UserError("Unknown asset %s in %s" % (imageId, fileId))

                animationAsset = assets[imageId]

                if "rows" in data or "columns" in data:
                    rows = Util.getKey(data, "rows", 1)
                    columns = Util.getKey(data, "columns", 1)
                    frames = Util.getKey(data, "frames")

                    animationAsset.addImageAnimationData(columns, rows, frames)

                    if frames is None:
                        frames = rows * columns

                elif "layout" in data:
                    layout = data["layout"]
                    animationAsset.addImageAnimationData(None, None, layout=layout)
                    frames = len(layout)

                else:
                    raise UserError("Invalid image frame data for: %s" % imageId)

                Console.debug("  - Animation %s has %s frames", imageId, frames)

            Console.debug("  - Deleting animation config from assets: %s", fileId)
            del assets[fileId]

        Console.outdent()
Beispiel #2
0
    def setId(self, id):

        super().setId(id)

        self.extension = os.path.splitext(self.id.lower())[1]
        self.type = Util.getKey(AssetExtensions, self.extension, "other")
        self.shortType = self.type[0]
Beispiel #3
0
    def setId(self, id):

        super().setId(id)

        self.extension = os.path.splitext(self.id.lower())[1]
        self.type = Util.getKey(AssetExtensions, self.extension, "other")
        self.shortType = self.type[0]
Beispiel #4
0
    def __getFilteredPages(self, currentItem):
        """Return sorted list of only pages of same language and not hidden."""

        pages = self.__pages
        currentLang = currentItem["lang"]
        pageList = [pageItem for pageItem in pages if pageItem["lang"] == currentLang and not pageItem["status"] == "hidden"]

        return sorted(pageList, key=lambda pageItem: JasyUtil.getKey(pageItem, "pos", 1000000))
Beispiel #5
0
    def getRequires(self,
                    checkoutDirectory="external",
                    updateRepositories=True):
        """
        Return the project requirements as project instances
        """

        global projects

        result = []

        for entry in self.__requires:

            if type(entry) is dict:
                source = entry["source"]
                config = Util.getKey(entry, "config")
                version = Util.getKey(entry, "version")
                kind = Util.getKey(entry, "kind")
            else:
                source = entry
                config = None
                version = None
                kind = None

            # Versions are expected being string type
            if version is not None:
                version = str(version)

            revision = None

            if Repository.isUrl(source):
                kind = kind or Repository.getType(source)
                path = os.path.abspath(
                    os.path.join(checkoutDirectory,
                                 Repository.getTargetFolder(source, version)))

                # Only clone and update when the folder is unique in this session
                # This reduces git/hg/svn calls which are typically quite expensive
                if not path in projects:
                    revision = Repository.update(source, version, path,
                                                 updateRepositories)
                    if revision is None:
                        raise UserError("Could not update repository %s" %
                                        source)

            else:
                kind = "local"
                if not source.startswith(("/", "~")):
                    path = os.path.join(self.__path, source)
                else:
                    path = os.path.abspath(os.path.expanduser(source))

            if path in projects:
                project = projects[path]

            else:
                fullversion = []

                # Produce user readable version when non is defined
                if version is None and revision is not None:
                    version = "master"

                if version is not None:
                    if "/" in version:
                        fullversion.append(version[version.rindex("/") + 1:])
                    else:
                        fullversion.append(version)

                if revision is not None:
                    # Shorten typical long revisions as used by e.g. Git
                    if type(revision) is str and len(revision) > 20:
                        fullversion.append(revision[:10])
                    else:
                        fullversion.append(revision)

                if fullversion:
                    fullversion = "-".join(fullversion)
                else:
                    fullversion = None

                project = Project(path, config, fullversion)
                projects[path] = project

            result.append(project)

        return result
Beispiel #6
0
    def getRequires(self, checkoutDirectory="external", updateRepositories=True):
        """
        Return the project requirements as project instances
        """

        global projects
        
        result = []
        
        for entry in self.__requires:
            
            if type(entry) is dict:
                source = entry["source"]
                config = Util.getKey(entry, "config")
                version = Util.getKey(entry, "version")
                kind = Util.getKey(entry, "kind")
            else:
                source = entry
                config = None
                version = None
                kind = None

            # Versions are expected being string type
            if version is not None:
                version = str(version)

            revision = None
            
            if Repository.isUrl(source):
                kind = kind or Repository.getType(source)
                path = os.path.abspath(os.path.join(checkoutDirectory, Repository.getTargetFolder(source, version)))
                
                # Only clone and update when the folder is unique in this session
                # This reduces git/hg/svn calls which are typically quite expensive
                if not path in projects:
                    revision = Repository.update(source, version, path, updateRepositories)
                    if revision is None:
                        raise UserError("Could not update repository %s" % source)
            
            else:
                kind = "local"
                if not source.startswith(("/", "~")):
                    path = os.path.join(self.__path, source)
                else:
                    path = os.path.abspath(os.path.expanduser(source))

                path = os.path.normpath(path)
            
            if path in projects:
                project = projects[path]
                
            else:
                fullversion = []
                
                # Produce user readable version when non is defined
                if version is None and revision is not None:
                    version = "master"
                
                if version is not None:
                    if "/" in version:
                        fullversion.append(version[version.rindex("/")+1:])
                    else:
                        fullversion.append(version)
                    
                if revision is not None:
                    # Shorten typical long revisions as used by e.g. Git
                    if type(revision) is str and len(revision) > 20:
                        fullversion.append(revision[:10])
                    else:
                        fullversion.append(revision)
                        
                if fullversion:
                    fullversion = "-".join(fullversion)
                else:
                    fullversion = None

                project = Project(path, config, fullversion)
                projects[path] = project
            
            result.append(project)
        
        return result
Beispiel #7
0
    def processAnimations(self):
        """Processes jasyanimation files to merge animation data into asset registry."""

        assets = self.__assets
        configs = [
            fileId for fileId in assets
            if assets[fileId].isImageAnimationConfig()
        ]

        if configs:
            Console.info(
                "Processing %s...",
                Console.colorize("%s animations", "magenta") % len(configs))

        Console.indent()
        for fileId in configs:
            Console.debug("Processing %s...", fileId)

            asset = assets[fileId]
            base = os.path.dirname(fileId)

            try:
                config = asset.getParsedObject()
            except ValueError as err:
                raise UserError("Could not parse jasyanimation at %s: %s" %
                                (fileId, err))

            for relPath in config:
                imageId = "%s/%s" % (base, relPath)
                data = config[relPath]

                if imageId not in assets:
                    raise UserError("Unknown asset %s in %s" %
                                    (imageId, fileId))

                animationAsset = assets[imageId]

                if "rows" in data or "columns" in data:
                    rows = Util.getKey(data, "rows", 1)
                    columns = Util.getKey(data, "columns", 1)
                    frames = Util.getKey(data, "frames")

                    animationAsset.addImageAnimationData(columns, rows, frames)

                    if frames is None:
                        frames = rows * columns

                elif "layout" in data:
                    layout = data["layout"]
                    animationAsset.addImageAnimationData(None,
                                                         None,
                                                         layout=layout)
                    frames = len(layout)

                else:
                    raise UserError("Invalid image frame data for: %s" %
                                    imageId)

                Console.debug("  - Animation %s has %s frames", imageId,
                              frames)

            Console.debug("  - Deleting animation config from assets: %s",
                          fileId)
            del assets[fileId]

        Console.outdent()