コード例 #1
0
ファイル: __init__.py プロジェクト: yagebu/fava
    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)
コード例 #2
0
ファイル: test_api_helpers.py プロジェクト: yagebu/fava
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)
コード例 #3
0
ファイル: test_api_helpers.py プロジェクト: nathangrigg/fava
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)
コード例 #4
0
ファイル: __init__.py プロジェクト: yagebu/fava
    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()
コード例 #5
0
    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()
コード例 #6
0
 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))