|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# Copyright 2025 ROBOTIS CO., LTD. |
| 4 | +# |
| 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 | +# |
| 17 | +# Author: Woojin Wie |
| 18 | + |
| 19 | +import os |
| 20 | +import hashlib |
| 21 | +from collections import defaultdict |
| 22 | + |
| 23 | +MODEL_DIR = os.path.join(os.path.dirname(__file__), '..', 'param', 'dxl_model') |
| 24 | + |
| 25 | +# Get all files in the model directory |
| 26 | +files = [f for f in os.listdir(MODEL_DIR) if os.path.isfile(os.path.join(MODEL_DIR, f))] |
| 27 | + |
| 28 | +# Dictionary to map file content hash to list of files |
| 29 | +hash_to_files = defaultdict(list) |
| 30 | + |
| 31 | +def extract_control_table(filepath): |
| 32 | + with open(filepath, 'r', encoding='utf-8') as f: |
| 33 | + lines = f.readlines() |
| 34 | + in_control_table = False |
| 35 | + control_table_lines = [] |
| 36 | + for line in lines: |
| 37 | + if line.strip() == '[control table]': |
| 38 | + in_control_table = True |
| 39 | + continue |
| 40 | + if in_control_table: |
| 41 | + if line.startswith('[') and not line.strip().startswith('[control table]'): |
| 42 | + break |
| 43 | + if line.strip() == '': |
| 44 | + continue |
| 45 | + control_table_lines.append(line.strip()) |
| 46 | + return '\n'.join(control_table_lines) |
| 47 | + |
| 48 | +def control_table_hash(control_table_str): |
| 49 | + return hashlib.sha256(control_table_str.encode('utf-8')).hexdigest() |
| 50 | + |
| 51 | +for filename in files: |
| 52 | + path = os.path.join(MODEL_DIR, filename) |
| 53 | + control_table = extract_control_table(path) |
| 54 | + h = control_table_hash(control_table) |
| 55 | + hash_to_files[h].append(filename) |
| 56 | + |
| 57 | +# Print clusters of files with identical [control table] sections |
| 58 | +print('Clusters of files with identical [control table] sections:') |
| 59 | +for file_list in hash_to_files.values(): |
| 60 | + if len(file_list) > 1: |
| 61 | + print(', '.join(file_list)) |
| 62 | + |
| 63 | +# Print files with unique [control table] sections |
| 64 | +print('\nFiles with unique [control table] sections:') |
| 65 | +for file_list in hash_to_files.values(): |
| 66 | + if len(file_list) == 1: |
| 67 | + print(file_list[0]) |
0 commit comments