示例#1
0
def display(out):
    '''
    Accepts an Output data structure and prints out the results to the screen.

    Note: This function carries out all formatting for the output using the purely data-oriented Output object as input. The output is in a text format which can be piped forward
    '''

    from miscClasses import colorWidth as cW  # Custom function that sets width of text fields and colors it.

    print(cW(out.settings['name'] + ':', 12, colorTitle),
          end='')  # Print name of account and allow for further text

    if out.settings['showNums']:

        print("( total: %d | unseen: %d )" % (out.numAll, out.numUnseen))

    print('\n')

    # Preamble printed. Now start printing individual email information

    if out.settings['showUnseen']:  # Show only unseen messages

        for ii in range(len(out.emails)):

            email = out.emails[ii]

            print(
                cW(str(ii + 1), out.numDigits, align='>') + '.  ' +
                cW(email.Date, 17, colorDate) + '    ' +
                cW(email.From, 30, colorFrom) + '   ' +
                cW(email.Subject, 120, colorSubjectUnseen, fill=False))

    else:  # Show ALL messages. Different formatting scheme.

        if showFlags:  # Global setting which declares that the flags associated with each message must be displayed

            flags = lambda x: '  [ ' + cW(x, 2, colorFlag) + ']   '

        else:

            flags = lambda x: '.   '

        for ii in range(len(out.emails)):

            email = out.emails[ii]

            if email.Seen:  # Email has a Seen flag.

                flag = ' '
                colorSubject = colorSubjectSeen

            else:
                flag = 'N'
                colorSubject = colorSubjectUnseen

            print(
                cW(str(ii + 1), out.numDigits, align='>') + flags(flag) +
                cW(email.Date, 17, colorDate) + '    ' +
                cW(email.From, 30, colorFrom) + '   ' +
                cW(email.Subject, 120, colorSubject))
示例#2
0
def display( out ) :

    '''
    Accepts an Output data structure and prints out the results to the screen.

    Note: This function carries out all formatting for the output using the purely data-oriented Output object as input. The output is in a text format which can be piped forward
    '''

    from miscClasses import colorWidth as cW	# Custom function that sets width of text fields and colors it.

    print( cW( out.settings[ 'name' ] + ':', 12, colorTitle ), end = '' )			# Print name of account and allow for further text

    if out.settings[ 'showNums' ] :

        print( "( total: %d | unseen: %d )" % (out.numAll, out.numUnseen) )

    print( '\n' )


    # Preamble printed. Now start printing individual email information

    if out.settings[ 'showUnseen' ] :		# Show only unseen messages

        for ii in range( len( out.emails ) ) :

            email = out.emails[ ii ]

            print( cW( str(ii + 1), out.numDigits, align = '>' ) + '.  ' + cW( email.Date, 17, colorDate ) + '    ' + cW( email.From, 30, colorFrom ) + '   ' + cW( email.Subject, 120, colorSubjectUnseen, fill = False ) )

    else :						# Show ALL messages. Different formatting scheme.

        if showFlags :			# Global setting which declares that the flags associated with each message must be displayed

            flags = lambda x : '  [ ' + cW( x, 2, colorFlag ) + ']   '

        else :

            flags = lambda x : '.   '


        for ii in range( len( out.emails ) ) :

            email = out.emails[ ii ]

            if email.Seen :			# Email has a Seen flag.

                flag = ' '
                colorSubject = colorSubjectSeen

            else :
                flag = 'N'
                colorSubject = colorSubjectUnseen

            print( cW( str(ii + 1), out.numDigits, align = '>' ) + flags( flag ) + cW( email.Date, 17, colorDate ) + '    ' + cW( email.From, 30, colorFrom ) + '   ' + cW( email.Subject, 120, colorSubject ) )
示例#3
0
def main():
    '''
    Main function that starts the execution of all of the code.
    '''

    args = argParse()

    # Specify default locations for configuration and specification files:

    import os

    homeFolder = os.getenv("HOME")  # Basically the value in $HOME
    packageFolder = '/usr/local/share/fetchheaders'  # Location of folder containing all package files

    #	packageFolder = '.'

    fileConf = homeFolder + '/.fetchheaders.conf'

    fileSpec = packageFolder + '/fetchheaders.conf.spec'  # Path to config specification file

    # Check if a configuration file has been specified using the -c or --config flag.

    if args.config:  # A configuration file has been provided

        fileConf = args.config

    # Read in settings and options from configuration files :

    servers, globalSettings = setOptions(fileConf, fileSpec)

    # Override settings and options from command-line arguments :

    servers, globalSettings = applyArgs(args, servers, globalSettings)

    # Apply Global Settings. These are applied outside of pollAccount which acts on each account independantly.

    applyGlobalSettings(
        globalSettings
    )  # Apply the global settings contained in the 'globalSettings' dictionary we created from the configuration file and command-line arguments

    # Now we determine whether the output is intended to go to the terminal (stdout) straight or passed on to urwid

    if globalSettings['terminal']:  # Do NOT use urwid

        from miscClasses import threadedExec

        for out in threadedExec(servers, maxThreads):

            if out.error:  # If an error occurs while constructing the Output object the exception is caught and the error flag is set

                from miscClasses import colorWidth as cW

                print(
                    cW(out.settings['name'] + ':', 12, colorTitle), end=''
                )  # We indicate in the output that an Error has occurred.
                print("Error!\n\n")

            else:

                display(out)

    else:

        # Use urwid to display the results, interact with the display and possibly flag messages for deletion:

        from urwidDisplay import urwidDisplay

        # Create instance of the imported class to create and start the urwid loop to display emails

        settings = {'maxThreads': maxThreads, 'showFlags': showFlags}

        urwidDisplay(servers, settings)
示例#4
0
def main() :

    '''
    Main function that starts the execution of all of the code.
    '''

    args = argParse()

    # Specify default locations for configuration and specification files:

    import os

    homeFolder = os.getenv( "HOME" )	# Basically the value in $HOME
    packageFolder = '/usr/local/share/fetchheaders'		# Location of folder containing all package files

#	packageFolder = '.'

    fileConf = homeFolder + '/.fetchheaders.conf'

    fileSpec = packageFolder + '/fetchheaders.conf.spec'	# Path to config specification file

    # Check if a configuration file has been specified using the -c or --config flag.

    if args.config :		# A configuration file has been provided

        fileConf = args.config


    # Read in settings and options from configuration files :

    servers, globalSettings = setOptions( fileConf, fileSpec )


    # Override settings and options from command-line arguments :

    servers, globalSettings = applyArgs( args, servers, globalSettings )


    # Apply Global Settings. These are applied outside of pollAccount which acts on each account independantly.

    applyGlobalSettings( globalSettings ) 		# Apply the global settings contained in the 'globalSettings' dictionary we created from the configuration file and command-line arguments


    # Now we determine whether the output is intended to go to the terminal (stdout) straight or passed on to urwid

    if globalSettings[ 'terminal' ]:		# Do NOT use urwid

        from miscClasses import threadedExec

        for out in threadedExec( servers, maxThreads ):

            if out.error:         # If an error occurs while constructing the Output object the exception is caught and the error flag is set

                from miscClasses import colorWidth as cW

                print( cW( out.settings[ 'name' ] + ':', 12, colorTitle ), end = '' )       # We indicate in the output that an Error has occurred.
                print( "Error!\n\n" )

            else:

                display(out)

    else:

        # Use urwid to display the results, interact with the display and possibly flag messages for deletion:

        from urwidDisplay import urwidDisplay

        # Create instance of the imported class to create and start the urwid loop to display emails

        settings = { 'maxThreads': maxThreads, 'showFlags': showFlags }

        urwidDisplay( servers, settings )