示例#1
0
文件: Project.py 项目: E01T/jasy
    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")
示例#2
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")