📅 2024-06-05T20:52:01.740Z
👁️ 17 katselukertaa
🔓 Julkinen

import sys
import os

def parse_filename(filename):
    # Parse filename up to before the last underscore
    parsed_name = filename.rsplit('_', 1)[0]
    # Check if the last 10 characters contain 'ACK' or 'CAN'
    if 'ACK' in filename[-10:] or 'CAN' in filename[-10:]:
        ack_or_can = 'ACK_OR_CAN=' + filename[-10:]
        ack_or_can = ''
    return parsed_name, ack_or_can

def update_config(filename):
    # Get the parsed name and ACK/CAN status
    parsed_name, ack_or_can = parse_filename(filename)
    # Read the existing .config file
    config_file_path = '/path/to/config/file.config'  # Specify the path to your .config file
    with open(config_file_path, 'r') as config_file:
        config_lines = config_file.readlines()
    # Update the File_Desc field with the parsed name
    for i, line in enumerate(config_lines):
        if line.startswith('File_Desc='):
            config_lines[i] = 'File_Desc=' + parsed_name + '\n'
    # Add ACK_OR_CAN field if it exists
    if ack_or_can:
        config_lines.append(ack_or_can + '\n')
    # Write the updated config file
    with open(config_file_path, 'w') as config_file:

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python script.py <filename>")
    filename = sys.argv[1]