Example #1
0
def word_to_word(text, file, search):
    root = sys.argv[0][:-14]
    if not os.path.isfile("{}word_list.csv".format(root)):
        return text
    wordList = File.readFile("{}word_list.csv".format(root), True)
    # find_listを開く
    if search:
        findListPath = "{}find_list.csv".format(root)
        if not os.path.isfile(findListPath):
            search = False
        with open(findListPath) as f:
            findList = [s.strip() for s in f.readlines()]

    textArr = text.splitlines()
    wordOut = []
    findOut = []
    for i, text in enumerate(textArr):
        for li in wordList:  # 文字列警告
            reObj = re.search(li[0], text)
            if reObj:
                wordOut.append([i + 1, reObj.start(), reObj.group(), li[1]])
        if search:  # 文字列探索
            for li in findList:
                reObj = re.search(li, text)
                if reObj:
                    findOut.append([i + 1, reObj.start(), li])
    for c in wordOut:
        print("\033[33mWARNING\033[0m: {}:{}:{}: ({}) => ({})".format(
            file, c[0], c[1], c[2], c[3]))
    for c in findOut:
        print("\033[36mFOUND!!\033[0m: {}:{}:{}: ({})".format(
            file, c[0], c[1], c[2]))
    return "\n".join(textArr)
Example #2
0
def file_search(root="/", dir="", search=False):
    ex_files_prot = File.readFile("%s/exclusion_list.csv" % (root)).split("\n")

    files = get_file_names(dir)

    # 除外リストに記載されていないファイルパス一覧
    valid_filepath = []

    for f in files:
        p = Path(f)
        is_exclusion = False
        for e in ex_files_prot:
            # 除外リストのファイルがない場合
            if not Path(e).exists():
                continue
            # 除外リストのファイルと一致した場合
            if p.samefile(e):
                is_exclusion = True
                break
        if not is_exclusion:
            valid_filepath.append(f)

    for file in valid_filepath:
        Conv.converter(file, search)
        print(file + " : \033[32mOK\033[0m")

    print("converter : \033[32mALL SUCCEEDED\033[0m")
Example #3
0
def main():
    #Lista de los tokens
    tokenList = []
    #Nombre del archivo
    file = readFile('demo.py')
    #Variable para concatenar la cadena leída
    expretion = ''
    #Variable para concatenar un operador
    operators = ''
    #Variable para identificar si es un string lo que se esta leyendo
    isString = False
    for c in file:
        #Completar el operador y en caso de que sea de longitud más de uno juntarlo
        if operators != '':
            if c in logic_operators or c in unary_operators:
                operators += c
            n = ['OPERATOR', operators]
            tokenList.append(n)
            operators = ''
        else:
            operators = ''
        #En caso de que encuentre una apertura de cadena " ' ' "
        if c in string_identifier:
            if not isString:
                isString = True
                expretion += c
            else:
                expretion += c
                tokenList.append(['STRING', expretion])
                isString = False
                expretion = ''

        #Parar si hay un espacio o un operador
        elif (c == ' ' or c in logic_operators or c in unary_operators
              or c in OP) and not isString:
            #Identifica y concatena unicamente si es un operador
            if c in logic_operators or c in unary_operators:
                operators += c
            #Identifica si la cadena es palabra reservada y la agrega a la lista de tokens
            if expretion in reserved_words:
                n = ['RESERVED', expretion]
                tokenList.append(n)
            #Identifica si la cadena es un numero y la agrega a la lista de tokens
            elif expretion.isdigit():
                n = ['CONSTANT', expretion]
                tokenList.append(n)
            #Identifica si la cadena es una palabra y la agrega a la lista de tokens
            elif expretion != '':
                n = ['NAME', expretion]
                tokenList.append(n)
            if c in OP:
                n = ['OP', c]
                tokenList.append(n)
            expretion = ''

        else:
            expretion += c

    printList(tokenList)
Example #4
0
def main(scan_n=0.15, trans_n=0.1, rot_n=.1):
    global INITIAL_HEADING, N, NTh

    global noise
    global NTh
    noise = (scan_n, trans_n, rot_n)
    INITIAL_HEADING = 0

    rd.readFile('trajectories_1.txt')
    makeWorld('grid1.txt', 3)

    N = 30
    NTh = N / 2
    known = True
    print 'Is Start Known: ', known

    print 'total iterations', len(
        rd.position), ' with ', N, ' number of particles'
    particleFilter(len(rd.position) - len(rd.position) + 1,
                   isStartKnown=known,
                   graph=True)
Example #5
0
def converter(file, search):
    text = File.readFile(file)

    if not search:
        # 数値の前後,行頭の英単語の後にスペースを入れる
        sc = SpaceConvert(text)
        text = sc.split_text()
        # ,を、に変更する
        text = dot_to_comma(text)
    # 指定した単語のWARNINGを出す
    text = word_to_word(text, file, search)

    with open(file, mode="w") as f:
        f.write(text)
def run():
    try:
        information = read_file.readFile("my_play.txt")
    except:
        information = []
    # set up the screen
    information = stringToList(information)
    screen = pygame.display.set_mode((1000, screenHeight))
    pygame.display.set_caption("Game")
    makeWhiteKeys()
    makeBlackKeys()
    # set up fallingPieces
    all_keys = all_whitekeys + all_blackkeys
    generateNotes(information, screen)
    while True:
        drawFast(screen)
        drawSlow(screen)
        FPS = data.FPS
        clock.tick(FPS)
        makePieceFall(screen, all_keys)
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                # press esc to return home
                if event.key == pygame.K_ESCAPE:
                    import home
                    home.run()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                if data.fastRect.collidepoint(pos):
                    # fast FPS is 120
                    print "fast"
                    data.FPS = 120
                elif data.slowRect.collidepoint(pos):
                    # set slow FPS to 20
                    print "slow"
                    data.FPS = 20
        pygame.display.update()
def run():
    try:
        information = read_file.readFile("my_play.txt")
    except:
        information = []
    # set up the screen
    information = stringToList(information)
    screen = pygame.display.set_mode((1000, screenHeight))
    pygame.display.set_caption("Game")
    makeWhiteKeys()
    makeBlackKeys()
    # set up fallingPieces
    all_keys = all_whitekeys + all_blackkeys
    generateNotes(information, screen)
    while True:
        drawFast(screen)
        drawSlow(screen)
        FPS = data.FPS
        clock.tick(FPS)
        makePieceFall(screen,all_keys)
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                # press esc to return home
                if event.key == pygame.K_ESCAPE:
                    import home
                    home.run()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                if data.fastRect.collidepoint(pos):
                    # fast FPS is 120
                    print "fast"
                    data.FPS = 120
                elif data.slowRect.collidepoint(pos):
                    # set slow FPS to 20
                    print "slow"
                    data.FPS = 20
        pygame.display.update()
Example #8
0
import sys
from read_file import readFile

file = sys.argv[1]

#read in file
content = readFile(file)

for line in content: