[fbt-commit] SF.net SVN: fbt:[103] trunk/bin/mkipcat.py
Status: Beta
Brought to you by:
dave_infj
From: <dav...@us...> - 2011-12-05 19:41:24
|
Revision: 103 http://fbt.svn.sourceforge.net/fbt/?rev=103&view=rev Author: dave_infj Date: 2011-12-05 19:41:18 +0000 (Mon, 05 Dec 2011) Log Message: ----------- initial commit; coregen IP catalogue generator Added Paths: ----------- trunk/bin/mkipcat.py Added: trunk/bin/mkipcat.py =================================================================== --- trunk/bin/mkipcat.py (rev 0) +++ trunk/bin/mkipcat.py 2011-12-05 19:41:18 UTC (rev 103) @@ -0,0 +1,100 @@ +#!/usr/bin/env python + +################################################################################ +# +# FPGA Build Tool +# Copyright (C) 2008 David Miller +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# MODULE: +# +# mkipcat.py +# +# PURPOSE: +# +# Generate catalogue of all available IP in coregen for $XILINX. The catalogue +# is used by the coregen writer in tool_common.py (via mkvproj.py) to rewrite +# IP version if required. +# +# $Id$ + +from __future__ import with_statement + +import os +import platform +import subprocess +import sys + +CAT_NAME = 'fbt_ip_catalogue.csv' + +def scan_ip( base, parent, ver_len ): + """ + Scans directories under `base` looking for directories containing IP, which + are identified by parent directory named `parent`, and returns a list of + (name, version) where version is the last `ver_len` elements of the + directory name. + """ + ip = [] + for root, dirs, files in os.walk( base ): + if os.path.basename(root) == parent: + for dir in dirs: + elts = dir.rsplit( '_', ver_len ) + if len(elts) != ver_len + 1 or elts[-ver_len][0] != 'v': + continue + elts[-ver_len] = elts[-ver_len][1:] # trim leading 'v' + ip.append( (elts[0], '.'.join(elts[-ver_len:])) ) + return ip + + +def main(): + if len(sys.argv) > 1: + xilinx = sys.argv[1] + else: + if 'XILINX' not in os.environ: + print '$XILINX not set' + sys.exit(1) + else: + xilinx = os.environ['XILINX'] + + if platform.system().lower().find('cygwin') != -1: + # On cygwin - must convert $XILINX to cygwin path + xilinx = subprocess.Popen( ['cygpath', xilinx], stdout=subprocess.PIPE ).communicate()[0].strip() + + cg_root = os.path.join( xilinx, 'coregen' ) + catalogue = os.path.join( xilinx, CAT_NAME ) + # Sanity check + for dir in [xilinx, cg_root]: + if not os.path.isdir( dir ): + print '%s not found' % dir + sys.exit(1) + + print """\ +Xilinx installation at %s +Coregen at %s +IP catalogue writen to %s +""" % (xilinx, cg_root, catalogue) + + ip = scan_ip( os.path.join( cg_root, 'ip' ), 'ip', 2 ) + \ + scan_ip( os.path.join( cg_root, 'iprepo' ), 'pcores', 3 ) + + with open( catalogue, 'w' ) as f: + f.writelines( ','.join(d)+'\n' for d in ip ) + + print 'Total cores: %d' % len(ip) + + +if __name__ == '__main__': + main() Property changes on: trunk/bin/mkipcat.py ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |