|
|
|
@ -7,31 +7,35 @@ from re import compile as re_compile |
|
|
|
|
|
|
|
|
|
def main(path : str, php :str, output_groups : str, output_group_folders : str, exclude_group: str): |
|
|
|
|
output_groups = Path(output_groups) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if output_group_folders: |
|
|
|
|
output_group_folders = Path(output_group_folders) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if exclude_group: |
|
|
|
|
exclude_group = re_compile(exclude_group) |
|
|
|
|
|
|
|
|
|
r = run([php, "occ", "-V"], cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
version = list(map(int, r.stdout.decode().split(" ")[-1].split("."))) |
|
|
|
|
|
|
|
|
|
r = run([php, "occ", "config:list", "--private", "--output", "json"], cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
config = loads(r.stdout.decode().strip()) |
|
|
|
|
|
|
|
|
|
out = run([php, "occ", "-V"], cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
version = list(map(int, out.stdout.decode().split(" ")[-1].split("."))) |
|
|
|
|
|
|
|
|
|
out = run([php, "occ", "config:list", "--private", "--output", "json"], cwd=path, check=True, |
|
|
|
|
stdout=PIPE, stderr=PIPE) |
|
|
|
|
config = loads(out.stdout.decode().strip()) |
|
|
|
|
|
|
|
|
|
groups = {} |
|
|
|
|
offset = 0 |
|
|
|
|
if version[0] >= 22: |
|
|
|
|
while True: |
|
|
|
|
r = run([php, "occ", "group:list", "--offset", str(offset), "--info", "--output", "json"], cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
new_groups = loads(r.stdout.decode().strip()) |
|
|
|
|
out = run( |
|
|
|
|
[php, "occ", "group:list", "--offset", str(offset), "--info", "--output", "json"], |
|
|
|
|
cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
new_groups = loads(out.stdout.decode().strip()) |
|
|
|
|
if not new_groups: |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for group in new_groups.keys(): |
|
|
|
|
r = run([php, "occ", "group:info", group, "--output", "json"], cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
infos = loads(r.stdout.decode().strip()) |
|
|
|
|
out = run([php, "occ", "group:info", group, "--output", "json"], |
|
|
|
|
cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
infos = loads(out.stdout.decode().strip()) |
|
|
|
|
new_groups[group]["displayName"] = infos["displayName"] |
|
|
|
|
|
|
|
|
|
groups.update(new_groups) |
|
|
|
@ -45,32 +49,37 @@ def main(path : str, php :str, output_groups : str, output_group_folders : str, |
|
|
|
|
db_password = config["system"]["dbpassword"] |
|
|
|
|
db_name = config["system"]["dbname"] |
|
|
|
|
db_prefix = config["system"]["dbtableprefix"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if db_type == "mysql": |
|
|
|
|
r = run(["mysql", "-B", "-r", "--disable-column-names", "-h", db_host, "-P", db_port, "-u", db_user, f"-p{db_password}", "-e", f"select JSON_OBJECT('gid', gid, 'displayname', displayname) from {db_prefix}groups", db_name], cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
for l in map(loads, filter(lambda l: l != "", r.stdout.decode().split("\n"))): |
|
|
|
|
groups[l["gid"]] = {"displayName": l["displayname"]} |
|
|
|
|
out = run(["mysql", "-B", "-r", "--disable-column-names", "-h", db_host, "-P", db_port, |
|
|
|
|
"-u", db_user, f"-p{db_password}","-e", |
|
|
|
|
"select JSON_OBJECT('gid', gid, 'displayname', displayname) "\ |
|
|
|
|
f"from {db_prefix}groups", db_name], |
|
|
|
|
cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
for line in map(loads, filter(lambda l: l != "", out.stdout.decode().split("\n"))): |
|
|
|
|
groups[line["gid"]] = {"displayName": line["displayname"]} |
|
|
|
|
elif db_type == "psql": |
|
|
|
|
pass |
|
|
|
|
elif db_type == "sqlite": |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
print(f"Got {len(groups)} groups") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if exclude_group: |
|
|
|
|
groups = {k: v for k, v in groups.items() if not exclude_group.findall(k)} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f"Got {len(groups)} filtered groups") |
|
|
|
|
|
|
|
|
|
with output_groups.open("w") as f: |
|
|
|
|
dump({k: v["displayName"] for (k, v) in groups.items()}, f) |
|
|
|
|
with output_groups.open("w", encoding="UTF-8") as file: |
|
|
|
|
dump({k: v["displayName"] for (k, v) in groups.items()}, file) |
|
|
|
|
|
|
|
|
|
if output_group_folders: |
|
|
|
|
r = run([php, "occ", "groupfolders:list", "--output", "json"], cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
group_folders = loads(r.stdout.decode().strip()) |
|
|
|
|
|
|
|
|
|
with output_group_folders.open("w") as f: |
|
|
|
|
dump(group_folders, f) |
|
|
|
|
out = run([php, "occ", "groupfolders:list", "--output", "json"], |
|
|
|
|
cwd=path, check=True, stdout=PIPE, stderr=PIPE) |
|
|
|
|
group_folders = loads(out.stdout.decode().strip()) |
|
|
|
|
|
|
|
|
|
with output_group_folders.open("w", encoding="UTF-8") as file: |
|
|
|
|
dump(group_folders, file) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
@ -82,5 +91,5 @@ if __name__ == '__main__': |
|
|
|
|
parser.add_argument("--exclude-group", "-e", default=None) |
|
|
|
|
|
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main(args.path, args.php, args.output_groups, args.output_group_folders, args.exclude_group) |
|
|
|
|