File: metainfo_xml_write.py

package info (click to toggle)
cherrytree 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 23,528 kB
  • sloc: cpp: 102,757; ansic: 14,613; xml: 1,532; sh: 374; python: 288; javascript: 80; ruby: 63; makefile: 9
file content (46 lines) | stat: -rwxr-xr-x 1,458 bytes parent folder | download
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
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3

import os
import re
import time
import xml.etree.ElementTree as ET

SCRIPTS_DIR = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(SCRIPTS_DIR)
DATA_DIR = os.path.join(ROOT_DIR, "data")
TEMPLATE_METAINFO_XML_FILEPATH = os.path.join(DATA_DIR, "_net.giuspen.cherrytree.metainfo.xml")
METAINFO_XML_FILEPATH = os.path.join(DATA_DIR, "net.giuspen.cherrytree.metainfo.xml")
DEBIAN_CHANGELOG_PATH = os.path.join(ROOT_DIR, "debian", "changelog")

VERSION = "?"
with open(DEBIAN_CHANGELOG_PATH, "rb") as fd:
    for fileline in fd:
        match = re.search(b"cherrytree +\\(([0-9]+\\.[0-9]+\\.[0-9]+)[-+]", fileline)
        if match is not None:
            VERSION = str(match.group(1))
            #print(VERSION)
            break
DATE = time.strftime(
    "%Y-%m-%d",
    time.gmtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
)

# <?xml version="1.0" encoding="UTF-8"?>
# <component type="desktop-application">
#  <releases>
#    <release version="0.99.2" date="2020-06-21" />
#  </releases>
# </component>

def main(args):
    tree = ET.parse(TEMPLATE_METAINFO_XML_FILEPATH)
    root = tree.getroot()
    releases = root.findall("./releases")
    assert len(releases) == 1
    releases[0].text = "\n  "
    release_Element = ET.SubElement(releases[0], "release", version=VERSION, date=DATE)
    tree.write(METAINFO_XML_FILEPATH)

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))