# Path: e3d/plugin_management/PluginHandlers.py
# class PluginDescription(object):
#     def __init__(self, name='', description='', authorName='', authorEmail=''):
#         self.name = name
#         self.description = description
#         self.authorName = authorName
#         self.authorEmail = authorEmail
# 
#     def __repr__(self):
#         return self.name
# 
#     def _toDict(self):
#         d = dir(self)
#         dd = {v: getattr(self, v) for v in d if not v.startswith('_') and not callable(getattr(self, v))}
#         return dd
# 
#     def saveToDisk(self, destFolder):
#         try:
#             finalPath = path.abspath(path.join(destFolder, DESCRIPTIONNAME + '.json'))
#             with open(finalPath, 'w') as dest:
#                 dump(self._toDict(), dest, indent=4)
#         except:
#             raise
# 
#     @staticmethod
#     def fromDisk(folderPath):
#         descriptionPath = path.abspath(path.join(folderPath, DESCRIPTIONNAME + '.json'))
#         if not path.exists(descriptionPath):
#             raise FileNotFoundError('required plugin description file not found.')
#         with open(descriptionPath) as desc:
#             data = load(desc)
# 
#         description = PluginDescription(**data)
#         return description
# 
# def packPluginFromFolder(folderPath):
#     folderPath = path.abspath(folderPath)
#     if not path.exists(folderPath):
#         raise FileNotFoundError('the folder does not exist.')
#     if not path.isdir(folderPath):
#         raise NotADirectoryError('folderPath must be a directory with files.')
# 
#     parentFolder = path.abspath(path.join(folderPath, path.pardir))
#     descriptionPath = path.abspath(path.join(folderPath, DESCRIPTIONNAME + '.json'))
#     if not path.exists(descriptionPath):
#         raise FileNotFoundError('required plugin description file not found.')
# 
#     zipTitle = folderPath
#     finalName = zipTitle + PLUGINEXTENSION
#     make_archive(zipTitle, 'gztar', folderPath, './')
#     os.rename(zipTitle + '.tar.gz', finalName)


from e3d.plugin_management.PluginHandlers import PluginDescription, packPluginFromFolder


if __name__ == '__main__':
    desc = PluginDescription('My Test Plugin', 'JR-García', 'some@example.com', 'Dummy plugin to test '
                                                                             'plugin creation')

    pluginFolderPath = './plugins/MyTestPlugin'

# Path: e3d/plugin_management/PluginHandlers.py
# class PluginDescription(object):
#     def __init__(self, name='', description='', authorName='', authorEmail=''):
#         self.name = name
#         self.description = description
#         self.authorName = authorName
#         self.authorEmail = authorEmail
# 
#     def __repr__(self):
#         return self.name
# 
#     def _toDict(self):
#         d = dir(self)
#         dd = {v: getattr(self, v) for v in d if not v.startswith('_') and not callable(getattr(self, v))}
#         return dd
# 
#     def saveToDisk(self, destFolder):
#         try:
#             finalPath = path.abspath(path.join(destFolder, DESCRIPTIONNAME + '.json'))
#             with open(finalPath, 'w') as dest:
#                 dump(self._toDict(), dest, indent=4)
#         except:
#             raise
# 
#     @staticmethod
#     def fromDisk(folderPath):
#         descriptionPath = path.abspath(path.join(folderPath, DESCRIPTIONNAME + '.json'))
#         if not path.exists(descriptionPath):
#             raise FileNotFoundError('required plugin description file not found.')
#         with open(descriptionPath) as desc:
#             data = load(desc)
# 
#         description = PluginDescription(**data)
#         return description
# 
# def packPluginFromFolder(folderPath):
#     folderPath = path.abspath(folderPath)
#     if not path.exists(folderPath):
#         raise FileNotFoundError('the folder does not exist.')
#     if not path.isdir(folderPath):
#         raise NotADirectoryError('folderPath must be a directory with files.')
# 
#     parentFolder = path.abspath(path.join(folderPath, path.pardir))
#     descriptionPath = path.abspath(path.join(folderPath, DESCRIPTIONNAME + '.json'))
#     if not path.exists(descriptionPath):
#         raise FileNotFoundError('required plugin description file not found.')
# 
#     zipTitle = folderPath
#     finalName = zipTitle + PLUGINEXTENSION
#     make_archive(zipTitle, 'gztar', folderPath, './')
#     os.rename(zipTitle + '.tar.gz', finalName)


# Path: Demos/plugin_creation_test.py
from e3d.plugin_management.PluginHandlers import PluginDescription, packPluginFromFolder



if __name__ == '__main__':
    desc = PluginDescription('My Test Plugin', 'JR-García', 'some@example.com', 'Dummy plugin to test '
                                                                             'plugin creation')

    pluginFolderPath = './plugins/MyTestPlugin'

    desc.saveToDisk(pluginFolderPath)