<?xml version='1.0' encoding='utf-8'?>
<snippets language="rpmspec">
  <snippet>
    <tag>clog</tag>
    <text><![CDATA[$<
filename = $GEDIT_CURRENT_DOCUMENT_PATH
import re
from datetime import datetime
global date
global version
global release
with open(filename, "r") as f:
    data = f.readlines()


def get_macroses():
    macroses = {}
    for line in data:
        if re.match("^%[ \t]*(define|global)", line):
            macroses[line.split()[1]] = line.split()[2]
    return macroses


def get_tag(s):
    for line in data:
        if line.startswith(s):
            return line.split()[1]


def is_macrosized(s):
    if "%" in s:
        return True
    else:
        return False


def parse_tag(tag):
    for macros in macroses:
        macros_formatted = "%{{{}}}".format(macros)
        if macros_formatted in tag:
            tag = tag.replace(macros_formatted, macroses[macros])
    print(tag)
    return tag

date = datetime.utcnow().strftime("%a %b %m %Y")
macroses = get_macroses()
version = get_tag("Version:")
release = get_tag("Release:").replace("%{?dist}", "")
if is_macrosized(version):
    version = parse_tag(version)
if is_macrosized(release):
    release = parse_tag(release)

return
>
* $<return date> Igor Gnatenko <i.gnatenko.brain@gmail.com> - $<return version>-$<return release>
- ]]></text>
    <accelerator><![CDATA[<Primary>b]]></accelerator>
    <description>Add ChangeLog Entry</description>
  </snippet>
</snippets>
