def do_storage(self, args, arguments):
        """
        ::

          Usage:
                storage [--storage=SERVICE] put FILENAME SOURCEDIR
                storage [--storage=SERVICE] get FILENAME DESTDIR
                storage [--storage=SERVICE] delete file FILENAME
                storage [--storage=SERVICE] list file DIRNAME
                storage [--storage=SERVICE] info FILENAME
                storage [--storage=SERVICE] create dir DIRNAME
                storage [--storage=SERVICE] list dir
                storage [--storage=SERVICE] delete dir DIRNAME


          This command does some useful things.

          Arguments:
              FILENAME   a BLOB name
              SOURCEDIR  local path for the FILENAME to be uploaded
              DESTDIR    local path for the FILENAME to be downloaded

          Options:
              --storage=SERVICE  specify the cloud service name like aws or azure or box or google

          Description:
                commands used to upload, download, list files on different cloud storage services.

                storage put [options..]
                    Uploads the file specified in the filename to specified cloud from the SOURCEDIR.

                storage get [options..]
                    Downloads the file specified in the filename from the specified cloud to the DESTDIR.

                storage delete file [options..]
                    Deletes the file specified in the filename from the specified cloud.

                storage list file [options..]
                    lists all the files from the container name specified on the specified cloud.

                storage info [options..]
                    returns the properties of the filename specified on the specified cloud.

                storage create dir [options..]
                    creates a folder with the directory name specified on the specified cloud.

                storage list dir [options..]
                    lists all the folders on the specified cloud.

                storage delete dir [options..]
                    deletes all the files in the directory specified on the specified cloud.


          Example:
            set storage=azureblob
            storage put FILENAME SOURCEDIR

            is the same as 

            storage --storage=azureblob put FILENAME SOURCEDIR


        """
        # arguments.CONTAINER = arguments["--container"]
        arguments.SERVICE = arguments["--storage"]
        pprint(arguments)

        m = Manager()

        service = None

        try:
            service = arguments["--storage"][0]
        except Exception as e:
            try:
                v = Variables()
                service = v['storage']
            except Exception as e:
                service = None

        if service is None:
            Console.error("storage service not defined")

        if arguments['get']:
            if arguments.SERVICE is None:
                variables = Variables()
                arguments.SERVICE = variables['storage']
            m.get(arguments.SERVICE, arguments.FILENAME, arguments.DESTDIR)

        elif arguments['put']:
            if arguments.SERVICE is None:
                variables = Variables()
                arguments.SERVICE = variables['storage']
            m.put(arguments.SERVICE, arguments.FILENAME, arguments.SOURCEDIR)

        elif arguments['delete'] and  arguments['file']:
            if arguments.SERVICE is None:
                variables = Variables()
                arguments.SERVICE = variables['storage']
            m.delete(arguments.SERVICE, arguments.FILENAME)

        elif arguments['list'] and arguments['file']:
            if arguments.SERVICE is None:
                variables = Variables()
                arguments.SERVICE = variables['storage']
            m.listfiles(arguments.SERVICE, arguments.DIRNAME)

        elif arguments['info']:
            if arguments.SERVICE is None:
                variables = Variables()
                arguments.SERVICE = variables['storage']
            m.info(arguments.SERVICE, arguments.FILENAME)

        elif arguments['create'] and arguments['dir']:
            if arguments.SERVICE is None:
                variables = Variables()
                arguments.SERVICE = variables['storage']
            m.createdir(arguments.SERVICE, arguments.DIRNAME)

        elif arguments['list'] and arguments['dir']:
            if arguments.SERVICE is None:
                variables = Variables()
                arguments.SERVICE = variables['storage']
            m.listdir(arguments.SERVICE)

        elif arguments['delete'] and arguments['dir']:
            if arguments.SERVICE is None:
                variables = Variables()
                arguments.SERVICE = variables['storage']
            m.deletedir(arguments.SERVICE, arguments.DIRNAME)
Exemple #2
0
    def do_storage(self, args, arguments):
        """
        ::
          Usage:
                storage [--storage=SERVICE] create dir DIRECTORY
                storage [--storage=SERVICE] gett SOURCE DESTINATION [--recursive]
                storage [--storage=SERVICE] put SOURCE DESTINATION [--recursive]
                storage [--storage=SERVICE] list SOURCE [--recursive]
                storage [--storage=SERVICE] delete SOURCE
                storage [--storage=SERVICE] search DIRECTORY FILENAME [--recursive]

          This command does some useful things.

          Arguments:
              SOURCE        SOURCE can be a directory or file
              DESTINATION   DESTINATION can be a directory or file
              DIRECTORY     DIRECTORY refers to a folder on the cloud service

          Options:
              --storage=SERVICE  specify the cloud service name like aws or azure or box or google

          Description:
                commands used to upload, download, list files on different cloud storage services.

                storage put [options..]
                    Uploads the file specified in the filename to specified cloud from the SOURCEDIR.

                storage gett [options..]
                    Downloads the file specified in the filename from the specified cloud to the DESTDIR.

                storage delete [options..]
                    Deletes the file specified in the filename from the specified cloud.

                storage list [options..]
                    lists all the files from the container name specified on the specified cloud.

                storage create dir [options..]
                    creates a folder with the directory name specified on the specified cloud.

                storage search [options..]
                    searches for the source in all the folders on the specified cloud.

          Example:
            set storage=aws
            storage put SOURCE DESTINATION --recursive
            is the same as
            storage --storage=aws put SOURCE DESTINATION --recursive
        """

        pprint(arguments)
        m = Manager()

        service = None

        try:
            arguments.storage = arguments["--storage"]
            arguments.recursive = arguments["--recursive"]
        except Exception as e:
            try:
                v = Variables()
                service = v['storage']
            except Exception as e:
                service = None

        if arguments.storage is None:
            Console.error("storage service not defined")

        if arguments.gett:
            m.get(arguments.storage, arguments.SOURCE, arguments.DESTINATION,
                  arguments.recursive)
        elif arguments.put:
            m.put(arguments.storage, arguments.SOURCE, arguments.DESTINATION,
                  arguments.recursive)
        elif arguments.list:
            print('in list')
            m.list(arguments.storage, arguments.SOURCE, arguments.recursive)
        elif arguments.create and arguments.dir:
            m.createdir(arguments.storage, arguments.DIRECTORY)
        elif arguments.delete:
            m.delete(arguments.storage, arguments.SOURCE)
        elif arguments.search:
            m.search(arguments.storage, arguments.DIRECTORY,
                     arguments.FILENAME, arguments.recursive)
        else:
            print("Command not recognized.")
    def do_storage(self, args, arguments):
        """
        ::

          Usage:
                storage [--storage=SERVICE] create dir DIRECTORY
                storage [--storage=SERVICE] get SOURCE DESTINATION [--recursive]
                storage [--storage=SERVICE] put SOURCE DESTINATION [--recursive]
                storage [--storage=SERVICE] list SOURCE [--recursive]
                storage [--storage=SERVICE] delete SOURCE
                storage [--storage=SERVICE] search  DIRECTORY FILENAME [--recursive]


          This command does some useful things.

          Arguments:
              SOURCE        SOURCE can be a directory or file
              DESTINATION   DESTINATION can be a directory or file
              DIRECTORY     DIRECTORY refers to a folder on the cloud service


          Options:
              --storage=SERVICE  specify the cloud service name like aws or azure or box or google
          Description:
                commands used to upload, download, list files on different cloud storage services.

                storage put [options..]
                    Uploads the file specified in the filename to specified cloud from the SOURCEDIR.

                storage get [options..]
                    Downloads the file specified in the filename from the specified cloud to the DESTDIR.

                storage delete [options..]
                    Deletes the file specified in the filename from the specified cloud.

                storage list [options..]
                    lists all the files from the container name specified on the specified cloud.

                storage create dir [options..]
                    creates a folder with the directory name specified on the specified cloud.

                storage search [options..]
                    searches for the source in all the folders on the specified cloud.

          Example:
            set storage=azureblob
            storage put SOURCE DESTINATION --recursive

            is the same as
            storage --storage=azureblob put SOURCE DESTINATION --recursive

        """
        # arguments.CONTAINER = arguments["--container"]

        map_parameters(arguments,
                       "recursive",
                       "storage")
        arguments.storage = arguments["--storage"]
        pprint(arguments)

        m = Manager()

        service = None

        #
        # BUG
        # services = Parameter.expand(arguments.storage)
        # service = services[0]
        # if services is None:
        #  ... do second try

        ##### BUG
        try:
            service = arguments["--storage"][0]
        except Exception as e:
            try:
                v = Variables()
                service = v['storage']
            except Exception as e:
                service = None

        if service is None:
            Console.error("storage service not defined")
            return

        # bug this is now done twice ....
        if arguments.storage is None:
            variables = Variables()
            arguments.storage = variables['storage']

        ##### Prvious code needs to be modified

        if arguments.get:
            m.get(arguments.storage, arguments.SOURCE, arguments.DESTINATION,
                  arguments.recursive)

        elif arguments.put:
            m.put(arguments.storage, arguments.SOURCE, arguments.DESTINATION,
                  arguments.recursive)

        elif arguments.list:
            print('in List')
            m.list(arguments.storage, arguments.SOURCE, arguments.recursive)

        elif arguments.create and arguments.dir.:
            m.createdir(arguments.storage, arguments.DIRECTORY)

        elif arguments.delete.:
            m.delete(arguments.storage, arguments.SOURCE)

        elif arguments['search']:
            m.search(arguments.storage, arguments.DIRECTORY, arguments.FILENAME,
                     arguments.recursive)