c9c1dc1
#!/usr/bin/python
c9c1dc1
c9c1dc1
"""
c9c1dc1
Automatic provides generator for Drupal 7 modules, profiles, and themes.
c9c1dc1
c9c1dc1
Parsed from *.info files.
039b1a5
039b1a5
First command line argument is used as version if provided.
c9c1dc1
"""
c9c1dc1
49c3bbb
# Copyright 2013-2020 Shawn Iwinski <shawn.iwinski@gmail.com>
c9c1dc1
#
c9c1dc1
# Permission is hereby granted, free of charge, to any person obtaining a copy
c9c1dc1
# of this software and associated documentation files (the "Software"), to
c9c1dc1
# deal in the Software without restriction, including without limitation the
c9c1dc1
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
c9c1dc1
# sell copies of the Software, and to permit persons to whom the Software is
c9c1dc1
# furnished to do so, subject to the following conditions:
c9c1dc1
#
c9c1dc1
# The above copyright notice and this permission notice shall be included in
c9c1dc1
# all copies or substantial portions of the Software.
c9c1dc1
#
c9c1dc1
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
c9c1dc1
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
c9c1dc1
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
c9c1dc1
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
c9c1dc1
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
c9c1dc1
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
c9c1dc1
# IN THE SOFTWARE.
c9c1dc1
039b1a5
import re
c9c1dc1
import subprocess
c9c1dc1
import sys
c9c1dc1
import os
c9c1dc1
c9c1dc1
039b1a5
RE_HIDDEN = re.compile(r'hidden\s*=\s*TRUE', re.IGNORECASE)
039b1a5
039b1a5
c9c1dc1
def main():
Peter Borsa b872df3
    version = None
Peter Borsa b074201
    if len(sys.argv) > 1:
Peter Borsa b872df3
        version = sys.argv[1]
Peter Borsa b074201
Peter Borsa b074201
    paths = [path.rstrip() for path in sys.stdin.readlines()]
c9c1dc1
c9c1dc1
    for path in paths:
039b1a5
        if path.endswith('.info') and not re.search(RE_HIDDEN, open(path).read()):
039b1a5
            print 'drupal7(' + os.path.basename(path)[:-len('.info')] + ')',
039b1a5
            if version is not None:
7651202
                print ' = ', version
039b1a5
            else:
039b1a5
                print ''
c9c1dc1
c9c1dc1
    # Invoke the regular RPM provides generator to allow compatibility with RPM < 4.9 (no fileattrs)
c9c1dc1
    p = subprocess.Popen(['/usr/lib/rpm/find-provides'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
c9c1dc1
    print p.communicate(input='\n'.join(paths))[0]
c9c1dc1
c9c1dc1
c9c1dc1
if __name__ == '__main__':
c9c1dc1
    main()