Example #1
0
    def decorated(self):
        name = fn.__name__.replace('_', '-')
        if len(self.app.pargs.date) and self.app.pargs.date[0]:
            try:
                self.app.election.electiondate = parse_date(
                    self.app.pargs.date[0]
                )
                return fn(self)
            except ValueError:
                puts(
                    colored.yellow('Whoa there, friend! There was an error:\n')
                )
                text = '{0} could not be recognized as a date.\n'
                puts(text.format(colored.green(self.app.pargs.date[0])))

                # Should exit status 1 so we can script against it.
                self.app.close(1)

            return fn(self)
        else:
            text = 'Please specify an election date (e.g. `elex {0} 2015-11-\
03\`) or data file (e.g. `elex {0} --data-file path/to/file.json`). \n\nRun \
`elex` for help.\n'
            puts(colored.yellow(text.format(name)))

            # Should exit status 1 so we can script against it.
            self.app.close(1)
Example #2
0
 def decorated(self):
     name = fn.__name__.replace('_', '-')
     if len(self.app.pargs.date) and self.app.pargs.date[0]:
         try:
             self.app.election.electiondate = parse_date(self.app.pargs.date[0])
             return fn(self)
         except ValueError:
             puts(colored.yellow('Whoa there, friend! There was an error:\n'))
             puts('{0} could not be recognized as a date.\n'.format(colored.green(self.app.pargs.date[0])))
         return fn(self)
     else:
         puts(colored.yellow('Please specify an election date (e.g. `elex {0} 2015-11-03`) or data file (e.g. `elex {0} --data-file path/to/file.json`). \n\nRun `elex` for help.\n'.format(name)))
Example #3
0
def attach_election_date(app, wrapped_fn, callback_context):
    """
    Attaches value of date argument to election model used in commands.

    Common to both `accept_date_argument` and `require_date_argument`
    decorators (i.e., this is called whether the date argument is
    mandatory or optional).
    """
    try:
        app.election.electiondate = parse_date(app.pargs.date[0])
        return wrapped_fn(callback_context)
    except ValueError:
        text = '{0} could not be recognized as a date.'
        app.log.error(text.format(app.pargs.date[0]))
        app.close(1)

    return wrapped_fn(callback_context)
Example #4
0
 def decorated(self):
     name = fn.__name__.replace('_', '-')
     if not self.app.pargs.data_file and len(self.app.pargs.date) and self.app.pargs.date[0]:
         try:
             self.app.election.electiondate = parse_date(self.app.pargs.date[0])
             return fn(self)
         except ValueError:
             puts(colored.yellow('Whoa there, friend! There was an error:\n'))
             puts('{0} could not be recognized as a date.\n'.format(colored.green(self.app.pargs.date[0])))
         except KeyError:
             puts(colored.yellow('Whoa there, friend! There was an error:\n'))
             puts('You have not exported {0} as an environment variable.\n'.format(colored.green("AP_API_KEY")))
     elif self.app.pargs.data_file:
         self.app.election.electiondate = 'data file: {0}'.format(self.app.pargs.data_file)
         return fn(self)
     else:
         puts(colored.yellow('Please specify an election date (e.g. `elex {0} 2015-11-03`) or data file (e.g. `elex {0} --data-file path/to/file.json`). \n\nRun `elex` for help.\n'.format(name)))
Example #5
0
    def decorated(self):
        name = fn.__name__.replace('_', '-')
        if self.app.pargs.data_file:
            return fn(self)
        elif len(self.app.pargs.date) and self.app.pargs.date[0]:
            try:
                self.app.election.electiondate = parse_date(
                    self.app.pargs.date[0])
                return fn(self)
            except ValueError:
                text = '{0} could not be recognized as a date.'
                self.app.log.error(text.format(self.app.pargs.date[0]))
                self.app.close(1)

            return fn(self)
        else:
            text = 'No election date (e.g. `elex {0} 2015-11-\
03`) or data file (e.g. `elex {0} --data-file path/to/file.json`) specified.'

            self.app.log.error(text.format(name))
            self.app.close(1)
Example #6
0
    def decorated(self):
        name = fn.__name__.replace('_', '-')
        if self.app.pargs.data_file:
            return fn(self)
        elif len(self.app.pargs.date) and self.app.pargs.date[0]:
            try:
                self.app.election.electiondate = parse_date(
                    self.app.pargs.date[0]
                )
                return fn(self)
            except ValueError:
                text = '{0} could not be recognized as a date.'
                self.app.log.error(text.format(self.app.pargs.date[0]))
                self.app.close(1)

            return fn(self)
        else:
            text = 'No election date (e.g. `elex {0} 2015-11-\
03`) or data file (e.g. `elex {0} --data-file path/to/file.json`) specified.'
            self.app.log.error(text.format(name))
            self.app.close(1)