(sbg)
Argument processing of the command line.

    :param sbg: the `isbg.ISBG` instance which would be updated with the
                parameters.
    :type sbg: isbg.ISBG
    :return: `None`

    :Example: You can run it using:

        >>> sbg = isbg.ISBG()
        >>> parse_args(sbg)
Argument processing of the command line.
Argument processing of the command line .
def parse_args(sbg):
    """Argument processing of the command line.

    :param sbg: the `isbg.ISBG` instance which would be updated with the
                parameters.
    :type sbg: isbg.ISBG
    :return: `None`

    :Example: You can run it using:

        >>> sbg = isbg.ISBG()
        >>> parse_args(sbg)
    """
    try:
        opts = docopt(__cmd_opts__.__doc__, version="isbg_v" +
                      isbg.__version__ + ", from: " +
                      os.path.abspath(__file__) + "\n\n" + isbg.__license__)
        opts = dict([(k, v) for k, v in opts.items()
                     if v is not None])
    except DocoptExit as exc:
        raise isbg.ISBGError(isbg.__exitcodes__['flags'],
                             "Option processing failed - " + str(exc))

    if opts.get("--usage"):
        print(printable_usage(__cmd_opts__.__doc__))
        return 1

    if opts.get("--deletehigherthan") is not None:
        try:
            sbg.deletehigherthan = float(opts["--deletehigherthan"])
        except Exception:  # pylint: disable=broad-except
            raise isbg.ISBGError(isbg.__exitcodes__['flags'],
                                 "Unrecognized score - " +
                                 opts["--deletehigherthan"])
        if sbg.deletehigherthan < 1:
            raise isbg.ISBGError(isbg.__exitcodes__['flags'],
                                 "Score " + repr(sbg.deletehigherthan) +
                                 " is too small")

    if opts["--flag"] is True:
        sbg.spamflags.append("\\Flagged")

    sbg.imapsets.host = opts.get('--imaphost', sbg.imapsets.host)
    sbg.imapsets.passwd = opts.get('--imappasswd',
                                   sbg.imapsets.passwd)
    sbg.imapsets.port = opts.get('--imapport', sbg.imapsets.port)
    sbg.imapsets.user = opts.get('--imapuser', sbg.imapsets.user)
    sbg.imapsets.inbox = opts.get('--imapinbox', sbg.imapsets.inbox)
    sbg.imapsets.spaminbox = opts.get('--spaminbox', sbg.imapsets.spaminbox)
    sbg.imapsets.learnspambox = opts.get('--learnspambox')
    sbg.imapsets.learnhambox = opts.get('--learnhambox')
    sbg.imapsets.nossl = opts.get('--nossl', sbg.imapsets.nossl)

    sbg.lockfilegrace = float(opts.get('--lockfilegrace', sbg.lockfilegrace))

    sbg.nostats = opts.get('--nostats', False)
    sbg.dryrun = opts.get('--dryrun', False)
    sbg.delete = opts.get('--delete', False)
    sbg.gmail = opts.get('--gmail', False)

    if opts.get("--maxsize") is not None:
        try:
            sbg.maxsize = int(opts["--maxsize"])
        except (TypeError, ValueError):
            raise isbg.ISBGError(isbg.__exitcodes__['flags'],
                                 "Unrecognised size - " + opts["--maxsize"])
        if sbg.maxsize < 1:
            raise isbg.ISBGError(isbg.__exitcodes__['flags'],
                                 "Size " + repr(sbg.maxsize) + " is too small")

    sbg.movehamto = opts.get('--movehamto')

    if opts["--noninteractive"] is True:
        sbg.interactive = 0

    sbg.noreport = opts.get('--noreport', sbg.noreport)

    sbg.lockfilename = opts.get('--lockfilename', sbg.lockfilename)

    sbg.trackfile = opts.get('--trackfile', sbg.trackfile)

    sbg.partialrun = opts.get('--partialrun', sbg.partialrun)
    try:
        sbg.partialrun = int(opts["--partialrun"])
    except ValueError:
        raise isbg.ISBGError(isbg.__exitcodes__['flags'],
                             "partialrun \'{}\' must be a integer".format(
                             repr(sbg.partialrun)))
    if sbg.partialrun < 0:
        raise isbg.ISBGError(isbg.__exitcodes__['flags'],
                             ("Partial run \'{}\' number must be equal to " +
                              "0 or higher").format(repr(sbg.partialrun)))
    elif sbg.partialrun == 0:
        sbg.partialrun = None

    sbg.verbose = opts.get('--verbose', sbg.verbose)
    sbg.verbose_mails = opts.get('--verbose-mails', sbg.verbose_mails)
    sbg.ignorelockfile = opts.get("--ignorelockfile", sbg.ignorelockfile)
    sbg.savepw = opts.get('--savepw', sbg.savepw)
    sbg.passwdfilename = opts.get('--passwdfilename', sbg.passwdfilename)

    sbg.imaplist = opts.get('--imaplist', sbg.imaplist)

    sbg.learnunflagged = opts.get('--learnunflagged', sbg.learnunflagged)
    sbg.learnflagged = opts.get('--learnflagged', sbg.learnflagged)
    sbg.learnthendestroy = opts.get('--learnthendestroy', sbg.learnthendestroy)
    sbg.learnthenflag = opts.get('--learnthendestroy', sbg.learnthenflag)
    sbg.expunge = opts.get('--expunge', sbg.expunge)

    sbg.teachonly = opts.get('--teachonly', sbg.teachonly)
    sbg.spamc = opts.get('--spamc', sbg.spamc)

    sbg.exitcodes = opts.get('--exitcodes', sbg.exitcodes)

    # fixup any arguments
    if opts.get("--imapport") is None:
        if opts["--nossl"] is True:
            sbg.imapsets.port = 143
        else:
            sbg.imapsets.port = 993
def parse_args ( sbg ) : try : opts = docopt ( __cmd_opts__ . __doc__ , version = "isbg_v" + isbg . __version__ + ", from: " + os . path . abspath ( __file__ ) + "\n\n" + isbg . __license__ ) opts = dict ( [ ( k , v ) for k , v in opts . items ( ) if v is not None ] ) except DocoptExit as exc : raise isbg . ISBGError ( isbg . __exitcodes__ [ 'flags' ] , "Option processing failed - " + str ( exc ) ) if opts . get ( "--usage" ) : print ( printable_usage ( __cmd_opts__ . __doc__ ) ) return 1 if opts . get ( "--deletehigherthan" ) is not None : try : sbg . deletehigherthan = float ( opts [ "--deletehigherthan" ] ) except Exception : # pylint: disable=broad-except raise isbg . ISBGError ( isbg . __exitcodes__ [ 'flags' ] , "Unrecognized score - " + opts [ "--deletehigherthan" ] ) if sbg . deletehigherthan < 1 : raise isbg . ISBGError ( isbg . __exitcodes__ [ 'flags' ] , "Score " + repr ( sbg . deletehigherthan ) + " is too small" ) if opts [ "--flag" ] is True : sbg . spamflags . append ( "\\Flagged" ) sbg . imapsets . host = opts . get ( '--imaphost' , sbg . imapsets . host ) sbg . imapsets . passwd = opts . get ( '--imappasswd' , sbg . imapsets . passwd ) sbg . imapsets . port = opts . get ( '--imapport' , sbg . imapsets . port ) sbg . imapsets . user = opts . get ( '--imapuser' , sbg . imapsets . user ) sbg . imapsets . inbox = opts . get ( '--imapinbox' , sbg . imapsets . inbox ) sbg . imapsets . spaminbox = opts . get ( '--spaminbox' , sbg . imapsets . spaminbox ) sbg . imapsets . learnspambox = opts . get ( '--learnspambox' ) sbg . imapsets . learnhambox = opts . get ( '--learnhambox' ) sbg . imapsets . nossl = opts . get ( '--nossl' , sbg . imapsets . nossl ) sbg . lockfilegrace = float ( opts . get ( '--lockfilegrace' , sbg . lockfilegrace ) ) sbg . nostats = opts . get ( '--nostats' , False ) sbg . dryrun = opts . get ( '--dryrun' , False ) sbg . delete = opts . get ( '--delete' , False ) sbg . gmail = opts . get ( '--gmail' , False ) if opts . get ( "--maxsize" ) is not None : try : sbg . maxsize = int ( opts [ "--maxsize" ] ) except ( TypeError , ValueError ) : raise isbg . ISBGError ( isbg . __exitcodes__ [ 'flags' ] , "Unrecognised size - " + opts [ "--maxsize" ] ) if sbg . maxsize < 1 : raise isbg . ISBGError ( isbg . __exitcodes__ [ 'flags' ] , "Size " + repr ( sbg . maxsize ) + " is too small" ) sbg . movehamto = opts . get ( '--movehamto' ) if opts [ "--noninteractive" ] is True : sbg . interactive = 0 sbg . noreport = opts . get ( '--noreport' , sbg . noreport ) sbg . lockfilename = opts . get ( '--lockfilename' , sbg . lockfilename ) sbg . trackfile = opts . get ( '--trackfile' , sbg . trackfile ) sbg . partialrun = opts . get ( '--partialrun' , sbg . partialrun ) try : sbg . partialrun = int ( opts [ "--partialrun" ] ) except ValueError : raise isbg . ISBGError ( isbg . __exitcodes__ [ 'flags' ] , "partialrun \'{}\' must be a integer" . format ( repr ( sbg . partialrun ) ) ) if sbg . partialrun < 0 : raise isbg . ISBGError ( isbg . __exitcodes__ [ 'flags' ] , ( "Partial run \'{}\' number must be equal to " + "0 or higher" ) . format ( repr ( sbg . partialrun ) ) ) elif sbg . partialrun == 0 : sbg . partialrun = None sbg . verbose = opts . get ( '--verbose' , sbg . verbose ) sbg . verbose_mails = opts . get ( '--verbose-mails' , sbg . verbose_mails ) sbg . ignorelockfile = opts . get ( "--ignorelockfile" , sbg . ignorelockfile ) sbg . savepw = opts . get ( '--savepw' , sbg . savepw ) sbg . passwdfilename = opts . get ( '--passwdfilename' , sbg . passwdfilename ) sbg . imaplist = opts . get ( '--imaplist' , sbg . imaplist ) sbg . learnunflagged = opts . get ( '--learnunflagged' , sbg . learnunflagged ) sbg . learnflagged = opts . get ( '--learnflagged' , sbg . learnflagged ) sbg . learnthendestroy = opts . get ( '--learnthendestroy' , sbg . learnthendestroy ) sbg . learnthenflag = opts . get ( '--learnthendestroy' , sbg . learnthenflag ) sbg . expunge = opts . get ( '--expunge' , sbg . expunge ) sbg . teachonly = opts . get ( '--teachonly' , sbg . teachonly ) sbg . spamc = opts . get ( '--spamc' , sbg . spamc ) sbg . exitcodes = opts . get ( '--exitcodes' , sbg . exitcodes ) # fixup any arguments if opts . get ( "--imapport" ) is None : if opts [ "--nossl" ] is True : sbg . imapsets . port = 143 else : sbg . imapsets . port = 993