# 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/config.py
# def get_config():
#     if config is None:
#         init()
#     return config
# 
# class ChoiceValidator(object):
#     def __init__(self, choices):
#         self.choices = choices        
#         message = "Supported options include: {}"
#         self.message = message.format(",".join(self.choices))
# 
#     def is_valid(self, value):
#         if value in self.choices:
#             return True
#         return False
# 
# 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/helper.py
# class cd:
#     """Context manager for changing the current working directory"""
#     def __init__(self, newPath):
#         self.newPath = os.path.expanduser(newPath)
# 
#     def __enter__(self):
#         self.savedPath = os.getcwd()
#         os.chdir(self.newPath)
# 
#     def __exit__(self, etype, value, traceback):
#         os.chdir(self.savedPath)


import os, sys, stat, subprocess
import boto3
import getpass
from dgitcore.plugins.backend import BackendBase
from dgitcore.config import get_config, ChoiceValidator, NonEmptyValidator
from dgitcore.helper import cd
        return output

    def config(self, what='get', params=None):

        if what == 'get':
            return {
                'name': 'S3',
                'nature': 'backend',
                'variables': ['enable',
                              'client', 's3cfg',
                              'bucket', 'prefix'],
                'defaults': {
                    'enable': {
                        'value': "y",
                        "description": "Enable S3 backend?",
                        'validator': ChoiceValidator(['y', 'n'])
                    },
                    'client': {
                        'value': 'aws',
                        'description': 'Command line tool to use for repo backup (aws|s3cmd)',
                        'validator': NonEmptyValidator()
                    },
                    "s3cfg": {
                        'value': os.path.join(os.environ.get('HOME',"."), '.s3cfg'),
                        'description': 's3cfg configuration file if s3cmd is chosen. Otherwise ignore',
                        'validator': NonEmptyValidator()
                    },
                    'bucket': {
                        'value': "",
                        'description': "Bucket into which the datasets are stored",

# 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/config.py
# def get_config():
#     if config is None:
#         init()
#     return config
# 
# class ChoiceValidator(object):
#     def __init__(self, choices):
#         self.choices = choices        
#         message = "Supported options include: {}"
#         self.message = message.format(",".join(self.choices))
# 
#     def is_valid(self, value):
#         if value in self.choices:
#             return True
#         return False
# 
# 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/helper.py
# class cd:
#     """Context manager for changing the current working directory"""
#     def __init__(self, newPath):
#         self.newPath = os.path.expanduser(newPath)
# 
#     def __enter__(self):
#         self.savedPath = os.getcwd()
#         os.chdir(self.newPath)
# 
#     def __exit__(self, etype, value, traceback):
#         os.chdir(self.savedPath)


# Path: dgitcore/contrib/backends/s3.py
import os, sys, stat, subprocess
import boto3
import getpass
from dgitcore.plugins.backend import BackendBase
from dgitcore.config import get_config, ChoiceValidator, NonEmptyValidator
from dgitcore.helper import cd

        return output

    def config(self, what='get', params=None):

        if what == 'get':
            return {
                'name': 'S3',
                'nature': 'backend',
                'variables': ['enable',
                              'client', 's3cfg',
                              'bucket', 'prefix'],
                'defaults': {
                    'enable': {
                        'value': "y",
                        "description": "Enable S3 backend?",
                        'validator': ChoiceValidator(['y', 'n'])
                    },
                    'client': {
                        'value': 'aws',
                        'description': 'Command line tool to use for repo backup (aws|s3cmd)',
                        'validator': NonEmptyValidator()
                    },
                    "s3cfg": {
                        'value': os.path.join(os.environ.get('HOME',"."), '.s3cfg'),
                        'description': 's3cfg configuration file if s3cmd is chosen. Otherwise ignore',
                        'validator': NonEmptyValidator()
                    },
                    'bucket': {
                        'value': "",
                        'description': "Bucket into which the datasets are stored",

                        'validator': NonEmptyValidator()