#!/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)

[((23, 11, 23, 46), 'dlite.classfactory', 'dlite.classfactory', (), '', False, 'import dlite\n'), ((35, 10, 35, 58), 'dlite.loadfactory', 'dlite.loadfactory', ({(35, 28, 35, 34): 'Person', (35, 36, 35, 57): '"""json://persons.json"""'}, {}), "(Person, 'json://persons.json')", False, 'import dlite\n'), ((37, 10, 37, 63), 'dlite.objectfactory', 'dlite.objectfactory', (), '', False, 'import dlite\n'), ((7, 26, 7, 51), 'os.path.dirname', 'os.path.dirname', ({(7, 42, 7, 50): '__file__'}, {}), '(__file__)', False, 'import os\n')]