Next / Previous / Contents / Shipman's homepage

18.5. Args._final(): Semantic checking

listext2
# - - -   A r g s . _ f i n a l

    def _final(self):
        '''Compute final values of all options.

          [ self._argParser is an argparse.ArgumentParser instance ->
             self.extraLeading  :=  (effective leading from
                 self.rawLeading) - (self.pointSize), as an h.FoDim
             self.nCols  :=  self.nCols with default value as a
                 function of self.isLandscape ]
        '''

First find the effective extra leading. If the user did not specify a leading, the default value is the class variable DEFAULT_LEADING_INCR. Otherwise it is the specified leading minus the effective font size.

listext2
        #-- 1
        # [ if self.rawLeading is None ->
        #     self.extraLeading  :=  self.DEFAULT_LEADING_INCR
        #   else if self.rawLeading is a valid decimal number in
        #   string form ->
        #     self.extraLeading  :=  max(0, difference between
        #         self.rawLeading and self.pointSize) as an h.FoDim
        #   else ->
        #     raise argparse.ArgumentTypeError ]
        if self.rawLeading is None:
            self.extraLeading = self.DEFAULT_LEADING_INCR
        else:
            try:
                leading = Decimal(self.rawLeading)
            except ValueError:
                parser.error("The leading option must be a valid "
                    "decimal number, e.g., '10.5'.")

            extra = leading - Decimal(self.pointSize)
            if extra > Decimal(0):
                self.extraLeading = h.FoDim(extra, 'pt')
            else:
                self.extraLeading = h.FoDim('0', 'pt')

The default number of columns depends on the orientation.

listext2
        #-- 2
        # [ if self.nCols is not None ->
        #     I
        #   else if self.isLandscape ->
        #     self.nCols  :=  self.DEFAULT_LANDSCAPE_COLS
        #   else ->
        #     self.nCols  :=  self.DEFAULT_PORTRAIT_COLS ]
        if self.nCols is None:
            self.nCols =(self.DEFAULT_LANDSCAPE_COLS
                         if self.isLandscape
                         else self.DEFAULT_PORTRAIT_COLS)

        #-- 3
        try:
            self.inFile = open(self.inFileName)
        except IOError, detail:
            self._argParser.error("Can't open the input file '%s': %s" %
                    (self.inFileName, detail))