- # TODO(fungi): remove this method after the YAML transition
- def load_mpy(self):
- """Read a file and create elements accordingly."""
- self._format = 'mpy'
- self.modified = False
- self.data = configparser.RawConfigParser()
- if os.access(self.filename, os.R_OK):
- self.data.read(self.filename)
- if not hasattr(self.universe, "files"):
- self.universe.files = {}
- self.universe.files[self.filename] = self
- includes = []
- if self.data.has_option("__control__", "include_files"):
- for included in makelist(
- self.data.get("__control__", "include_files")
- ):
- included = find_file(
- included,
- relative=self.filename,
- universe=self.universe
- )
- if included not in includes:
- includes.append(included)
- if self.data.has_option("__control__", "include_dirs"):
- for included in [
- os.path.join(x, "__init__.yaml") for x in makelist(
- self.data["__control__"]["include_dirs"]
- )
- ]:
- included = find_file(
- included,
- relative=self.filename,
- universe=self.universe
- )
- if included not in includes:
- includes.append(included)
- for included in [
- os.path.join(x, "__init__.mpy") for x in makelist(
- self.data.get("__control__", "include_dirs")
- )
- ]:
- included = find_file(
- included,
- relative=self.filename,
- universe=self.universe
- )
- if included not in includes:
- includes.append(included)
- if self.data.has_option("__control__", "default_files"):
- origins = makedict(
- self.data.get("__control__", "default_files")
- )
- for key in origins.keys():
- origins[key] = find_file(
- origins[key],
- relative=self.filename,
- universe=self.universe
- )
- if origins[key] not in includes:
- includes.append(origins[key])
- self.universe.default_origins[key] = origins[key]
- if key not in self.universe.categories:
- self.universe.categories[key] = {}
- if self.data.has_option("__control__", "private_files"):
- for item in makelist(
- self.data.get("__control__", "private_files")
- ):
- item = find_file(
- item,
- relative=self.filename,
- universe=self.universe
- )
- if item not in includes:
- includes.append(item)
- if item not in self.universe.private_files:
- self.universe.private_files.append(item)
- for section in self.data.sections():
- if section != "__control__":
- mudpy.misc.Element(section, self.universe, self.filename)
- for include_file in includes:
- if not os.path.isabs(include_file):
- include_file = find_file(
- include_file,
- relative=self.filename,
- universe=self.universe
- )
- if (include_file not in self.universe.files or not
- self.universe.files[include_file].is_writeable()):
- DataFile(include_file, self.universe)
-
- # TODO(fungi): this should support writing YAML