@login
    @command(index=int, capsule=int)
    def do_upload(self, index=1, capsule=None):
        """
        Usage: upload [<index>] [<capsule>]
        """
        fname = None
        docs = list(self.cache._for_adf('archives').iteritems())
        docs = sorted(docs, key=compose(creation, operator.itemgetter(1)))

        _error = "Cannot upload: "

        if index <= 0 or len(docs) < index:
            _error += "no such archive."
        else:
            fname = docs[index-1][0]
            docs = docs[index-1][1]
            size = docs['archive'].meta.size

            capsules = self.session.capsule_ids(
                size if self.safe else None)
            if capsule is not None:
                capsule = capsules.get(capsule)
            elif len(capsules) > 0:
                capsule = capsules.itervalues().next()

            if capsule is None:
                _error += "no capsules found"

        if 'links' not in docs:
            _error += "no local copy exists."
            link = False
        else:
            link = docs['links']
        if link and fname and capsule:
            if link.upload or link.download:
                print "upload is already completed"
            else:
                try:
                    with UploadState.get(
                            fname, size, capsule, self.sandbox) as state:
                        handler = ConsoleProgressHandler(
                            maxval=size, fname=fname, state=state)
                        with handler as progq:
                            saved = self.upload(docs, fname, progq, state)
                        if not self.batch:
                            print ""
                            print "Upload finished, waiting for verification"
                            print "Press Ctrl-C to check manually later"
                            status = self._poll_status(saved['link'])
                            while status is None:
                                getLogger().debug("couldn't get status, "
                                                  "retrying..")
                                status = self._poll_status(saved['link'])
                            if status['status'] == "error":
                                print "status: error"
                                self.cache.upload_error(fname)
                                state.error(True)
                            elif status['status'] == "completed":
                                print "status: completed"
                                fname = saved['fname']
                                cert, f = self.cache.save_cert(
                                    self.cache.upload_complete(fname, status))
                                if f:
                                    print "Certificate", cert, "saved:", f
                                else:
                                    print "Certificate", cert, "already exists"
                                print " ".join(("Use lacli certificate list",
                                                "to see your certificates, or",
                                                "lacli certificate --help for",
                                                "more options"))
                                for i in range(3):
                                    try:
                                        UploadState.reset(fname)
                                        break
                                    except OSError as e:
                                        if 3 < i and e.errno == errno.EACCES:
                                            continue
                                        else:
                                            raise e
                            else:
                                st = status['status']
                                print "Unknown status received:", st

                    print "\ndone."
                except PauseEvent:
                    print "\npaused."
                except Exception as e:
                    self.cache.upload_error(fname)
                    getLogger().debug("exception while uploading",
                                      exc_info=True)
                    print "\nerror: " + str(e)
        else:
            print _error
dataset/ETHPy150Open longaccess/longaccess-client/lacli/command.py/LaArchiveCommand.do_upload/swapped operands of `<`