# Path: dgitcore/config.py
# class NonEmptyValidator(object):
#     def __init__(self):
#         self.message = "Value cannot be an empty string"
# 
#     def is_valid(self, value):
#         if value is None or len(value) == 0:
#             return False
#         return True
# 
# Path: dgitcore/plugins/backend.py
# class BackendBase(object):
#     """
#     Backend object implements
#     """
#     def __init__(self, name, version, description, supported=[]):
#         """
#         Parameters:
#         -----------
#         name: Name of the backend service e.g., s3
#         version: Version of this implementation
#         description: Text description of this service
#         supported: supported services with including name
# 
#         For example, there may be multiple s3 implementations that
#         support different kinds of services.
# 
#         """
#         self.enable = 'y'
#         self.name = name
#         self.version = version
#         self.description = description
#         self.support = supported + [name]
#         self.initialize()
# 
#     def __str__(self): 
#         return self.name 
# 
#     def initialize(self):
#         """
#         Called to initialize sessions, internal objects etc.
#         """
#         return
# 
#     def clone_repo(self, url, gitdir):
#         """
#         Clone a repo at specified URL
#         """
#         return
# 
#     def supported(self, url):
#         """
#         Check if a URL is supported by repo
#         """
#         return False
# 
#     def url_is_valid(self, url):
#         """
#         Check if a URL exists
#         """
#         return
# 
#     def push(self, state, name):
#         """
#         Push a data version to the server
# 
#         Parameters
#         ----------
# 
#         state: Overall state object that has dataset details
#         name: name of the dataset
#         """
#         return
# 
#     def config(self, what='get', params=None):
#         return


import os, sys
from dgitcore.config import NonEmptyValidator
from dgitcore.plugins.backend import BackendBase
    Filesystem based backend
    """
    def __init__(self):

        self.enable = 'y'
        self.workspace = None
        super(LocalBackend,self).__init__('local', 'v0',
                                          "Local Filesystem Backend")

    def url_is_valid(self, url):
        """
        Check if a URL exists
        """
        # Check if the file system path exists...
        if url.startswith("file://"):
            url = url.replace("file://","")

        return os.path.exists(url)


    def config(self, what='get', params=None):
        if what == 'get':
            return {
                'name': 'Local',
                'variables': ['workspace'],
                'nature': 'backend',
                'defaults': {
                    'workspace': {
                        "value": os.path.join(os.environ['HOME'], '.dgit'),
                        "description": "Local directory to store datasets",

# Path: dgitcore/config.py
# class NonEmptyValidator(object):
#     def __init__(self):
#         self.message = "Value cannot be an empty string"
# 
#     def is_valid(self, value):
#         if value is None or len(value) == 0:
#             return False
#         return True
# 
# Path: dgitcore/plugins/backend.py
# class BackendBase(object):
#     """
#     Backend object implements
#     """
#     def __init__(self, name, version, description, supported=[]):
#         """
#         Parameters:
#         -----------
#         name: Name of the backend service e.g., s3
#         version: Version of this implementation
#         description: Text description of this service
#         supported: supported services with including name
# 
#         For example, there may be multiple s3 implementations that
#         support different kinds of services.
# 
#         """
#         self.enable = 'y'
#         self.name = name
#         self.version = version
#         self.description = description
#         self.support = supported + [name]
#         self.initialize()
# 
#     def __str__(self): 
#         return self.name 
# 
#     def initialize(self):
#         """
#         Called to initialize sessions, internal objects etc.
#         """
#         return
# 
#     def clone_repo(self, url, gitdir):
#         """
#         Clone a repo at specified URL
#         """
#         return
# 
#     def supported(self, url):
#         """
#         Check if a URL is supported by repo
#         """
#         return False
# 
#     def url_is_valid(self, url):
#         """
#         Check if a URL exists
#         """
#         return
# 
#     def push(self, state, name):
#         """
#         Push a data version to the server
# 
#         Parameters
#         ----------
# 
#         state: Overall state object that has dataset details
#         name: name of the dataset
#         """
#         return
# 
#     def config(self, what='get', params=None):
#         return


# Path: dgitcore/contrib/backends/local.py
import os, sys
from dgitcore.config import NonEmptyValidator
from dgitcore.plugins.backend import BackendBase

    Filesystem based backend
    """
    def __init__(self):

        self.enable = 'y'
        self.workspace = None
        super(LocalBackend,self).__init__('local', 'v0',
                                          "Local Filesystem Backend")

    def url_is_valid(self, url):
        """
        Check if a URL exists
        """
        # Check if the file system path exists...
        if url.startswith("file://"):
            url = url.replace("file://","")

        return os.path.exists(url)


    def config(self, what='get', params=None):
        if what == 'get':
            return {
                'name': 'Local',
                'variables': ['workspace'],
                'nature': 'backend',
                'defaults': {
                    'workspace': {
                        "value": os.path.join(os.environ['HOME'], '.dgit'),
                        "description": "Local directory to store datasets",

                        'validator': NonEmptyValidator()