示例#1
0
 def relation_ids(self, relation_name):
     try:
         return self._relation_ids_map[relation_name]
     except KeyError as e:
         if relation_name not in self._meta.relations:
             raise model.ModelError('{} is not a known relation'.format(relation_name)) from e
         return []
示例#2
0
 def resource_get(self, resource_name):
     if resource_name not in self._resources_map:
         raise model.ModelError(
             "ERROR could not download resource: HTTP request failed: "
             "Get https://.../units/unit-{}/resources/{}: resource#{}/{} not found"
             .format(self.unit_name.replace('/', '-'), resource_name,
                     self.app_name, resource_name))
     filename, contents = self._resources_map[resource_name]
     resource_dir = self._get_resource_dir()
     resource_filename = resource_dir / resource_name / filename
     if not resource_filename.exists():
         if isinstance(contents, bytes):
             mode = 'wb'
         else:
             mode = 'wt'
         resource_filename.parent.mkdir(exist_ok=True)
         with resource_filename.open(mode=mode) as resource_file:
             resource_file.write(contents)
     return resource_filename