1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2024 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import os
18import subprocess
19import argparse
20import time
21from datetime import datetime
22
23
24def verify_abc_files(folder_path, verifier_path):
25    total_count = 0
26    success_count = 0
27    failure_count = 0
28
29    start_time = time.time()
30
31    for root, _, files in os.walk(folder_path):
32        for file in files:
33            if not file.endswith('.abc'):
34                continue
35            total_count += 1
36            file_path = os.path.join(root, file)
37            command = [verifier_path, "--input_file", file_path]
38            result = subprocess.run(command, shell=False)
39
40            if result.returncode == 0:
41                success_count += 1
42                print(f"Success: {file_path}")
43            else:
44                failure_count += 1
45                print(f"Failure: {file_path}")
46
47    end_time = time.time()
48    elapsed_time = end_time - start_time
49    completion_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
50
51    print(f"Total .abc files: {total_count}")
52    print(f"Success: {success_count}")
53    print(f"Failure: {failure_count}")
54    print(f"Execution time: {elapsed_time:.2f} seconds")
55    print(f"Completion time: {completion_time}")
56
57if __name__ == "__main__":
58    parser = argparse.ArgumentParser(description="Verify .abc files using ark_verifier tool.")
59    parser.add_argument("--folder_path", type=str, required=True, help="Path to the folder containing .abc files")
60    parser.add_argument("--verifier_path", type=str, required=True, help="Path to the ark_verifier tool")
61
62    args = parser.parse_args()
63
64    verify_abc_files(args.folder_path, args.verifier_path)
65