Esempio n. 1
0
    def do_storage(self, args, arguments):
        """
        ::

          Usage:
                storage [--storage=SERVICE] put FILENAME
                storage [--storage=SERVICE] get FILENAME
                storage [--storage=SERVICE] delete FILENAME
                storage [--storage=SERVICE] size FILENAME
                storage [--storage=SERVICE] info FILENAME
                storage [--storage=SERVICE] create FILENAME
                storage [--storage=SERVICE] sync SOURCEDIR DESTDIR


          This command does some useful things.

          Arguments:
              FILE   a file name
              

          Options:
              -f      specify the file

          Example:
            set storage=box
            starage  put FILENAME

            is the same as 

            starage  --storage=box put FILENAME


        """

        pprint(arguments)

        m = Manager()

        service = None

        filename = arguments.FILENAME[0]
        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("storge service not defined")

        if arguments.get:
            m.get(service, filename)
Esempio n. 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.")
Esempio n. 3
0
    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)
Esempio n. 4
0
    def do_storage(self, args, arguments):
        """
        ::
        Usage:
            storage [--storage=<SERVICE>] create dir DIRNAME
            storage [--storage=<SERVICE>] delete dir DIRNAME
            storage [--storage=<SERVICE>] list dir files [DIRNAME]
            storage [--storage=<SERVICE>] put file SOURCEFILENAME SOURCEDIR DESTFILENAME DESTDIR
            storage [--storage=<SERVICE>] gett file SOURCEFILENAME SOURCEDIR DESTFILENAME DESTDIR
            storage [--storage=<SERVICE>] delete file FILENAME DIRNAME
            storage [--storage=<SERVICE>] search file FILENAME [DIRNAME]
            storage [--storage=<SERVICE>] list file info FILENAME DIRNAME

        Manage file storage on AWS S3 buckets and perform operations like put, get, delete on the files.

        Arguments:
            DIRNAME Name of the directory where file is to be created or searched or deleted.
            FILENAME Name of the file is to be created or searched or deleted.
            SOURCEFILENAME Name of the source file for put or get actions
            SOURCEDIR Name of the source file directory for put or get actions
            DESTFILENAME Name of the destination file for put or get actions
            DESTDIR Name of the destination file directory for put or get actions

        Options:
          -h --help
          --storage=<SERVICE>  Cloud storage service name like aws or azure or box or google

        Description:
            Commands to manage file storage on cloud

            storage create dir
                Creates directory with the given name.

            storage delete dir
                Deletes directory with the given name.

            storage list dir files
                Lists all files present in the input directory.
                If no dir is specified, it will list all files across directories.

            storage put file
                Uploads file to cloud storage from the local store.

            storage gett file
                Downloads file from cloud storage to the local store.

            storage delete file
                Deletes the input file from specified cloud storage directory.

            storage search file
                Searches and lists the input file from specified cloud storage directory.
                If no dir is specified, it will list all files across directories which match the filename.

            storage list file info
                Lists the file attributes for the input file.

        Example:
            set storage=aws
            storage put FILENAME DESTDIR

            is the same as
            storage  --storage=aws put FILENAME DESTDIR
        """

        pprint(arguments)

        m = Manager()

        service = None

        #filename = arguments.FILENAME[0]
        try:
            service = arguments["--storage"]
        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.create == True and arguments.dir == True:
            m.createDir(service, arguments.DIRNAME)
        elif arguments.gett == True and arguments.file == True:
            print('In service get file')
            m.getFile(service, arguments.SOURCEFILENAME, arguments.SOURCEDIR,
                      arguments.DESTFILENAME, arguments.DESTDIR)
        elif arguments.delete == True and arguments.dir == True:
            m.deleteDir(service, arguments.DIRNAME)
        elif arguments.list == True and arguments.dir == True and arguments.files == True:
            if arguments.DIRNAME is not None:
                m.listDirFiles(service, arguments.DIRNAME)
            else:
                m.listDirFiles(service, '')
        elif arguments.put == True and arguments.file == True:
            m.putFile(service, arguments.SOURCEFILENAME, arguments.SOURCEDIR,
                      arguments.DESTFILENAME, arguments.DESTDIR)
        elif arguments.delete and arguments.file == True:
            m.deleteFile(service, arguments.FILENAME, arguments.DIRNAME)
        elif arguments.search == True and arguments.file == True:
            if arguments.DIRNAME is not None:
                m.searchFile(service, arguments.FILENAME, arguments.DIRNAME)
            else:
                m.searchFile(service, arguments.FILENAME, '')
        elif arguments.list == True and arguments.file == True and arguments.info == True:
            m.listFileInfo(service, arguments.FILENAME, arguments.DIRNAME)
        else:
            print("Command not recognized.")
Esempio n. 5
0
    def do_storage(self, args, arguments):
        """
        ::

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


          This command creates, deletes, and returns information on directories and files in cloud storage services.

          Arguments:
              FILE      a file name
              DESTDIR   destination directory for uploads and downloads
              SOURCEDIR source directory for syncing directories
              DIRNAME name of new folder


          Example:
            set storage=box
            storage put FILENAME SOURCEDIR DESTDIR

            is the same as 

            storage  --storage=box put FILENAME SOURCEDIR DESTDIR


        """

        pprint(arguments)

        m = Manager()

        service = None

        try:
            service = arguments["--storage"]
        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 == True:
            m.get(service, arguments.FILENAME, arguments.DESTDIR)
        elif arguments.put == True:
            if arguments.DESTDIR is not None:
                m.put(service, arguments.FILENAME, arguments.SOURCEDIR,
                      arguments.DESTDIR)
            else:
                m.put(service, arguments.FILENAME, arguments.SOURCEDIR)
        elif arguments.delete == True:
            m.delete(service, arguments.FILENAME)
        elif arguments.info == True:
            m.info(service, arguments.FILENAME)
        elif arguments.search == True:
            m.search(service, arguments.FILENAME)
        elif arguments.create == True and arguments.dir == True:
            if arguments.DESTDIR is not None:
                m.create_dir(service, arguments.DIRNAME, arguments.DESTDIR)
            else:
                m.create_dir(service, arguments.DIRNAME)
        elif arguments.list == True and arguments.dir == True:
            if arguments.DIRNAME is not None:
                m.list_dir(service, arguments.DIRNAME)
            else:
                m.list_dir(service)
        elif arguments.delete == True and arguments.dir == True:
            m.delete_dir(service, arguments.DIRNAME)
        else:
            print("Command not recognized.")
Esempio n. 6
0
    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)