2 # Copyright 2017 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
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
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an 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.
20 from lib
.util
import Util
21 from lib
.parser
import Parser
27 logging
.basicConfig(level
=logging
.DEBUG
)
28 log
= logging
.getLogger('OsmParser')
30 class OsmParser(Parser
):
31 """Parser methods for osm project type
36 super(OsmParser
, self
).__init
__()
39 def importprojectdir(cls
,dir_project
, file_type
):
40 """Imports all descriptor files under a given folder
42 this method is specific for Osm project type
54 for desc_type
in project
:
55 cur_type_path
= os
.path
.join(dir_project
, desc_type
.upper())
56 log
.debug(cur_type_path
)
57 if os
.path
.isdir(cur_type_path
):
58 for file in glob
.glob(os
.path
.join(cur_type_path
, '*.'+file_type
)):
59 if file_type
== 'json':
60 project
[desc_type
][os
.path
.basename(file).split('.')[0]] = Util
.loadjsonfile(file)
61 elif file_type
== 'yaml':
62 project
[desc_type
][os
.path
.basename(file).split('.')[0]] = Util
.loadyamlfile(file)
65 for vertices_file
in glob
.glob(os
.path
.join(dir_project
, '*.json')):
66 if os
.path
.basename(vertices_file
) == 'vertices.json':
67 project
['positions']['vertices'] = Util
.loadjsonfile(vertices_file
)
72 def importprojectfiles(cls
, file_dict
):
73 """Imports descriptors (extracted from the new project POST)
75 The keys in the dictionary are the file types
83 for desc_type
in project
:
84 if desc_type
in file_dict
:
85 files_desc_type
= file_dict
[desc_type
]
86 for file in files_desc_type
:
87 project
[desc_type
][os
.path
.splitext(file.name
)[0]] = json
.loads(file.read())