mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
Generated by com2ann (slightly patched to avoid also converting assignment type annotations, which require Python 3.6), followed by some manual whitespace adjustment, and six fixes for runtime issues: - def __init__(self, token: Token, parent: Optional[Node]) -> None: + def __init__(self, token: Token, parent: "Optional[Node]") -> None: -def main(options: argparse.Namespace) -> NoReturn: +def main(options: argparse.Namespace) -> "NoReturn": -def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]: +def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]": -def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None: +def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None: -def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool: +def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool: - method_kwarg_pairs: List[FuncKwargPair], + method_kwarg_pairs: "List[FuncKwargPair]", Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
77 lines
2.8 KiB
Python
Executable File
77 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import glob
|
|
import os
|
|
import sys
|
|
import fileinput
|
|
import re
|
|
|
|
from typing import List
|
|
|
|
def validate_order(order: List[int], length: int) -> None:
|
|
if len(order) != length:
|
|
print("Please enter the sequence of all the conflicting files at once")
|
|
sys.exit(1)
|
|
|
|
for i in order:
|
|
if i > length or i < 1 or order.count(i) > 1:
|
|
print("Incorrect input")
|
|
sys.exit(1)
|
|
|
|
def renumber_migration(conflicts: List[str], order: List[int], last_correct_migration: str) -> None:
|
|
stack = [] # type: List[str]
|
|
for i in order:
|
|
if conflicts[i-1][0:4] not in stack:
|
|
stack.append(conflicts[i-1][0:4])
|
|
else:
|
|
# Replace dependencies with the last correct migration
|
|
file = fileinput.FileInput('zerver/migrations/' + conflicts[i-1], inplace=True)
|
|
for line in file:
|
|
print(re.sub(r'[\d]+(_[a-z0-9]+)+', last_correct_migration, line), end='')
|
|
|
|
# Rename the migration indexing at the end
|
|
new_name = conflicts[i-1].replace(conflicts[i-1][0:4],
|
|
'%04d' % (int(last_correct_migration[0:4]) + 1,))
|
|
os.rename('zerver/migrations/' + conflicts[i-1], 'zerver/migrations/' + new_name)
|
|
|
|
last_correct_migration = new_name.replace('.py', '')
|
|
|
|
def resolve_conflicts(conflicts: List[str], files_list: List[str]) -> None:
|
|
print("Conflicting migrations:")
|
|
for i in range(0, len(conflicts)):
|
|
print(str(i+1) + '. ' + conflicts[i])
|
|
|
|
order_input = input("Enter the order in which these migrations should be arranged: ")
|
|
order = list(map(int, order_input.split()))
|
|
validate_order(order, len(conflicts))
|
|
|
|
last_correct_migration = conflicts[order[0] - 1]
|
|
|
|
last_correct_migration = last_correct_migration.replace('.py', '')
|
|
renumber_migration(conflicts, order, last_correct_migration)
|
|
|
|
if __name__ == '__main__':
|
|
|
|
while True:
|
|
conflicts = [] # type: List[str]
|
|
stack = [] # type: List[str]
|
|
files_list = [os.path.basename(path) for path in glob.glob("zerver/migrations/????_*.py")]
|
|
file_index = [file[0:4] for file in files_list]
|
|
|
|
for file in file_index:
|
|
migration_number = file[0:4]
|
|
counter = file_index.count(migration_number)
|
|
|
|
# There are 2 migrations 0209 because of a security
|
|
# release requiring a migration.
|
|
if counter > 1 and file[0:4] not in stack and migration_number != "0209":
|
|
conflicts += [file_name for file_name in files_list if file_name.startswith(migration_number)]
|
|
stack.append(migration_number)
|
|
|
|
if len(conflicts) > 0:
|
|
resolve_conflicts(conflicts, files_list)
|
|
else:
|
|
break
|
|
|
|
print("All conflicts resolved")
|