• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# extract-release-date-from-doap-file.py VERSION DOAP-FILE
4#
5# Extract release date for the given release version from a DOAP file
6#
7# Copyright (C) 2020 Tim-Philipp Müller <tim centricular com>
8#
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Library General Public
11# License as published by the Free Software Foundation; either
12# version 2 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17# Library General Public License for more details.
18#
19# You should have received a copy of the GNU Library General Public
20# License along with this library; if not, write to the
21# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22# Boston, MA 02110-1301, USA.
23
24import sys
25import xml.etree.ElementTree as ET
26
27if len(sys.argv) != 3:
28  sys.exit('Usage: {} VERSION DOAP-FILE'.format(sys.argv[0]))
29
30release_version = sys.argv[1]
31doap_fn = sys.argv[2]
32
33tree = ET.parse(doap_fn)
34root = tree.getroot()
35
36namespaces = {'doap': 'http://usefulinc.com/ns/doap#'}
37
38for v in root.findall('doap:release/doap:Version', namespaces=namespaces):
39  if v.findtext('doap:revision', namespaces=namespaces) == release_version:
40    release_date = v.findtext('doap:created', namespaces=namespaces)
41    if release_date:
42      print(release_date)
43      sys.exit(0)
44
45sys.exit('Could not find a release with version {} in {}'.format(release_version, doap_fn))
46