#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os

import dlite

thisdir = os.path.abspath(os.path.dirname(__file__))


class Person:
    def __init__(self, name, age, skills):
        self.name = name
        self.age = age
        self.skills = skills

    def __repr__(self):
        return 'Person(%r, %r, %r)' % (self.name, self.age, list(self.skills))


url = 'json://' + thisdir + '/Person.json'

print('-- create: ExPerson')
ExPerson = dlite.classfactory(Person, url=url)

print('-- create: person1')
person1 = Person('Jack Daniel', 42, ['distilling', 'tasting'])

print('-- create: person2')
person2 = ExPerson('Jack Daniel', 42, ['distilling', 'tasting'])
person2.dlite_inst.save('json', 'persons.json', 'mode=w')

# Print json-representation of person2 using dlite
print(person2.dlite_inst.asjson(indent=2))

person3 = dlite.loadfactory(Person, 'json://persons.json')

person4 = dlite.objectfactory(person1, meta=person2.dlite_meta)

[((450, 485), 'dlite.classfactory', 'dlite.classfactory', (['Person'], {'url': 'url'}), '(Person, url=url)\n', (468, 485), False, 'import dlite\n'), ((836, 884), 'dlite.loadfactory', 'dlite.loadfactory', (['Person', '"""json://persons.json"""'], {}), "(Person, 'json://persons.json')\n", (853, 884), False, 'import dlite\n'), ((896, 949), 'dlite.objectfactory', 'dlite.objectfactory', (['person1'], {'meta': 'person2.dlite_meta'}), '(person1, meta=person2.dlite_meta)\n', (915, 949), False, 'import dlite\n'), ((97, 122), 'os.path.dirname', 'os.path.dirname', (['__file__'], {}), '(__file__)\n', (112, 122), False, 'import os\n')]