cmake_var.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2013, Yujin Robot, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Yujin Robot nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 import os
00034 import sys
00035 import shutil
00036 import re
00037 
00038 class Enum(set):
00039     def __getattr__(self, name):
00040         if name in self:
00041             return name
00042         raise AttributeError
00043 
00044 def get_value(pathname, keyname):
00045     try:
00046         file = open(pathname, 'r')
00047         buff = file.read()
00048     except:
00049         print("File not found.")
00050         return buff
00051     
00052     condition = re.compile('^.+', re.M)
00053     lines = condition.findall(buff)
00054     vars = []
00055     AssembleMode = Enum(["None", "Symbol", "Sentence"])
00056 
00057     try:
00058         iter_lines = iter(lines)
00059         for i in iter_lines:
00060             line = i.strip()
00061             if line[0] == '#':
00062                 continue
00063             
00064             tokens = re.split('[()]+', i)
00065             token = tokens[0].lower()
00066             command = token.strip()
00067 
00068             # filter 'set' command
00069             if command != 'set':
00070                 continue
00071             
00072             runner = 0;
00073             token = tokens[1]
00074             length = len(token)
00075             
00076             ##############################
00077             # Segment description of set command
00078             ##############################
00079 
00080             mode = AssembleMode.None
00081             word = ""
00082             words = []
00083             
00084             while runner < length:
00085                 if token[runner] == ' ':
00086                     if mode == AssembleMode.Symbol:
00087                         words.append(word)
00088                         word = ""
00089                         mode = AssembleMode.None
00090                     elif mode == AssembleMode.Sentence:
00091                         word += token[runner]
00092                 elif token[runner] == '"':
00093                     if mode == AssembleMode.None:
00094                         mode = AssembleMode.Sentence
00095                     elif mode == AssembleMode.Symbol:
00096                         words.append(word)
00097                         word = ""
00098                         mode = AssembleMode.Sentence
00099                     elif mode == AssembleMode.Sentence:
00100                         words.append(word)
00101                         word = ""
00102                         mode = AssembleMode.None
00103                 else:
00104                     word += token[runner]
00105                     if mode == AssembleMode.None:
00106                         mode = AssembleMode.Symbol
00107                         
00108                 runner += 1
00109 
00110             if len(words) < 2:
00111                 continue
00112 
00113             ##############################
00114             # Extract value of variable
00115             ##############################
00116             
00117             try:
00118                 idx = words.index('CACHE')
00119                 runner = 0
00120                 val = words[1]
00121                 while runner < (idx - 2):
00122                     val += ' '
00123                     val += words[runner + 2]
00124                     runner += 1
00125             except:
00126                 val = words[1]
00127                 
00128             dic = {"key":words[0], "val":val}
00129             vars.append(dic)
00130 
00131     except:
00132         return ""
00133 
00134     ##############################
00135     # Return matched value
00136     ##############################
00137 
00138     for j in vars:
00139         if j["key"] == keyname:
00140             return j["val"]
00141 
00142     return ""


win_python_build_tools
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:23:48