|
3 | 3 | import RFEM.dependencies # dependency check ahead of imports |
4 | 4 | import socket |
5 | 5 | import requests |
| 6 | +import xmltodict |
| 7 | +from urllib import request |
6 | 8 | from suds import WebFault |
7 | 9 | from suds.client import Client |
8 | 10 | from RFEM.enums import ObjectTypes, ModelType, AddOn |
@@ -42,14 +44,23 @@ def connectToServer(url=connectionGlobals.url, port=connectionGlobals.port): |
42 | 44 | a_socket.close() |
43 | 45 | sys.exit() |
44 | 46 |
|
45 | | - # Delete cached WSDL older than 1 day to reflect newer version of RFEM |
| 47 | + # Delete old cache if the version or mode doesn't correlate |
46 | 48 | connectionGlobals.cacheLoc = os.path.join(gettempdir(), 'WSDL') |
47 | | - currentTime = time.time() |
| 49 | + new_wsdl = request.urlopen(urlAndPort+'/wsdl') |
| 50 | + new_wsdl_data = new_wsdl.read() |
| 51 | + new_wsdl.close() |
| 52 | + new_tns = xmltodict.parse(new_wsdl_data)['definitions']['@targetNamespace'] |
| 53 | + |
48 | 54 | if os.path.exists(connectionGlobals.cacheLoc): |
49 | 55 | for file in os.listdir(connectionGlobals.cacheLoc): |
50 | 56 | filePath = os.path.join(connectionGlobals.cacheLoc, file) |
51 | | - if (currentTime - os.path.getmtime(filePath)) > 86400: |
52 | | - os.remove(filePath) |
| 57 | + if file.endswith('.xml'): |
| 58 | + with open(filePath,'r', encoding='utf-8') as old_wsdl: |
| 59 | + old_wsdl_data = old_wsdl.read() |
| 60 | + old_wsdl.close() |
| 61 | + old_tns = xmltodict.parse(old_wsdl_data)['definitions']['@targetNamespace'] |
| 62 | + if new_tns != old_tns: |
| 63 | + os.remove(filePath) |
53 | 64 |
|
54 | 65 | # Check for issues locally and remotely |
55 | 66 | try: |
|
0 commit comments