File size: 1,260 Bytes
76a137a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import argparse
import os
import subprocess


def execute_in_directory(directory, command):
    original_dir = os.getcwd()
    try:
        os.chdir(directory)
        result = subprocess.run(
            command,
            shell=True,
            check=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True
        )
        # print(f"success:\n{result.stdout}")
        return result.returncode
    except subprocess.CalledProcessError as e:
        print(f"error:\n{e.stderr}")
        return e.returncode
    finally:
        os.chdir(original_dir)


def main(root_dir):
    for root, _, files in os.walk(root_dir):
        if "scene.usd" in files:
            if os.path.exists(os.path.join(root, "SubUSDs")):
                bash_command = "rm ./SubUSDs"
                execute_in_directory(root, bash_command)

            bash_command = "ln -s ../SubUSDs ./SubUSDs"
            execute_in_directory(root, bash_command)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='add soft link file')
    parser.add_argument('val_dataset_path', 
                       type=str,
                       help='dataset path')
    args = parser.parse_args()
    main(args.val_dataset_path)