Exemplo n.º 1
0
    def object_updater(self, url, container, u_file):
        """Update an existing object in a swift container.

        This method will place new headers on an existing object.

        :param url:
        :param container:
        :param u_file:
        """

        for retry in basic.retryloop(attempts=ARGS.get('error_retry'),
                                     delay=2,
                                     obj=u_file):

            # HTML Encode the path for the file
            rpath = http.quoter(url=url.path, cont=container, ufile=u_file)

            fheaders = self.payload['headers']
            if ARGS.get('object_headers') is not None:
                fheaders.update(ARGS.get('object_headers'))
            if ARGS.get('save_perms') is not None:
                fheaders.update(basic.stat_file(local_file=u_file))

            with meth.operation(retry, obj='%s %s' % (fheaders, u_file)):
                self._header_poster(url=url, rpath=rpath, fheaders=fheaders)
Exemplo n.º 2
0
    def object_putter(self, url, container, source, u_file):
        """This is the Sync method which uploads files to the swift repository

        if they are not already found. If a file "name" is found locally and
        in the swift repository an MD5 comparison is done between the two
        files. If the MD5 is miss-matched the local file is uploaded to the
        repository. If custom meta data is specified, and the object exists the
        method will put the metadata onto the object.

        :param url:
        :param container:
        :param source:
        :param u_file:
        """

        for retry in basic.retryloop(attempts=ARGS.get('error_retry'),
                                     delay=2,
                                     obj=u_file):
            # Open Connection
            conn = http.open_connection(url=url)

            # Open connection and perform operation
            with meth.operation(retry, conn, obj=u_file):
                # Get the path ready for action
                sfile = basic.get_sfile(ufile=u_file, source=source)
                rpath = http.quoter(url=url.path, cont=container, ufile=sfile)

                fheaders = self.payload['headers']

                # Perform Upload.
                self._putter(conn=conn,
                             fpath=u_file,
                             rpath=rpath,
                             fheaders=fheaders,
                             retry=retry)

                # Put headers on the object if custom headers, or save perms.
                if any([
                        ARGS.get('object_headers') is not None,
                        ARGS.get('save_perms') is not None
                ]):

                    if ARGS.get('object_headers') is not None:
                        fheaders.update(ARGS.get('object_headers'))
                    if ARGS.get('save_perms') is not None:
                        fheaders.update(basic.stat_file(local_file=u_file))

                    self._header_poster(conn=conn,
                                        rpath=rpath,
                                        fheaders=fheaders,
                                        retry=retry)
Exemplo n.º 3
0
    def object_putter(self, url, container, source, u_file):
        """This is the Sync method which uploads files to the swift repository

        if they are not already found. If a file "name" is found locally and
        in the swift repository an MD5 comparison is done between the two
        files. If the MD5 is miss-matched the local file is uploaded to the
        repository. If custom meta data is specified, and the object exists the
        method will put the metadata onto the object.

        :param url:
        :param container:
        :param source:
        :param u_file:
        """

        for retry in basic.retryloop(attempts=ARGS.get('error_retry'),
                                     delay=2,
                                     obj=u_file):
            # Open Connection
            conn = http.open_connection(url=url)

            # Open connection and perform operation
            with meth.operation(retry, conn, obj=u_file):
                # Get the path ready for action
                sfile = basic.get_sfile(ufile=u_file, source=source)
                rpath = http.quoter(url=url.path,
                                    cont=container,
                                    ufile=sfile)

                fheaders = self.payload['headers']

                # Perform Upload.
                self._putter(conn=conn,
                             fpath=u_file,
                             rpath=rpath,
                             fheaders=fheaders,
                             retry=retry)

                # Put headers on the object if custom headers, or save perms.
                if any([ARGS.get('object_headers') is not None,
                        ARGS.get('save_perms') is not None]):

                    if ARGS.get('object_headers') is not None:
                        fheaders.update(ARGS.get('object_headers'))
                    if ARGS.get('save_perms') is not None:
                        fheaders.update(basic.stat_file(local_file=u_file))

                    self._header_poster(conn=conn,
                                        rpath=rpath,
                                        fheaders=fheaders,
                                        retry=retry)
Exemplo n.º 4
0
    def object_putter(self, url, container, source, u_file):
        """This is the Sync method which uploads files to the swift repository

        if they are not already found. If a file "name" is found locally and
        in the swift repository an MD5 comparison is done between the two
        files. If the MD5 is miss-matched the local file is uploaded to the
        repository. If custom meta data is specified, and the object exists the
        method will put the metadata onto the object.

        :param url:
        :param container:
        :param source:
        :param u_file:
        """

        for retry in basic.retryloop(attempts=ARGS.get('error_retry'),
                                     delay=2,
                                     obj=u_file):

            # Open connection and perform operation

            # Get the path ready for action
            sfile = basic.get_sfile(ufile=u_file, source=source)

            if ARGS.get('dir'):
                container = '%s/%s' % (container, ARGS['dir'].strip('/'))

            rpath = http.quoter(url=url.path, cont=container, ufile=sfile)

            fheaders = self.payload['headers']

            if ARGS.get('object_headers') is not None:
                fheaders.update(ARGS.get('object_headers'))
            if ARGS.get('save_perms') is not None:
                fheaders.update(basic.stat_file(local_file=u_file))

            with meth.operation(retry, obj='%s %s' % (fheaders, u_file)):
                self._putter(url=url,
                             fpath=u_file,
                             rpath=rpath,
                             fheaders=fheaders)
Exemplo n.º 5
0
    def object_updater(self, url, container, u_file):
        """Update an existing object in a swift container.

        This method will place new headers on an existing object.

        :param url:
        :param container:
        :param u_file:
        """

        for retry in basic.retryloop(attempts=ARGS.get("error_retry"), delay=2, obj=u_file):

            # HTML Encode the path for the file
            rpath = http.quoter(url=url.path, cont=container, ufile=u_file)

            fheaders = self.payload["headers"]
            if ARGS.get("object_headers") is not None:
                fheaders.update(ARGS.get("object_headers"))
            if ARGS.get("save_perms") is not None:
                fheaders.update(basic.stat_file(local_file=u_file))

            with meth.operation(retry, obj="%s %s" % (fheaders, u_file)):
                self._header_poster(url=url, rpath=rpath, fheaders=fheaders)
Exemplo n.º 6
0
    def object_putter(self, url, container, source, u_file):
        """This is the Sync method which uploads files to the swift repository

        if they are not already found. If a file "name" is found locally and
        in the swift repository an MD5 comparison is done between the two
        files. If the MD5 is miss-matched the local file is uploaded to the
        repository. If custom meta data is specified, and the object exists the
        method will put the metadata onto the object.

        :param url:
        :param container:
        :param source:
        :param u_file:
        """

        for retry in basic.retryloop(attempts=ARGS.get("error_retry"), delay=2, obj=u_file):

            # Open connection and perform operation

            # Get the path ready for action
            sfile = basic.get_sfile(ufile=u_file, source=source)

            if ARGS.get("dir"):
                container = "%s/%s" % (container, ARGS["dir"].strip("/"))

            rpath = http.quoter(url=url.path, cont=container, ufile=sfile)

            fheaders = self.payload["headers"]

            if ARGS.get("object_headers") is not None:
                fheaders.update(ARGS.get("object_headers"))
            if ARGS.get("save_perms") is not None:
                fheaders.update(basic.stat_file(local_file=u_file))

            with meth.operation(retry, obj="%s %s" % (fheaders, u_file)):
                self._putter(url=url, fpath=u_file, rpath=rpath, fheaders=fheaders)