update_list.py 1.63 KB
import fileinput
import re
import os

#global hasListView
#hasListView = False

global checkDir

checkDir = './js'

def matchText(text):
    if re.match(r'^.*ListView,.*', text):
        return True
    else:
        return False

def matchRnText(text):
    if re.match(r'^.*\'react-native\'', text):
        return True
    elif re.match(r'^.*\"react-native\"', text):
        return True
    elif re.match(r'^.*ReactNative', text):
        return True
    else:
        return False



def updatelist():
    for currentpath, folders, files in os.walk(checkDir):
        for file in files:
            print(os.path.join(currentpath, file))
            fullpath = os.path.join(currentpath, file)
            hasListView = False
            toBeWrite = True
            if file.endswith('.js'):
                for line in fileinput.input(fullpath, inplace=True):
                    if matchText(line):
                        hasListView = True
                        print(line.replace('ListView,', ''), end='')
                        if matchRnText(line) and toBeWrite:
                            print('import ListView from \'deprecated-react-native-listview\'')
                            toBeWrite = False
                            continue
                    elif matchRnText(line) and hasListView and toBeWrite:
                        print(line, end='')
                        print('import ListView from \'deprecated-react-native-listview\'')
                        toBeWrite = False
                        continue
                    else:
                        print(line, end='')
            else:
                pass


#updatelist()