Пример #1
0
    def create_file(entry_points_filepath):
        '''Create empty default EntryPoints file if it does not exist

		Args:
			entry_points_filepath (String): path for empty model_entry_points.yml file
		'''
        try:
            with open(entry_points_filepath, 'w') as entry_points_file:
                s = "entry_points:\n\n"
                entry_points_file.write(s)
        except IOError as e:
            raise ModellingException("Could not create entry_points file. " +
                                     e.strerror)
Пример #2
0
    def create_file(tech_filepath):
        '''Create empty default technologies file if it does not exist

		Args:
			tech_filepath (String): path for empty model_technologies.yml file
		'''
        try:
            with open(tech_filepath, 'w') as technologies_file:
                s = "technologies:\n\n"
                technologies_file.write(s)
        except IOError as e:
            raise ModellingException("Could not create technologies file. " +
                                     e.strerror)
Пример #3
0
    def create_file(assets_filepath):
        '''Create empty default assets file if it does not exist

		Args:
			assets_filepath (String): path for empty model_assets.yml file
		'''
        try:
            with open(assets_filepath, 'w') as assets_file:
                s = "assets:\n\n"
                assets_file.write(s)
        except IOError as e:
            raise ModellingException("Could not create assets file. " +
                                     e.strerror)
Пример #4
0
    def fetch_known_technologies(tech_filepath):
        '''
		reads and returns content of the file used to 'cache' all already used Technologies to minimise persons typing

		Args:
			tech_filepath (String): path to file of set of used technologies info

		Raises:
			ModellingException: if a problem arrises report

		Returns:
			dict(String:dict): technologies from file tech_name:{name:tech_name, description:tech_desc, attributes: {attr1:attr1value, atrrX:attrXvalue, ...} }
		'''

        known_technologies = {}

        if not os.path.isfile(tech_filepath):
            Technology.create_file(tech_filepath)

        content = None
        with open(tech_filepath, 'r') as stream:
            try:
                content = yaml.safe_load(stream)
            except yaml.YAMLError as exc:
                raise ModellingException("Could not parse technologies file " +
                                         tech_filepath + ". \n" + str(exc))

        if not content or 'technologies' not in content:
            raise ModellingException("Technology file is corrupt: " +
                                     tech_filepath)

        if content['technologies']:
            for tech, tech_data in content['technologies'].items():
                # technology = Technology(tech_data['name'], tech_data['description'], tech_data['attributes'], tech_filepath)
                known_technologies[tech] = tech_data

        return known_technologies
Пример #5
0
    def fetch_known_entry_points(entry_points_filepath):
        '''
		reads and returns content of the file used to 'cache' all already used EntryPoints to minimise persons typing

		Args:
			entry_points_filepath (String): path to file of set of used entry_points info

		Raises:
			ModellingException: if a problem arrises report

		Returns:
			dict(String:String): entry_points from file entry_point_name:entry_point_desc
		'''

        known_entry_points = {}

        if not os.path.isfile(entry_points_filepath):
            EntryPoint.create_file(entry_points_filepath)

        content = None
        with open(entry_points_filepath, 'r') as stream:
            try:
                content = yaml.safe_load(stream)
            except yaml.YAMLError as exc:
                raise ModellingException("Could not parse entry_points file " +
                                         entry_points_filepath + ". \n" +
                                         str(exc))

        if not content or 'entry_points' not in content:
            raise ModellingException("EntryPoint file is corrupt: " +
                                     entry_points_filepath)

        if content['entry_points']:
            for name, desc in content['entry_points'].items():
                known_entry_points[name] = desc

        return known_entry_points
Пример #6
0
    def fetch_known_assets(assets_filepath):
        '''
		reads and returns content of the file used to 'cache' all already used Assets to minimise persons typing

		Args:
			assets_filepath (String): path to file of set of used assets info

		Raises:
			ModellingException: if a problem arrises report

		Returns:
			dict(String:String): assets from file name:description
		'''

        known_assets = {}

        if not os.path.isfile(assets_filepath):
            Asset.create_file(assets_filepath)

        content = None
        with open(assets_filepath, 'r') as stream:
            try:
                content = yaml.safe_load(stream)
            except yaml.YAMLError as exc:
                raise ModellingException("Could not parse asset file " +
                                         assets_filepath + ". \n" + str(exc))

        if not content or 'assets' not in content:
            raise ModellingException("Asset file is corrupt: " +
                                     assets_filepath)

        if content['assets']:
            for asset, asset_desc in content['assets'].items():
                known_assets[asset] = asset_desc

        return known_assets
Пример #7
0
    def update_known_assets(self):
        '''writes current asset value to model-assets.yml file

		Raises:
			ModellingException: 
		'''

        known_assets = Asset.fetch_known_assets(self.assets_filepath)
        known_assets[self.name] = self.description

        try:
            with open(self.assets_filepath, 'w') as assets_file:
                yaml.safe_dump({"assets": known_assets}, assets_file)
        except IOError as e:
            raise ModellingException("Could not append assets file. " +
                                     e.strerror)
Пример #8
0
    def update_known_entry_points(self):
        '''writes current entry_point value to model-entry_points.yml file

		Raises:
			ModellingException
		'''

        known_entry_points = EntryPoint.fetch_known_entry_points(
            self.entry_points_filepath)
        known_entry_points[self.name] = self.description

        try:
            with open(self.entry_points_filepath, 'w') as entry_points_file:
                yaml.safe_dump({"entry_points": known_entry_points},
                               entry_points_file)
                # entry_points_file.write("entry_points:\n")
                # for name, desc in known_entry_points.items():
                # 	s = "  '"+name+"': '"+desc+"'\n"
                # 	entry_points_file.write(s)
        except IOError as e:
            raise ModellingException("Could not append EntryPoints file. " +
                                     e.strerror)
Пример #9
0
    def update_known_technologies(self):
        '''writes current technology value to model-technologies.yml file

		Raises:
			ModellingException
		'''

        known_technologies = Technology.fetch_known_technologies(
            self.tech_filepath)
        known_technologies[self.name] = {
            "name": self.name,
            "description": self.description,
            "attributes": self.attributes
        }

        try:
            with open(self.tech_filepath, 'w') as technologies_file:

                yaml.safe_dump({"technologies": known_technologies},
                               technologies_file)
        except IOError as e:
            raise ModellingException("Could not append technology file. " +
                                     e.strerror)