# Path: g_sorcery/compatibility.py
# class TemporaryDirectory(object):
#     def __init__(self):
#         self.name = mkdtemp()
# 
#     def __del__(self):
#         shutil.rmtree(self.name)
# 
# Path: g_sorcery/exceptions.py
# class FileJSONError(GSorceryError):
#     pass
# 
# class DownloadingError(GSorceryError):
#     pass
# 
# Path: g_sorcery/serialization.py
# class JSONSerializer(json.JSONEncoder):
#     """
#     Custom JSON encoder.
# 
#     Each serializable class should have a method serialize
#     that returns JSON serializable value. If class additionally
#     has a classmethod deserialize that it can be deserialized
#     and additional metainformation is added to the resulting JSON.
#     """
#     def default(self, obj):
#         res = step_to_raw_serializable(obj)
#         if res:
#             return res
#         else:
#             return json.JSONEncoder.default(self, obj)
# 
# def deserializeHook(json_object):
#     """
#     Custom JSON decoder.
# 
#     Each class that can be deserialized should have classmethod deserialize
#     that takes value (previously returned by serialize method) and transforms
#     it into class instance.
#     """
#     return step_from_raw_serializable(json_object)


import glob
import json
import hashlib
import os
import tarfile
from .compatibility import TemporaryDirectory
from .exceptions import FileJSONError, DownloadingError
from .serialization import JSONSerializer, deserializeHook
        """
        Read file.
        """
        if not os.path.exists(self.directory):
            os.makedirs(self.directory)
        content = {}
        if not os.path.isfile(self.path):
            for key in self.mandatories:
                content[key] = ""
            self.write_content(content)
        else:
            content = self.read_content()
            for key in self.mandatories:
                if not key in content:
                    raise FileJSONError('lack of mandatory key: ' + key)

        return content

    def read_content(self):
        """
        Real read operation with deserialization. Should be overridden.
        """
        return []

    def write(self, content):
        """
        Write file.
        """
        for key in self.mandatories:
            if not key in content:

# Path: g_sorcery/compatibility.py
# class TemporaryDirectory(object):
#     def __init__(self):
#         self.name = mkdtemp()
# 
#     def __del__(self):
#         shutil.rmtree(self.name)
# 
# Path: g_sorcery/exceptions.py
# class FileJSONError(GSorceryError):
#     pass
# 
# class DownloadingError(GSorceryError):
#     pass
# 
# Path: g_sorcery/serialization.py
# class JSONSerializer(json.JSONEncoder):
#     """
#     Custom JSON encoder.
# 
#     Each serializable class should have a method serialize
#     that returns JSON serializable value. If class additionally
#     has a classmethod deserialize that it can be deserialized
#     and additional metainformation is added to the resulting JSON.
#     """
#     def default(self, obj):
#         res = step_to_raw_serializable(obj)
#         if res:
#             return res
#         else:
#             return json.JSONEncoder.default(self, obj)
# 
# def deserializeHook(json_object):
#     """
#     Custom JSON decoder.
# 
#     Each class that can be deserialized should have classmethod deserialize
#     that takes value (previously returned by serialize method) and transforms
#     it into class instance.
#     """
#     return step_from_raw_serializable(json_object)


# Path: g_sorcery/fileutils.py
import glob
import json
import hashlib
import os
import tarfile
from .compatibility import TemporaryDirectory
from .exceptions import FileJSONError, DownloadingError
from .serialization import JSONSerializer, deserializeHook

        """
        Read file.
        """
        if not os.path.exists(self.directory):
            os.makedirs(self.directory)
        content = {}
        if not os.path.isfile(self.path):
            for key in self.mandatories:
                content[key] = ""
            self.write_content(content)
        else:
            content = self.read_content()
            for key in self.mandatories:
                if not key in content:
                    raise FileJSONError('lack of mandatory key: ' + key)

        return content

    def read_content(self):
        """
        Real read operation with deserialization. Should be overridden.
        """
        return []

    def write(self, content):
        """
        Write file.
        """
        for key in self.mandatories:
            if not key in content:

                raise FileJSONError('lack of mandatory key: ' + key)