-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFLK.py
68 lines (61 loc) · 2.45 KB
/
FLK.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
62
63
64
65
66
67
68
from lxml import etree
from io import StringIO
import sys
import zipfile
XsdHM='ReestrMO.xsd'
XsdLM='RestrMOPers.xsd'
XsdVM='ReestrMOMEDPers.xsd'
XsdOM='ReestrOM.xsd'
def TestFLK(ArchivName):
Archive=zipfile.ZipFile(ArchivName)
for files in Archive.namelist():
XmlData=Archive.read(files)
if files[0]=='H':
with open(XsdHM, 'r') as SchemaFile:
SchemaToCheck = SchemaFile.read()
XMLSchemaDoc = etree.parse(XsdHM)
elif files[0]=='L':
with open(XsdLM, 'r') as SchemaFile:
SchemaToCheck = SchemaFile.read()
XMLSchemaDoc = etree.parse(XsdLM)
elif files[0]=='V':
with open(XsdVM, 'r') as SchemaFile:
SchemaToCheck = SchemaFile.read()
XMLSchemaDoc = etree.parse(XsdVM)
elif files[0]=='O':
with open(XsdOM, 'r') as SchemaFile:
SchemaToCheck = SchemaFile.read()
XMLSchemaDoc = etree.parse(XsdOM)
XMLSchema = etree.XMLSchema(XMLSchemaDoc)
try:
Doc = etree.fromstring(XmlData)
print('Файл '+files+' сформирован без ошибок.')
# check for file IO error
except IOError:
print('Ошибка чтения файла '+files)
# check for XML syntax errors
except etree.XMLSyntaxError as err:
print('Ошибка в синтаксисе XML файла '+files)
with open('error_schema.log', 'a') as error_log_file:
error_log_file.write(str(err.error_log))
quit()
except:
print('Неизвестная ошибка.')
quit()
try:
XMLSchema.assertValid(Doc)
print('Проверка файла '+files+' по XSD схеме завершена успешно.')
except etree.DocumentInvalid as err:
print('Ошибки валидации '+files+' по XSD схеме.')
with open('error_schema.log', 'a') as error_log_file:
error_log_file.write(str(err.error_log))
quit()
except:
print('Неизвестная ошибка.')
quit()
Archive.close()
if __name__=='__main__':
if len (sys.argv) == 1:
print ("Не указан файл на тестирование!")
else:
TestFLK(sys.argv[1])