Newer
Older
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#! /usr/bin/env python
# -*- Python -*-
####################################################################################################
#
# PyValentina - A Python implementation of Valentina Pattern Drafting Software
# Copyright (C) 2018 Salvaire Fabrice
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
####################################################################################################
from pathlib import Path
import yaml
import argparse
import json
####################################################################################################
parser = argparse.ArgumentParser(description='Extract Valentina Measurement')
parser.add_argument('valentina_path', metavar='ValentinaPath',
help='Valentina source path')
args = parser.parse_args()
####################################################################################################
TOPICS = {
'A': 'Direct Height',
'B': 'Direct Width',
'C': 'Indentation',
'D': 'Circumference and Arc',
'E': 'Vertical',
'F': 'Horizontal',
'G': 'Bust',
'H': 'Balance',
'I': 'Arm',
'J': 'Leg',
'K': 'Crotch and Rise',
'L': 'Hand',
'M': 'Foot',
'N': 'Head',
'O': 'Men & Tailoring',
'P': 'Historical & Specialty',
'Q': 'Patternmaking measurements',
}
####################################################################################################
cpp_file = Path(args.valentina_path).joinpath('src', 'libs', 'vpatterndb', 'vtranslatemeasurements.cpp')
# m = translate("VTranslateMeasurements", "height",
# "Name in a formula. Don't use math symbols and space in name!!!!");
# g = translate("VTranslateMeasurements", "Height: Total", "Full measurement name.");
# d = translate("VTranslateMeasurements", "Vertical distance from crown of head to floor.",
# "Full measurement description.");
# InitMeasurement(height_M, m, g, d, "A01");
codes = {}
names = {}
complete = False
with open(cpp_file, 'r') as fh:
offset = len('m = translate("VTranslateMeasurements", "')
for line in fh.readlines():
line = line.strip()
if line.startswith('m ='):
i = line.find('"', offset)
name = line[offset:i]
elif line.startswith('g ='):
i = line.find('"', offset)
full_name = line[offset:i]
elif line.startswith('d ='):
i = line.find('"', offset)
if i != -1:
description = line[offset:i]
else:
description = ''
complete = True
if not line.endswith(','):
complete = True
elif line.startswith('InitMeasurement'):
complete = False
i = line.find('"') + 1
if i:
j = line.find('"', i)
code = line[i:j]
description = description.replace('\\"', '"')
# measurements[code] = dict(name=name, full_name=full_name, description=description)
data = [name, full_name, description, 0]
codes[code] = data
names[name] = data
elif complete:
# ", "Full
i = line.find('"Full measurement description."')
if i == -1:
description += line[1:-2]
elif i > 0:
description += line[1:i-3]
complete = False
####################################################################################################
vit_file = Path(args.valentina_path).joinpath(
'src', 'app', 'share', 'tables', 'templates', 'template_all_measurements.vit')
with open(vit_file, 'r') as fh:
# <m name="height" value="0"/>
offset = len('<m name="')
for line in fh.readlines():
line = line.strip()
if line.startswith('<m'):
i = line.find('"', offset)
name = line[offset:i]
j = line.find('"', i+1) +1
k = line.find('"', j)
value = line[j:k]
if name not in names:
raise NameError('{} is missing'.format(name))
if value != '0':
if value.startswith('('):
value = value[1:-1]
names[name][3] = value
####################################################################################################
# Merge topics
data = {topic:{'description':description, 'measurements':{}} for topic, description in TOPICS.items()}
for code, code_dict in codes.items():
letter = code[0]
data[letter]['measurements'][code] = code_dict
#print(json.dumps(data, indent=True))
print(yaml.dump(data, default_flow_style=False, width=160))