-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCmdLineGetSafetyCrc.py
61 lines (46 loc) · 1.98 KB
/
CmdLineGetSafetyCrc.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''
* File: CmdLineGetSafetyCrc.py
* Copyright (c) 2023 Loupe
* https://loupe.team
*
* This file is part of ASPython, licensed under the MIT License.
'''
"""
@title CmdLineGetVersion
@description This python script takes in command line arguments
and retrieves the CRC of the specified safe application
0.1.0 - Synchronize all script versions
0.0.1 - Initial release
"""
# Python Modules
import argparse
import os.path
import shutil
import sys
import re
from typing import Dict, Tuple, Sequence, Union, List, Optional
# External Modules
import ASTools
import _version
def main():
# Parse arguments from the command line
parser = argparse.ArgumentParser(description='Retrieve the CRC for an SafeApplication.')
parser.add_argument('project', type=str, help='Path to AS project')
parser.add_argument('-c','--configuration', nargs='+', type=str, help='AS configuration(s)')
parser.add_argument('-sa','--safeApp', type=str, help='Location of the safe application binaries')
parser.add_argument('-v', '--version', action='version', version='%(prog)s {version}'.format(version=_version.__version__))
args = parser.parse_args()
project = ASTools.Project(args.project)
# Find the name of the PLC folder (the one that's right under the configuration name folder).
configurationDirectory = os.path.join(project.dirPath, 'Physical', args.configuration[0])
plcDirectory = [name for name in os.listdir(configurationDirectory) if os.path.isdir(os.path.join(configurationDirectory, name))]
# Truncate extension off of SfApp.
splitSafetyApp = args.safeApp.split('.')
# Create the full relative path to the obscure file.
relativePath = os.path.join('Physical', args.configuration[0], plcDirectory[0], 'MappSafety', splitSafetyApp[0], 'C', 'PLC', 'R', 'CPU', 'CPU.ini')
# And retrieve the CRC value.
safetyCrc = project.getIniValue(relativePath, 'CRC', 'PROJECT')
sys.stdout.write(safetyCrc)
sys.exit(0)
if __name__ == "__main__":
main()