From 6dbc7c9a4afc7dd16fb4adf794b78d06d6df517a Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Apr 04 2017 15:47:00 +0000 Subject: Yet another handy utility --- diff --git a/docs/show_update_dates.py b/docs/show_update_dates.py new file mode 100755 index 0000000..4e2d406 --- /dev/null +++ b/docs/show_update_dates.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +#PYTHON_ARGCOMPLETE_OK +#pylint: disable=line-too-long +''' + This script will simply print out updates and their publication dates +''' +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Version 0.1 by Pat Riehecky for Scientific Linux + +# for python3 compat +from __future__ import unicode_literals +from __future__ import absolute_import +from __future__ import print_function + +from datetime import datetime + +from updateinfo.updateinfo import Updateinfo +from updateinfo.helpers.repo import get_xml_from_repo + +def read_updateinfo_xml_from_repo(repobase): + ''' Get an updateinfo file, parse it and return the resulting object''' + txt = get_xml_from_repo(repobase, mdtype='updateinfo') + + updateinfo_obj = Updateinfo() + updateinfo_obj.xml = txt + + return updateinfo_obj + +def read_updateinfo_xml_from_file(filename): + ''' Open an updateinfo file, parse it and return the resulting object''' + _fd = open(filename, 'r') + txt = _fd.read() + _fd.close() + + updateinfo_obj = Updateinfo() + updateinfo_obj.xml = txt + + return updateinfo_obj + +def read_updateinfo_yaml_from_file(filename): + ''' Open an updateinfo file, parse it and return the resulting object''' + _fd = open(filename, 'r') + txt = _fd.read() + _fd.close() + + updateinfo_obj = Updateinfo() + updateinfo_obj.yaml = txt + + return updateinfo_obj + +def merge_updateinfo(primary, add_these): + '''merge in the elements from add_these into the primary object''' + for update in add_these: + primary.add(add_these[update]) + + return primary + + +if __name__ == '__main__': + import textwrap + from argparse import ArgumentParser + + PARSER = ArgumentParser(description=textwrap.dedent(__doc__)) + + PARSER.add_argument('filename', nargs='+', + help='What should be parsed? List however many') + PARSER.add_argument('--valsep', default='|', + help='How is output seperated') + PARSER.add_argument('--isyaml', action='store_true', + default=False, help='Are the source files YAML instead of XML') + + ARGS = PARSER.parse_args() + + MYUPDATEINFO = Updateinfo() + + for FILE in ARGS.filename: + if ARGS.isyaml: + TMPNAME = read_updateinfo_yaml_from_file(FILE) + else: + if FILE.startswith('http') or FILE.startswith('ftp://'): + TMPNAME = read_updateinfo_xml_from_repo(FILE) + else: + TMPNAME = read_updateinfo_xml_from_file(FILE) + merge_updateinfo(MYUPDATEINFO, TMPNAME) + + NOW = datetime.now() + + for UPDATE in MYUPDATEINFO: + TXT = MYUPDATEINFO[UPDATE].updateid + ARGS.valsep + MYUPDATEINFO[UPDATE].updatetype + ARGS.valsep + print(TXT + str(MYUPDATEINFO[UPDATE].issued_date)) +