def write_yaml(self, path, content): with self.profile.timer( 'Pod.write_yaml', label=path, meta={'path': path}): self.podcache.collection_cache.remove_by_path(path) self.podcache.document_cache.remove_by_path(path) content = utils.dump_yaml(content) self.write_file(path, content)
def create(cls, collection_path, fields, pod): """Creates a new collection by writing a blueprint.""" collection = cls.get(collection_path, pod) if collection.exists: raise CollectionExistsError('{} already exists.'.format(collection)) fields = utils.dump_yaml(fields) pod.write_file(collection._blueprint_path, fields) return collection
def create(cls, collection_path, fields, pod): """Creates a new collection by writing a blueprint.""" collection = cls.get(collection_path, pod) if collection.exists: raise CollectionExistsError( '{} already exists.'.format(collection)) fields = utils.dump_yaml(fields) pod.write_file(collection.blueprint_path, fields) return collection
def test_yaml_dump(self): """Test if the yaml representer is working correctly.""" pod = testing.create_pod() pod.write_yaml('/podspec.yaml', {}) pod.write_yaml('/content/pages/page.yaml', {}) doc = pod.get_doc('/content/pages/page.yaml') input_obj = {'doc': doc} expected = textwrap.dedent("""\ doc: !g.doc '/content/pages/page.yaml' """) self.assertEqual(expected, utils.dump_yaml(input_obj))
def update(self, fields=utils.SENTINEL, content=utils.SENTINEL): """Updates content and frontmatter.""" if fields is not utils.SENTINEL: raw_front_matter = utils.dump_yaml(fields) self.front_matter.update_raw_front_matter(raw_front_matter) self._doc.pod.podcache.document_cache.add_property( self._doc, 'front_matter', self.front_matter.export()) if content is not utils.SENTINEL: self._content = content self._raw_content = self.to_raw_content()
def update(content, fields=utils.SENTINEL, body=utils.SENTINEL): """Updates content with frontmatter. The existing fields and the existing body are preserved if they are not specified in arguments.""" parts = Format.split_front_matter(content) or ['', ''] if fields is not utils.SENTINEL: fields = '\n' + utils.dump_yaml(fields) parts[0] = fields if body is not utils.SENTINEL and len(parts) > 1: parts[1] = '\n' + body result = '---' + '---'.join(parts) if result.endswith('---\n'): return result[:-5] return result
def update(self, fields=utils.SENTINEL, content=utils.SENTINEL): """Updates content and frontmatter.""" if fields is not utils.SENTINEL: # Organize some of the fields for minimal consistency. fields = self.organize_fields(fields) raw_front_matter = utils.dump_yaml(fields) self.front_matter.update_raw_front_matter(raw_front_matter) self._doc.pod.podcache.document_cache.add_property( self._doc, 'front_matter', self.front_matter.export()) if content is not utils.SENTINEL: self._content = content self._raw_content = self.to_raw_content()
def test_yaml_dump(self): """Test if the yaml representer is working correctly.""" pod = testing.create_pod() pod.write_yaml('/podspec.yaml', {}) pod.write_yaml('/content/pages/page.yaml', {}) doc = pod.get_doc('/content/pages/page.yaml') input_obj = { 'doc': doc } expected = textwrap.dedent( """\ doc: !g.doc '/content/pages/page.yaml' """) self.assertEqual(expected, utils.dump_yaml(input_obj))
def write_yaml(self, path, content): self.podcache.collection_cache.remove_by_path(path) self.podcache.document_cache.remove_by_path(path) content = utils.dump_yaml(content) self.write_file(path, content)
def write_yaml(self, path, content): for virtual_key in self.virtual_files.keys(): if path in virtual_key: del self.virtual_files[virtual_key] content = utils.dump_yaml(content) self.write_file(path, content)
def write_yaml(self, path, content): content = utils.dump_yaml(content) self.write_file(path, content)
def update_from_message(self, message): if not message.fields: raise BadFieldsError("Fields are required to create a collection.") fields = json.loads(message.fields) fields = utils.dump_yaml(fields) self.pod.write_file(self._blueprint_path, fields)
def update_from_message(self, message): if not message.fields: raise BadFieldsError('Fields are required to create a collection.') fields = json.loads(message.fields) fields = utils.dump_yaml(fields) self.pod.write_file(self._blueprint_path, fields)
def update_fields(self, fields): """Update the data with new field values.""" _update_deep(self.data, fields) self.update_raw_front_matter(utils.dump_yaml(self.data))