|
|
|
@ -3,6 +3,7 @@ from subprocess import run, PIPE |
|
|
|
|
from argparse import ArgumentParser, ArgumentTypeError |
|
|
|
|
from datetime import datetime, timedelta, timezone |
|
|
|
|
from sys import stdout as sys_stdout |
|
|
|
|
from re import compile as re_compile, Pattern |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_command(args: list, remote: str = None, ssh_args: list = None, check: bool = True, |
|
|
|
@ -29,7 +30,7 @@ def occ(php: str, path: str, args: list, remote: str = None, ssh_args: list = No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_users(php: str, path: str, remote: str = None, ssh_args: list = None, |
|
|
|
|
last_seen_limit: int = None) -> list: |
|
|
|
|
last_seen_limit: int = None, exclude_users: Pattern = None) -> list: |
|
|
|
|
users = {} |
|
|
|
|
offset = 0 |
|
|
|
|
while True: |
|
|
|
@ -47,6 +48,10 @@ def get_users(php: str, path: str, remote: str = None, ssh_args: list = None, |
|
|
|
|
|
|
|
|
|
print(f"Got {len(users)} email filtered users") |
|
|
|
|
|
|
|
|
|
if exclude_users: |
|
|
|
|
users = {k: v for k, v in users.items() if not exclude_users.findall(k)} |
|
|
|
|
print(f"Got {len(users)} filtered users") |
|
|
|
|
|
|
|
|
|
if last_seen_limit: |
|
|
|
|
users = {k: v for k, v in users.items() |
|
|
|
|
if datetime.fromisoformat(v["last_seen"]) >= last_seen_limit} |
|
|
|
@ -56,20 +61,23 @@ def get_users(php: str, path: str, remote: str = None, ssh_args: list = None, |
|
|
|
|
return users |
|
|
|
|
|
|
|
|
|
def main(src_path: str, dest_path: str, src_php: str, dest_php: str, src_remote: str = None, |
|
|
|
|
dest_remote: str = None, ssh_args: list = None, days: int = 0): |
|
|
|
|
dest_remote: str = None, ssh_args: list = None, days: int = 0, exclude_users: str = None): |
|
|
|
|
if days != 0: |
|
|
|
|
last_seen_limit = datetime.now(timezone.utc)\ |
|
|
|
|
.replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(days=days) |
|
|
|
|
else: |
|
|
|
|
last_seen_limit = None |
|
|
|
|
|
|
|
|
|
if exclude_users: |
|
|
|
|
exclude_users = re_compile(exclude_users) |
|
|
|
|
|
|
|
|
|
src_data = occ(src_php, src_path, ["config:list", "--private"], remote=src_remote, |
|
|
|
|
ssh_args=ssh_args)["system"]["datadirectory"] |
|
|
|
|
|
|
|
|
|
dest_data = occ(dest_php, dest_path, ["config:list", "--private"], remote=dest_remote, |
|
|
|
|
ssh_args=ssh_args)["system"]["firstrunmigrate_dir"] |
|
|
|
|
|
|
|
|
|
users = get_users(src_php, src_path, src_remote, ssh_args, last_seen_limit) |
|
|
|
|
users = get_users(src_php, src_path, src_remote, ssh_args, last_seen_limit, exclude_users) |
|
|
|
|
max_users = len(users) |
|
|
|
|
|
|
|
|
|
for idx, user in enumerate(users): |
|
|
|
@ -93,6 +101,7 @@ if __name__ == '__main__': |
|
|
|
|
parser.add_argument("--dest-remote", default=None) |
|
|
|
|
parser.add_argument("--ssh-args", default=[]) |
|
|
|
|
parser.add_argument("--days", "-d", type=int, default="0") |
|
|
|
|
parser.add_argument("--exclude-users", "-e", default=None) |
|
|
|
|
|
|
|
|
|
parser_args = parser.parse_args() |
|
|
|
|
|
|
|
|
@ -103,4 +112,5 @@ if __name__ == '__main__': |
|
|
|
|
parser_args.ssh_args = parser_args.ssh_args.split(" ") |
|
|
|
|
|
|
|
|
|
main(parser_args.src_path, parser_args.dest_path, parser_args.src_php, parser_args.dest_php, |
|
|
|
|
parser_args.src_remote, parser_args.dest_remote, parser_args.ssh_args, parser_args.days) |
|
|
|
|
parser_args.src_remote, parser_args.dest_remote, parser_args.ssh_args, parser_args.days, |
|
|
|
|
parser_args.exclude_users) |
|
|
|
|