summaryrefslogtreecommitdiffstats
path: root/__init__.py
blob: 80b09f4ace41d6d2d2ab1fd1082841e1970b6ee0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import subprocess

from pelican import signals


class GitDescribe:
    def __init__(self, gen):
        self.settings = gen.settings
        self.process()

    def process(self):
        """Initialization process."""
        pass

    def defer_process(self):
        """Check and return git describe value."""
        result = subprocess.run(["git", "describe", "--tags"],
                                stdout=subprocess.PIPE, check=True)
        return result.stdout.decode('utf-8').strip()


def initialize(gen):
    """Function called upon article generator initialization."""
    gen.plugin_instance = GitDescribe(gen)


def fetch(gen, metadata):
    """Function called upon article generation context fetching."""
    gen.context['git_describe'] = gen.plugin_instance.defer_process()


def register():
    """Register Pelican signals to dedicated functions."""
    signals.article_generator_init.connect(initialize)
    signals.article_generator_context.connect(fetch)