2021-10-09 19:56:29 +02:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
# local imports
|
2021-10-10 11:33:30 +02:00
|
|
|
from .base import (
|
|
|
|
Data,
|
|
|
|
data_dir,
|
|
|
|
)
|
2021-10-09 19:56:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Meta(Data):
|
|
|
|
|
|
|
|
def __init__(self, path='.'):
|
|
|
|
super(Meta, self).__init__()
|
|
|
|
self.name = None
|
2021-10-09 20:37:54 +02:00
|
|
|
self.contact = {}
|
2021-10-09 19:56:29 +02:00
|
|
|
self.path = path
|
|
|
|
self.meta_path = os.path.join(self.path, 'meta.json')
|
|
|
|
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
super(Meta, self).load()
|
|
|
|
|
2021-10-09 20:37:54 +02:00
|
|
|
f = open(self.meta_path, 'r')
|
|
|
|
o = json.load(f)
|
2021-10-09 19:56:29 +02:00
|
|
|
f.close()
|
|
|
|
|
2021-10-09 20:37:54 +02:00
|
|
|
self.name = o['name']
|
|
|
|
self.contact = o['contact']
|
2021-10-09 19:56:29 +02:00
|
|
|
|
|
|
|
self.inited = True
|
|
|
|
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
super(Meta, self).start()
|
|
|
|
|
|
|
|
meta_template_file_path = os.path.join(data_dir, 'meta_template_v{}.json'.format(self.version()))
|
|
|
|
|
|
|
|
f = open(meta_template_file_path)
|
|
|
|
o = json.load(f)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
f = open(self.meta_path, 'w')
|
|
|
|
json.dump(o, f)
|
|
|
|
f.close()
|
2021-10-09 20:37:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
2021-10-10 14:49:22 +02:00
|
|
|
s = "contact.name = {}\n".format(self.name)
|
2021-10-09 20:37:54 +02:00
|
|
|
|
|
|
|
for k in self.contact.keys():
|
|
|
|
if self.contact[k] == '':
|
|
|
|
continue
|
2021-10-10 14:49:22 +02:00
|
|
|
s += "contact.{} = {}\n".format(k.lower(), self.contact[k])
|
2021-10-09 20:37:54 +02:00
|
|
|
|
|
|
|
return s
|