58 lines
1.2 KiB
Python
58 lines
1.2 KiB
Python
# standard imports
|
|
import os
|
|
import json
|
|
|
|
# local imports
|
|
from .base import (
|
|
Data,
|
|
data_dir,
|
|
)
|
|
|
|
|
|
class Meta(Data):
|
|
|
|
def __init__(self, path='.'):
|
|
super(Meta, self).__init__()
|
|
self.name = None
|
|
self.contact = {}
|
|
self.path = path
|
|
self.meta_path = os.path.join(self.path, 'meta.json')
|
|
|
|
|
|
def load(self):
|
|
super(Meta, self).load()
|
|
|
|
f = open(self.meta_path, 'r')
|
|
o = json.load(f)
|
|
f.close()
|
|
|
|
self.name = o['name']
|
|
self.contact = o['contact']
|
|
|
|
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()
|
|
|
|
|
|
def __str__(self):
|
|
s = "contact.name = {}\n".format(self.name)
|
|
|
|
for k in self.contact.keys():
|
|
if self.contact[k] == '':
|
|
continue
|
|
s += "contact.{} = {}\n".format(k.lower(), self.contact[k])
|
|
|
|
return s
|