srcanamdw_os/leavescan/test/LET/fl.py
changeset 0 83f4b4db085c
child 2 99082257a271
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 #!/usr/bin/python
       
     2 import string
       
     3 import sys
       
     4 import os
       
     5 from os import listdir
       
     6 from os.path import isdir
       
     7 
       
     8 
       
     9 dir_path=['.']
       
    10 
       
    11 os_type = 'unix'
       
    12 if sys.platform.lower().startswith('win'):
       
    13     os_type = 'windows'
       
    14 
       
    15 TRUE = 1
       
    16 FALSE = 0
       
    17 
       
    18 def correct_slashes(value):
       
    19     """
       
    20     This module corrects slashes in pathnames supplied to it.
       
    21     """
       
    22 
       
    23     while value.find('\\\\') != -1:
       
    24         value = value.replace('\\\\', '\\')
       
    25         continue
       
    26 
       
    27     while value.find('//') != -1:
       
    28         value = value.replace('//', '/')
       
    29         continue
       
    30     if os_type == 'windows' and '/' in value:
       
    31         while value.find('/') != -1:
       
    32             value = value.replace('/', '\\')
       
    33             continue
       
    34     return value
       
    35 
       
    36 def filter(file_name):
       
    37 	if file_name.endswith('.cpp'):
       
    38 		return TRUE
       
    39 	else:
       
    40 		return FALSE
       
    41 
       
    42 def print_files(dir_path):
       
    43 	if not os.path.exists(dir_path):
       
    44 		return
       
    45 	file_list = os.listdir(dir_path)
       
    46 	for cur_file in file_list:
       
    47 		if cur_file.endswith('\\') or cur_file.endswith('/'):
       
    48 			cur_file = dir_path+cur_file
       
    49 		else:
       
    50 			cur_file = dir_path+'\\'+cur_file	
       
    51 		if not os.path.isdir(cur_file):
       
    52 			if os.path.exists(cur_file) and filter(cur_file)== TRUE:
       
    53 				print correct_slashes(cur_file)
       
    54 		else:
       
    55 			print_files(cur_file)
       
    56 
       
    57 if __name__ == '__main__':
       
    58 	argv = sys.argv[1:]
       
    59 	if len(argv) >0:
       
    60 		dir_path = argv
       
    61 	for cur_path in dir_path:
       
    62 		print_files(os.path.abspath(cur_path))