import re
import sys
import yaml
from box import Box

class UploaderInvoker:

    @staticmethod
    def invoke():
        args = sys.argv[1:]

        if len(args) < 1:
            print('usage: dbx-sync [workspace root] [file] [config path]')
            return

        with open(args[2], 'r') as f:
            config = Box(yaml.safe_load(f))

        projectRoot = args[0]
        targetProjectRoot = config.dbx.projectPath
        sourceNotebookRelativePath = args[1].replace(projectRoot, '')
        sourceNotebookFullPath = args[1]
        targetNotebookFullPath = re.sub(r'.py$', '', targetProjectRoot + sourceNotebookRelativePath)

        from DbxSync.DependencyInjection.Container import createContainer

        container = createContainer(config)
        uploader = container.getUploader()

        print('Uploading ' + sourceNotebookFullPath + ' -> ' + targetNotebookFullPath)

        uploader.upload(sourceNotebookFullPath, targetNotebookFullPath)

        print('done')

import re
import sys
import yaml
from box import Box

class UploaderInvoker:

    @staticmethod
    def invoke():
        args = sys.argv[1:]

        if len(args) < 1:
            print('usage: dbx-sync [workspace root] [file] [config path]')
            return

        with open(args[2], 'r') as f:
            config = Box(yaml.safe_load(f))

        projectRoot = args[0]
        targetProjectRoot = config.dbx.projectPath
        sourceNotebookRelativePath = args[1].replace(projectRoot, '')
        sourceNotebookFullPath = args[1]
        targetNotebookFullPath = re.sub(r'.py$', '', targetProjectRoot + sourceNotebookRelativePath)

        from DbxSync.DependencyInjection.Container import createContainer

        container = createContainer(config)
        uploader = container.getUploader()

        print('Uploading ' + sourceNotebookFullPath + ' -> ' + targetNotebookFullPath)

        uploader.upload(sourceNotebookFullPath, targetNotebookFullPath)

        print('done')
