oceanbase

Форк
0
/
reset_upgrade_scripts.py 
56 строк · 2.2 Кб
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3

4
import os
5

6
def clear_action_codes(action_filename_list, action_begin_line, \
7
    action_end_line, is_special_upgrade_code):
8
  char_enter = '\n'
9
  for action_filename in action_filename_list:
10
    new_action_file_lines = []
11
    action_file = open(action_filename, 'r')
12
    action_file_lines = action_file.readlines()
13
    is_action_codes = False
14
    for action_file_line in action_file_lines:
15
      if is_action_codes and action_file_line == (action_end_line + char_enter):
16
        is_action_codes = False
17
      if not is_action_codes:
18
        new_action_file_lines.append(action_file_line)
19
      if not is_action_codes and action_file_line == (action_begin_line + char_enter):
20
        is_action_codes = True
21
    action_file.close()
22
    new_action_file = open(action_filename, 'w')
23
    for new_action_file_line in new_action_file_lines:
24
      if is_special_upgrade_code:
25
        if new_action_file_line == (action_end_line + char_enter):
26
          new_action_file.write('  return\n')
27
      new_action_file.write(new_action_file_line)
28
    new_action_file.close()
29

30
def regenerate_upgrade_script():
31
  print('\n=========run gen_upgrade_scripts.py, begin=========\n')
32
  info = os.popen('./gen_upgrade_scripts.py;')
33
  print(info.read())
34
  print('\n=========run gen_upgrade_scripts.py, end=========\n')
35

36
if __name__ == '__main__':
37
  action_begin_line = '####========******####======== actions begin ========####******========####'
38
  action_end_line = '####========******####========= actions end =========####******========####'
39
  action_filename_list = \
40
      [\
41
      'normal_ddl_actions_pre.py',\
42
      'normal_ddl_actions_post.py',\
43
      'normal_dml_actions_pre.py',\
44
      'normal_dml_actions_post.py',\
45
      'each_tenant_dml_actions_pre.py',\
46
      'each_tenant_dml_actions_post.py',\
47
      'each_tenant_ddl_actions_post.py'\
48
      ]
49
  special_upgrade_filename_list = \
50
      [\
51
      'special_upgrade_action_pre.py',\
52
      'special_upgrade_action_post.py'
53
      ]
54
  clear_action_codes(action_filename_list, action_begin_line, action_end_line, False)
55
  clear_action_codes(special_upgrade_filename_list, action_begin_line, action_end_line, True)
56
  regenerate_upgrade_script()
57

58

59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.