Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 1 | """ |
| 2 | Copyright (c) 2019 Cypress Semiconductor Corporation |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | """ |
| 16 | |
| 17 | import subprocess |
| 18 | import sys |
| 19 | |
INFINEON\DovhalA | 3b578f3 | 2024-11-29 01:06:04 +0200 | [diff] [blame^] | 20 | package = 'edgeprotecttools' |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 21 | |
| 22 | def find_cysectools(package_name): |
| 23 | |
| 24 | """ |
| 25 | Check if package exist in system and return its location if it does |
| 26 | """ |
| 27 | |
| 28 | pip_show = subprocess.Popen([sys.executable, '-m', 'pip', 'show', package], |
| 29 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 30 | |
| 31 | stdout = pip_show.communicate()[0] |
| 32 | rc = pip_show.wait() |
| 33 | |
| 34 | if (rc != 0): |
| 35 | print("No package with name " + package + " found") |
| 36 | exit(1) |
| 37 | else: |
| 38 | pip_show_info = stdout.decode("utf-8").splitlines() |
| 39 | |
| 40 | for line in pip_show_info: |
| 41 | if 'Location:' in line: |
| 42 | location = line.replace('Location: ', '') |
| 43 | |
| 44 | if sys.platform == 'win32': |
| 45 | return location.replace('\\','/') |
| 46 | else: |
| 47 | return location |
| 48 | |
| 49 | def main(): |
| 50 | """ |
| 51 | Call function and print output |
| 52 | """ |
| 53 | cysecuretools_path = find_cysectools(package) |
| 54 | |
| 55 | print(cysecuretools_path) |
| 56 | |
| 57 | if __name__ == "__main__": |
| 58 | main() |