Changeset - e79877ee6a3f
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2020-04-28 14:48:10
brettcsmith@brettcsmith.org
data: Add rt-id to LINK_METADATA.

This gets closer to our real intentions: anything that checks link
metadata should check rt-id. MetaRepoLinks is the exception, not
the rule, in ignoring rt-id.
3 files changed with 4 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/data.py
Show inline comments
...
 
@@ -53,12 +53,13 @@ LINK_METADATA = frozenset([
 
    'approval',
 
    'check',
 
    'contract',
 
    'invoice',
 
    'purchase-order',
 
    'receipt',
 
    'rt-id',
 
    'statement',
 
])
 

	
 
class Account(str):
 
    """Account name string
 

	
conservancy_beancount/plugin/meta_repo_links.py
Show inline comments
...
 
@@ -31,12 +31,13 @@ from typing import (
 
    MutableMapping,
 
    Optional,
 
)
 

	
 
class MetaRepoLinks(core.TransactionHook):
 
    HOOK_GROUPS = frozenset(['linkcheck'])
 
    LINK_METADATA = data.LINK_METADATA.difference('rt-id')
 
    PATH_PUNCT_RE = re.compile(r'[:/]')
 

	
 
    def __init__(self, config: configmod.Config) -> None:
 
        repo_path = config.repository_path()
 
        if repo_path is None:
 
            raise errormod.ConfigurationError("no repository configured")
...
 
@@ -45,13 +46,13 @@ class MetaRepoLinks(core.TransactionHook):
 
    def _check_links(self,
 
                     meta: MutableMapping[MetaKey, MetaValue],
 
                     txn: Transaction,
 
                     post: Optional[Posting]=None,
 
    ) -> errormod.Iter:
 
        metadata = data.Metadata(meta)
 
        for key in data.LINK_METADATA:
 
        for key in self.LINK_METADATA:
 
            try:
 
                links = metadata.get_links(key)
 
            except TypeError:
 
                yield errormod.InvalidMetadataError(txn, key, meta[key], post)
 
            else:
 
                for link in links:
conservancy_beancount/plugin/meta_rt_links.py
Show inline comments
...
 
@@ -29,13 +29,12 @@ from typing import (
 
    MutableMapping,
 
    Optional,
 
)
 

	
 
class MetaRTLinks(core.TransactionHook):
 
    HOOK_GROUPS = frozenset(['linkcheck', 'network', 'rt'])
 
    LINK_METADATA = data.LINK_METADATA.union(['rt-id'])
 

	
 
    def __init__(self, config: configmod.Config) -> None:
 
        rt_wrapper = config.rt_wrapper()
 
        if rt_wrapper is None:
 
            raise errormod.ConfigurationError("can't log in to RT")
 
        self.rt = rt_wrapper
...
 
@@ -43,13 +42,13 @@ class MetaRTLinks(core.TransactionHook):
 
    def _check_links(self,
 
                     meta: MutableMapping[MetaKey, MetaValue],
 
                     txn: Transaction,
 
                     post: Optional[Posting]=None,
 
    ) -> errormod.Iter:
 
        metadata = data.Metadata(meta)
 
        for key in self.LINK_METADATA:
 
        for key in data.LINK_METADATA:
 
            try:
 
                links = metadata.get_links(key)
 
            except TypeError:
 
                yield errormod.InvalidMetadataError(txn, key, meta[key], post)
 
            else:
 
                for link in links:
0 comments (0 inline, 0 general)