Aufgrund einer Störung des s3 Storage, könnten in nächster Zeit folgende GitLab Funktionen nicht zur Verfügung stehen: LFS, Container Registry, Job Artifacs, Uploads (Wiki, Bilder, Projekt-Exporte). Wir bitten um Verständnis. Es wird mit Hochdruck an der Behebung des Problems gearbeitet. Weitere Informationen zur Störung des Object Storage finden Sie hier: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/59-object-storage-pilot

Aufgrund einer Wartung wird GitLab am 03.08. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 03.08. between 8:00 and 9:00 am.

Commit cf6980ef authored by LammLukas's avatar LammLukas
Browse files

Added list of attributes to be exported to write_json and data2dict in exportable class.

parent 04ec04d9
......@@ -12,28 +12,29 @@ class Exportable(object):
"""Empty constructor"""
pass
def data2dict(self):
def data2dict(self, export_list=[]):
"""Store attributes in dictionary for .json export
"""
data = {}
for attr_name in self.get_attributes():
attribute = getattr(self, attr_name)
if isinstance(attribute, list):
if attribute and isinstance(attribute[0], Exportable):
item_list = []
for item in attribute:
item_data = item.data2dict()
item_list.append(item_data)
data[attr_name] = item_list
if not export_list or (attr_name in export_list):
if isinstance(attribute, list):
if attribute and isinstance(attribute[0], Exportable):
item_list = []
for item in attribute:
item_data = item.data2dict()
item_list.append(item_data)
data[attr_name] = item_list
else:
data[attr_name] = attribute
else:
data[attr_name] = attribute
else:
data[attr_name] = attribute
return data
def write_json(self, file):
def write_json(self, file, export_list=[]):
"""Write object data to .json file"""
data = self.data2dict()
data = self.data2dict(export_list)
with open(file, 'w') as outfile:
json.dump(data, outfile, indent=4)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment