Ejemplo n.º 1
0
    def test_write_yaml(self):

        tempDirectory = tempfile.TemporaryDirectory().name
        os.makedirs(tempDirectory)

        Config.writeConfig([{"one": 1,"two": 2},{"three": 3,"four": 4}], os.path.join(tempDirectory, "test.yaml"))
        
        self.assertEqual(Config.findConfig(os.path.join(tempDirectory, "test.yaml")), os.path.join(tempDirectory, "test.yaml"))        
Ejemplo n.º 2
0
    def test_write_and_read_json(self):

        tempDirectory = tempfile.TemporaryDirectory().name
        os.makedirs(tempDirectory)

        Config.writeConfig([{"one": 10-9,"two": 5-3},{"three": 1+1+1,"four": 2*2}], os.path.join(tempDirectory, "test.yaml"))
        data = Config.loadConfig(os.path.join(tempDirectory, "test.yaml"))

        self.assertEqual(data, [{'two': 2, 'one': 1}, {'four': 4, 'three': 3}]) 
Ejemplo n.º 3
0
    def test_write_and_read_yaml(self):

        tempDirectory = tempfile.TemporaryDirectory().name
        os.makedirs(tempDirectory)

        Config.writeConfig([{
            "one": 10 - 9,
            "two": 5 - 3
        }, {
            "three": 1 + 1 + 1,
            "four": 2 * 2
        }], os.path.join(tempDirectory, "test.yaml"))
        data = Config.loadConfig(os.path.join(tempDirectory, "test.yaml"))

        self.assertEqual(data, [{'two': 2, 'one': 1}, {'four': 4, 'three': 3}])
Ejemplo n.º 4
0
    def test_write_yaml(self):

        tempDirectory = tempfile.TemporaryDirectory().name
        os.makedirs(tempDirectory)

        Config.writeConfig([{
            "one": 1,
            "two": 2
        }, {
            "three": 3,
            "four": 4
        }], os.path.join(tempDirectory, "test.yaml"))

        self.assertEqual(
            Config.findConfig(os.path.join(tempDirectory, "test.yaml")),
            os.path.join(tempDirectory, "test.yaml"))
Ejemplo n.º 5
0
    def test_matching_types(self):

        self.assertTrue(Config.matchesType(42, "int"))
        self.assertTrue(Config.matchesType(11.0, "float"))
        self.assertTrue(Config.matchesType(11.1, "float"))
        self.assertTrue(Config.matchesType("hello", "string"))
        self.assertTrue(Config.matchesType(False, "bool"))
        self.assertTrue(Config.matchesType([{"one": 10-9,"two": 5-3},{"three": 1+1+1,"four": 2*2}], "list"))
        self.assertTrue(Config.matchesType({"one": 10-9,"two": 5-3}, "dict"))
Ejemplo n.º 6
0
    def init(self, autoInitialize=True, updateRepositories=True, scriptEnvironment=None):
        """
        Initialize the actual session with projects.

        :param autoInitialize: Whether the projects should be automatically added when the current folder contains a valid Jasy project.
        :param updateRepositories: Whether to update repositories of all project dependencies.
        :param scriptEnvironment: API object as being used for loadLibrary to add Python features offered by projects.
        :param commandEnvironment: API object as being used for loadCommands to add Python features for any item nodes.

        """

        self.__scriptEnvironment = scriptEnvironment
        self.__updateRepositories = updateRepositories

        if autoInitialize and Config.findConfig("jasyproject"):

            Console.info("Initializing session...")
            Console.indent()

            try:
                self.addProject(Project.getProjectFromPath(".", self))

            except UserError as err:
                Console.outdent(True)
                Console.error(err)
                raise UserError("Critical: Could not initialize session!")

            self.getVirtualProject()

            Console.debug("Active projects (%s):", len(self.__projects))
            Console.indent()

            for project in self.__projects:
                if project.version:
                    Console.debug("%s @ %s", Console.colorize(project.getName(), "bold"), Console.colorize(project.version, "magenta"))
                else:
                    Console.debug(Console.colorize(project.getName(), "bold"))

            Console.outdent()
            Console.outdent()
Ejemplo n.º 7
0
    def test_matching_types(self):

        self.assertTrue(Config.matchesType(42, "int"))
        self.assertTrue(Config.matchesType(11.0, "float"))
        self.assertTrue(Config.matchesType(11.1, "float"))
        self.assertTrue(Config.matchesType("hello", "string"))
        self.assertTrue(Config.matchesType(False, "bool"))
        self.assertTrue(
            Config.matchesType([{
                "one": 10 - 9,
                "two": 5 - 3
            }, {
                "three": 1 + 1 + 1,
                "four": 2 * 2
            }], "list"))
        self.assertTrue(
            Config.matchesType({
                "one": 10 - 9,
                "two": 5 - 3
            }, "dict"))
Ejemplo n.º 8
0
    def test_config_object_setdata_withdot(self):

        config = Config.Config({'foo': {'yeah': 42}, 'one': 1})
        config.set('foo.yeah', 1337)
        self.assertEqual(config.get('foo')['yeah'], 1337)
Ejemplo n.º 9
0
    def test_config_object_getdata_withdot(self):

        config = Config.Config({'foo': {'yeah': 42}, 'one': 1})
        self.assertEqual(config.get('foo.yeah'), 42)
Ejemplo n.º 10
0
    def __init__(self, path, config=None, version=None):
        """
        Constructor call of the project. 

        - First param is the path of the project relative to the current working directory.
        - Config can be read from jasyproject.json or using constructor parameter @config
        - Parent is used for structural debug messages (dependency trees)
        """

        if not os.path.isdir(path):
            raise UserError("Invalid project path: %s" % path)

        # Only store and work with full path
        self.__path = os.path.abspath(os.path.expanduser(path))

        # Store given params
        self.version = version

        # Intialize item registries
        self.classes = {}
        self.assets = {}
        self.docs = {}
        self.translations = {}

        # Load project configuration
        self.__config = Config.Config(config)
        self.__config.loadValues(os.path.join(self.__path, "jasyproject"),
                                 optional=True)

        # Initialize cache
        try:
            File.mkdir(os.path.join(self.__path, ".jasy"))
            self.__cache = jasy.core.Cache.Cache(self.__path,
                                                 filename=".jasy/cache")
        except IOError as err:
            raise UserError(
                "Could not initialize project. Cache file in %s could not be initialized! %s"
                % (self.__path, err))

        # Detect version changes
        if version is None:
            self.__modified = True
        else:
            cachedVersion = self.__cache.read("project[version]")
            self.__modified = cachedVersion != version
            self.__cache.store("project[version]", version)

        # Read name from manifest or use the basename of the project's path
        self.__name = self.__config.get("name",
                                        getProjectNameFromPath(self.__path))

        # Read requires
        self.__requires = self.__config.get("requires", {})

        # Defined whenever no package is defined and classes/assets are not stored in the toplevel structure.
        self.__package = self.__config.get(
            "package", self.__name if self.__config.has("name") else None)

        # Read fields (for injecting data into the project and build permutations)
        self.__fields = self.__config.get("fields", {})

        # Read setup for running command pre-scan
        self.__setup = self.__config.get("setup")
Ejemplo n.º 11
0
 def isImageSpriteConfig(self):
     return self.isText() and Config.isConfigName(self.id, "jasysprite")
Ejemplo n.º 12
0
 def isImageSpriteConfig(self):
     return self.isText() and Config.isConfigName(self.id, "jasysprite")
Ejemplo n.º 13
0
 def getParsedObject(self):
     return Config.loadConfig(self.getPath())
Ejemplo n.º 14
0
 def isImageAnimationConfig(self):
     return self.isText() and Config.isConfigName(self.id, "jasyanimation")
Ejemplo n.º 15
0
# Classes
from jasy.core.OutputManager import OutputManager
from jasy.core.FileManager import FileManager
from jasy.asset.Manager import AssetManager
from jasy.asset.SpritePacker import SpritePacker
from jasy.js.Resolver import Resolver
from jasy.js.api.Writer import ApiWriter
from jasy.http.Server import Server

# Commands (be careful with these, prefer modules and classes)
from jasy.env.Task import task

# Create config object
import jasy.core.Config as Config
config = Config.Config()
config.__doc__ = "Auto initialized config object based on project's jasyscript.yaml/json"
config.loadValues("jasyscript", optional=True)


@task
def about():
    """Print outs the Jasy about page"""

    import jasy

    jasy.info()

    from jasy.env.Task import getCommand

    Console.info("Command: %s", getCommand())
Ejemplo n.º 16
0
 def getParsedObject(self):
     return Config.loadConfig(self.getPath())
Ejemplo n.º 17
0
    def test_config_object_hasdata(self):

        config = Config.Config({'two': 2, 'one': 1, 'ten': 10})
        self.assertTrue(config.has('two'))
Ejemplo n.º 18
0
 def isImageAnimationConfig(self):
     return self.isText() and Config.isConfigName(self.id, "jasyanimation")
Ejemplo n.º 19
0
    def test_config_object_setdata(self):

        config = Config.Config({'two': 2, 'one': 1, 'ten': 10})
        config.set('ten', 15)
        self.assertEqual(config.get('ten'), 15)