Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ignore.py
00001 # mbed SDK 00002 # Copyright (c) 2011-2013 ARM Limited 00003 # 00004 # Licensed under the Apache License, Version 2.0 (the "License"); 00005 # you may not use this file except in compliance with the License. 00006 # You may obtain a copy of the License at 00007 # 00008 # http://www.apache.org/licenses/LICENSE-2.0 00009 # 00010 # Unless required by applicable law or agreed to in writing, software 00011 # distributed under the License is distributed on an "AS IS" BASIS, 00012 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 # See the License for the specific language governing permissions and 00014 # limitations under the License. 00015 00016 import fnmatch 00017 import re 00018 from os.path import normcase, join 00019 00020 00021 IGNORE_FILENAME = ".mbedignore" 00022 00023 00024 class MbedIgnoreSet (object): 00025 """ 00026 # The mbedignore rules as an object 00027 00028 A project in Mbed OS contains metadata files that exclude files from a build. 00029 These rules are stored as `fnmatch` patterns in text in a files named `.mbedignore`. 00030 """ 00031 00032 def __init__(self): 00033 self._ignore_patterns = [] 00034 self._ignore_regex = re.compile("$^") 00035 00036 def is_ignored (self, file_path): 00037 """Check if file path is ignored by any .mbedignore thus far""" 00038 return self._ignore_regex .match(normcase(file_path)) 00039 00040 def add_ignore_patterns (self, in_name, patterns): 00041 """Ignore all files and directories matching the paterns in 00042 directories named by in_name. 00043 00044 Positional arguments: 00045 in_name - the filename prefix that this ignore will apply to 00046 patterns - the list of patterns we will ignore in the future 00047 """ 00048 if in_name == ".": 00049 self._ignore_patterns .extend(normcase(p) for p in patterns) 00050 else: 00051 self._ignore_patterns .extend( 00052 normcase(join(in_name, pat)) for pat in patterns) 00053 if self._ignore_patterns : 00054 self._ignore_regex = re.compile("|".join( 00055 fnmatch.translate(p) for p in self._ignore_patterns )) 00056 00057 def add_mbedignore (self, in_name, filepath): 00058 """Add a series of patterns to the ignored paths 00059 00060 Positional arguments: 00061 in_name - the filename prefix that this ignore will apply to 00062 patterns - the list of patterns we will ignore in the future 00063 """ 00064 with open (filepath) as f: 00065 patterns = [l.strip() for l in f 00066 if l.strip() != "" and not l.startswith("#")] 00067 self.add_ignore_patterns (in_name, patterns) 00068 00069
Generated on Tue Jul 12 2022 17:12:47 by
1.7.2