00001 # This file is part of repro, a Python package for automating 00002 # reproducible research in scientific computing. 00003 # 00004 # Copyright (C) 2008 Gilles Hennenfent, Sean Ross-Ross 00005 # 00006 # This program is free software: you can redistribute it and/or modify 00007 # it under the terms of the GNU General Public License as published by 00008 # the Free Software Foundation, either version 3 of the License, or 00009 # (at your option) any later version. 00010 # 00011 # This program is distributed in the hope that it will be useful, 00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 # GNU General Public License for more details. 00015 # 00016 # You should have received a copy of the GNU General Public License 00017 # along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 ## 00020 # 00021 # @package latexgraphics 00022 # Provide an extended TeX scanner based on SCons TeX scanner 00023 # 00024 import re, os.path 00025 00026 from SCons.Tool import LaTeXScanner 00027 from SCons.Script import File, FindSourceFiles 00028 00029 ## 00030 # 00031 # @bug Scanner include commented lines in search for dependencies. These lines 00032 # should be ignored. 00033 # @todo Update scanner to find dependencies related to 'listing' package. 00034 # 00035 def scanner_function( node, env, path ): 00036 00037 incgraph_re = re.compile('includegraphics') 00038 00039 if node.is_derived(): 00040 src_files = FindSourceFiles( node ) 00041 else: 00042 src_files = [node] 00043 00044 all_src_files = src_files 00045 00046 for src_file in src_files: 00047 all_src_files += LaTeXScanner.scan( src_file ) 00048 00049 all_deps = all_src_files 00050 for src_file in all_src_files: 00051 deps = LaTeXScanner.find_include_names( src_file ) 00052 for dep in deps: 00053 if incgraph_re.match( dep[0] ): 00054 filename = dep[1] 00055 ext = os.path.splitext( filename )[1] 00056 if ext == '': 00057 # default extension is PNG 00058 all_deps.append( File( filename+'.png' ) ) 00059 else: 00060 all_deps.append( File( filename ) ) 00061 00062 return all_deps 00063 00064