#!/usr/bin/env python

from daqWebServiceSessionCli import DaqWebServiceSessionCli
from dm.daq_web_service.api.experimentDaqApi import ExperimentDaqApi
from dm.common.exceptions.invalidRequest import InvalidRequest

class StopUploadCli(DaqWebServiceSessionCli):
    def __init__(self):
        DaqWebServiceSessionCli.__init__(self, validArgCount=self.ANY_NUMBER_OF_POSITIONAL_ARGS)
        self.addOption('', '--id', dest='id', help='Upload id.')

    def checkArgs(self):
        if self.options.id is None:
            raise InvalidRequest('Upload id must be provided.')

    def getId(self):
        return self.options.id

    def runCommand(self):
        self.parseArgs(usage="""
    dm-stop-upload --id=ID

Description:
    Aborts specified data upload.
        """)
        self.checkArgs()
        api = ExperimentDaqApi(self.getLoginUsername(), self.getLoginPassword(), self.getServiceHost(), self.getServicePort(), self.getServiceProtocol())
        uploadInfo = api.stopUpload(self.getId())
        print uploadInfo.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())

#######################################################################
# Run command.
if __name__ == '__main__':
    cli = StopUploadCli()
    cli.run()