2 ################################################################################
3 # Copyright 2021 highstreet technologies GmbH
5 # Licensed under the Apache License, Version 2.0 (the 'License');
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an 'AS IS' BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 ################################################################################
19 # A selection of common methods
26 from pathlib import Path
28 def getInitData(domain):
29 currentTime = datetime.datetime.utcnow()
30 dir = os.path.dirname(os.path.realpath(__file__))
33 result['domain']= domain
34 result['directory']= dir
35 result['outdir']= dir + '/json/examples'
36 result['fqdn']= socket.getfqdn()
37 result['timestamp']= int(currentTime.timestamp()*1000000)
38 result['eventTime']= currentTime.isoformat() + 'Z'
41 with open('config.yml', 'r') as stream:
43 result['config']= yaml.safe_load(stream)
44 except yaml.YAMLError as exc:
48 templateFileName = dir + '/json/templates/' + domain + '.json'
49 with open(templateFileName) as f:
50 result['body']= json.load(f)
53 Path(result["outdir"]).mkdir(parents=True, exist_ok=True)