Warning, /sdk/kde-dev-scripts/kde-project-info is written in an unsupported language. File is not indexed.

0001 #!/usr/bin/env python
0002 
0003 # Prints requested info about KDE projects, as obtained from kde_projects.xml, which
0004 # must be downloaded separately.
0005 #
0006 # Copyright (c) 2014 Michael Pyne <mpyne@kde.org>
0007 #
0008 # Redistribution and use in source and binary forms, with or without
0009 # modification, are permitted provided that the following conditions
0010 # are met:
0011 # 
0012 # 1. Redistributions of source code must retain the above copyright
0013 #    notice, this list of conditions and the following disclaimer.
0014 # 2. Redistributions in binary form must reproduce the above copyright
0015 #    notice, this list of conditions and the following disclaimer in the
0016 #    documentation and/or other materials provided with the distribution.
0017 # 
0018 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0019 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0020 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0021 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0022 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0023 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0024 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0025 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0026 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0027 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0028 
0029 import xml.etree.ElementTree as ET
0030 import argparse
0031 import sys
0032 
0033 arg_parser = argparse.ArgumentParser(
0034         description="Prints data about KDE Project source repositories.",
0035         epilog="E.g. '%(prog)s -f /path/to/kde_projects.xml -p juk' would give kde/kdemultimedia/juk"
0036         )
0037 arg_parser.add_argument('-f', '--projects-file', dest='file',
0038         required=True, type=argparse.FileType('r'),
0039         help="Path to the kde_projects.xml file")
0040 arg_parser.add_argument('name',
0041         help="Name of KDE Project module to read information on")
0042 
0043 arg_group = arg_parser.add_mutually_exclusive_group(required=True)
0044 arg_group.add_argument('-p', '--print-path', action='store_true',
0045         help="Print full virtual project path for given modules")
0046 arg_group.add_argument('-d', '--print-description', action='store_true',
0047         help="Print module description")
0048 # Other options could be added here
0049 
0050 args = arg_parser.parse_args()
0051 proj_data = ET.parse(args.file)
0052 
0053 # Finds XML elements with a <repo> child, with an identifier="" attribute. I.e.
0054 # <foo identifier="name"><repo>...</repo>...</foo>
0055 element_list = proj_data.findall(".//repo/..[@identifier='%s']" % (args.name))
0056 if len(element_list) < 1 or element_list[0] is None:
0057     print("No project known by the name %s!" % (args.name))
0058     sys.exit(1)
0059 
0060 if len(element_list) > 1:
0061     print("Found %d elements, was only expecting 1." % (len(element_list)))
0062     sys.exit(1)
0063 
0064 # At this point we've found the XML element for our one project, now break out
0065 # the data we were asked for.
0066 element = element_list[0]
0067 
0068 if args.print_path:
0069     path = element.find('path').text
0070     print(path)
0071 elif args.print_description:
0072     desc = element.find('description').text
0073     print(desc)