def insert_metadata(self, filename, lineno, basekey, value): """Insert metadata into a file at lineno. Also, prevent duplicate keys. """ entry = entry_at_lineno(self.entries, filename, lineno, Transaction) key = next_key(basekey, entry.meta) insert_metadata_in_file(filename, lineno - 1, key, value)
def test_entry_at_lineno(load_doc): """ plugin "auto_accounts" 2016-01-01 * "Test" "Test" Equity:Unknown Assets:Cash 5000 USD """ entries, _, _ = load_doc assert entries[0] == entry_at_lineno(entries, '<string>', 4) assert entries[0] == entry_at_lineno(entries, '<string>', 4, Transaction) with pytest.raises(FavaAPIException): entry_at_lineno(entries, '<string>', 1) with pytest.raises(FavaAPIException): entry_at_lineno(entries, 'foo', 4) with pytest.raises(FavaAPIException): entry_at_lineno(entries, '<string>', 4, Posting)
def statement_path(self, filename, lineno, metadata_key): """Returns the path for a statement found in the specified entry.""" entry = entry_at_lineno(self.entries, filename, lineno, Transaction) value = entry.meta[metadata_key] paths = [value] paths.extend([os.path.join(posting.account.replace(":", "/"), value) for posting in entry.postings]) paths.extend( [ os.path.join(document_root, posting.account.replace(":", "/"), value) for posting in entry.postings for document_root in self.options["documents"] ] ) for path in [self.abs_path(p) for p in paths]: if os.path.isfile(path): return path raise FavaFileNotFoundException()
def statement_path(self, filename, lineno, metadata_key): """Returns the path for a statement found in the specified entry.""" entry = entry_at_lineno(self.entries, filename, lineno, Transaction) value = entry.meta[metadata_key] paths = [value] paths.extend([os.path.join(posting.account.replace(':', '/'), value) for posting in entry.postings]) paths.extend([os.path.join( document_root, posting.account.replace(':', '/'), value) for posting in entry.postings for document_root in self.options['documents']]) for path in [self.abs_path(p) for p in paths]: if os.path.isfile(path): return path raise FavaFileNotFoundException()
def insert_metadata(self, filename, lineno, basekey, value): """Insert metadata into a file at lineno. Also, prevent duplicate keys.""" entry = entry_at_lineno(self.entries, filename, lineno, Transaction) key = next_key(basekey, entry.meta) insert_line_in_file(filename, lineno-1, '{}: "{}"'.format(key, value))