|
| 1 | +importos |
| 2 | +importre |
| 3 | +importshutil |
| 4 | + |
| 5 | + |
| 6 | +# Create a folder if not exists |
| 7 | +defcreateFolder(path): |
| 8 | +try: |
| 9 | +ifnotos.path.exists(path): |
| 10 | +os.makedirs(path) |
| 11 | +exceptOSError: |
| 12 | +print("Error: Creating directory. "+path) |
| 13 | + |
| 14 | + |
| 15 | +# Delete targeted folder recursively |
| 16 | +defdeleteFolder(path): |
| 17 | +ifos.path.isdir(path): |
| 18 | +shutil.rmtree(path,ignore_errors=True) |
| 19 | + |
| 20 | + |
| 21 | +# copy src folder recursively to dest |
| 22 | +defcopyFolder(src,dest,ign_patt=set()): |
| 23 | +try: |
| 24 | +ifos.path.isdir(src): |
| 25 | +shutil.copytree(src,dest,ignore=shutil.ignore_patterns(*ign_patt)) |
| 26 | +exceptOSErrorase: |
| 27 | +print("Error: Folder %s not copied. %s"%src,e) |
| 28 | + |
| 29 | + |
| 30 | +defgenSTM32List(path,pattern): |
| 31 | +stm32_list= []# Serie |
| 32 | +dir_pattern=re.compile("^STM32(.*)xx_HAL_Driver$",re.IGNORECASE) |
| 33 | + |
| 34 | +ifpatternisnotNone: |
| 35 | +serie_pattern=re.compile(pattern,re.IGNORECASE) |
| 36 | +else: |
| 37 | +serie_pattern=re.compile(".*",re.IGNORECASE) |
| 38 | + |
| 39 | +forfileinos.listdir(path): |
| 40 | +res=dir_pattern.match(file) |
| 41 | +ifresandserie_pattern.search(res.group(1)): |
| 42 | +stm32_list.append(res.group(1)) |
| 43 | +stm32_list.sort() |
| 44 | +returnstm32_list |