Beispiel #1
0
def local_main():
    import sys
    import os
    root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    if root not in sys.path:
        sys.path.append(root)
    sys.exit(main(CronTabber))
Beispiel #2
0
def local_main():  # pragma: no cover
    import sys
    import os
    root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    if root not in sys.path:
        sys.path.append(root)
    sys.exit(main(CronTabber))
Beispiel #3
0
    @staticmethod
    def backwards_action(x):
        print x[::-1]

    @staticmethod
    def upper_action(x):
        print x.upper()

    @staticmethod
    def action_converter(action):
        try:
            return getattr(Demo3App, "%s_action" % action)
        except AttributeError:
            raise Exception("'%s' is not a valid action" % action)

# normally, all the parameters are defined within the class, but
# the methods of this class itself are used in the configuration parameters.
# Python doesn't allow reference to class members until the class is entirely
# defined.  This tag along code injects the final config parameter after
# the class has been fully defined
list_of_actions = [x[:-7] for x in dir(Demo3App) if x.endswith('_action')]
doc_string = 'the action to take [%s]' % ', '.join(list_of_actions)
Demo3App.required_config.add_option('action', 'echo', doc_string,
                                short_form='a')

# if you'd rather invoke the app directly with its source file, this will
# allow it.
if __name__ == "__main__":
    import generic_app
    generic_app.main(Demo3App)
Beispiel #4
0
    @staticmethod
    def upper_action(x):
        print x.upper()

    @staticmethod
    def action_converter(action):
        try:
            return getattr(Demo3App, "%s_action" % action)
        except AttributeError:
            raise Exception("'%s' is not a valid action" % action)


# normally, all the parameters are defined within the class, but
# the methods of this class itself are used in the configuration parameters.
# Python doesn't allow reference to class members until the class is entirely
# defined.  This tag along code injects the final config parameter after
# the class has been fully defined
list_of_actions = [x[:-7] for x in dir(Demo3App) if x.endswith('_action')]
doc_string = 'the action to take [%s]' % ', '.join(list_of_actions)
Demo3App.required_config.add_option('action',
                                    'echo',
                                    doc_string,
                                    short_form='a')

# if you'd rather invoke the app directly with its source file, this will
# allow it.
if __name__ == "__main__":
    import generic_app
    generic_app.main(Demo3App)
                'option2=Option Two\n'
            )
    if not os.path.isfile(f3):
        with open(f3, 'w') as f:
            f.write(
                'option3=Option Three\n'
            )
    if not os.path.isfile(f0):
        with open(f0, 'w') as f:
            f.write(
                "application='%s'\n" % RelativeIncludesApp.__name__
            )
            f.write(
                "+include %s\n" % f1
            )
            f.write(
                "+include ./%s\n" % os.path.basename(f2)
            )
            f.write(
                "+include %s\n" % os.path.basename(f3)
            )
        return f0

if __name__ == "__main__":
    f = create_environment()
    if f:
        print "Now run:\n\tpython %s --admin.conf=%s\n" % (__file__, f)
    else:
        import generic_app
        generic_app.main(RelativeIncludesApp)
    # create the definitions for the parameters that are to come from
    # the command line or config file.
    required_config = Namespace()
    required_config.add_option(
        'option1',
        doc='Option 1',
        default='foo: FOO, bar: BAR',
        from_string_converter=decoder,
        to_string_converter=encoder
    )
    required_config.add_option(
        'option2',
        doc='Option 2',
        default={'baz': 'BAZ'},
        from_string_converter=decoder,
        to_string_converter=encoder
    )

    def __init__(self, config):
        self.config = config

    def main(self):
        print(self.config.option1['foo'])
        print(self.config.option2['baz'])


if __name__ == "__main__":
    import generic_app
    generic_app.main(CustomFormatterApp)
Beispiel #7
0
    app_name = 'custom_formatter_app'
    app_version = '0.1'
    app_description = __doc__

    # create the definitions for the parameters that are to come from
    # the command line or config file.
    required_config = Namespace()
    required_config.add_option('option1',
                               doc='Option 1',
                               default='foo: FOO, bar: BAR',
                               from_string_converter=decoder,
                               to_string_converter=encoder)
    required_config.add_option('option2',
                               doc='Option 2',
                               default={'baz': 'BAZ'},
                               from_string_converter=decoder,
                               to_string_converter=encoder)

    def __init__(self, config):
        self.config = config

    def main(self):
        print self.config.option1['foo']
        print self.config.option2['baz']


if __name__ == "__main__":
    import generic_app
    generic_app.main(CustomFormatterApp)
Beispiel #8
0
        """instantiate the threaded task manager to run the producer/consumer
        queue that is the heart of the processor."""
        self.config.logger.info('installing signal handers')
        signal.signal(signal.SIGTERM, respond_to_SIGTERM)
        signal.signal(signal.SIGHUP, respond_to_SIGTERM)
        self.task_manager = \
            self.config.producer_consumer.producer_consumer_class(
              self.config.producer_consumer,
              job_source_iterator=self.source_iterator,
              task_func=self.transform
            )

    #--------------------------------------------------------------------------
    def _cleanup(self):
        pass

    #--------------------------------------------------------------------------
    def main(self):
        """this main routine sets up the signal handlers, the source and
        destination crashstorage systems at the  theaded task manager.  That
        starts a flock of threads that are ready to shepherd crashes from
        the source to the destination."""

        self._setup_task_manager()
        self._setup_source_and_destination()
        self.task_manager.blocking_start(waiting_func=self.waiting_func)
        self._cleanup()
        
if __name__ == '__main__':
    main(FetchTransformSaveApp)
Beispiel #9
0
    import os
    f0 = '/tmp/relative_includes.ini'
    f1 = '/tmp/relative_includes_one.ini'
    f2 = '/tmp/relative_includes_two.ini'
    f3 = '/tmp/relative_includes_three.ini'
    if not os.path.isfile(f1):
        with open(f1, 'w') as f:
            f.write('option1=Option One\n')
    if not os.path.isfile(f2):
        with open(f2, 'w') as f:
            f.write('option2=Option Two\n')
    if not os.path.isfile(f3):
        with open(f3, 'w') as f:
            f.write('option3=Option Three\n')
    if not os.path.isfile(f0):
        with open(f0, 'w') as f:
            f.write("application='%s'\n" % RelativeIncludesApp.__name__)
            f.write("+include %s\n" % f1)
            f.write("+include ./%s\n" % os.path.basename(f2))
            f.write("+include %s\n" % os.path.basename(f3))
        return f0


if __name__ == "__main__":
    f = create_environment()
    if f:
        print "Now run:\n\tpython %s --admin.conf=%s\n" % (__file__, f)
    else:
        import generic_app
        generic_app.main(RelativeIncludesApp)
Beispiel #10
0
                 short_form='s',
                 from_string_converter=class_converter)
    d.add_option('storage',
                 'data_store.CannedDataSink',
                 'the class to handle database interaction for output',
                 short_form='d',
                 from_string_converter=class_converter)

    def __init__(self, config):
        super(DynApp, self).__init__()
        self.config = config

    def main(self):
        # the config object now has reference to a source and destination
        # classes. We need to instantiate the classes
        print(self.config.source.storage)
        source = self.config.source.storage(self.config)
        destination = self.config.destination.storage(self.config)
        # this is the actual functional part of the script.  Read rows from
        # source's 'fetch' iterator and spool them into the destination's
        # write function
        for row in source.fetch():
            destination.write(row)


# if you'd rather invoke the app directly with its source file, this will
# allow it.
if __name__ == "__main__":
    import generic_app
    generic_app.main(DynApp)
Beispiel #11
0
    s.add_option('storage', 'data_store.CannedDataSource',
                 'the class to handle database interaction for input',
                 short_form='s',
                 from_string_converter=class_converter)
    d.add_option('storage', 'data_store.CannedDataSink',
                 'the class to handle database interaction for output',
                 short_form='d',
                 from_string_converter=class_converter)

    def __init__(self, config):
        super(DynApp, self).__init__()
        self.config = config

    def main(self):
        # the config object now has reference to a source and destination
        # classes. We need to instantiate the classes
        print self.config.source.storage
        source = self.config.source.storage(self.config)
        destination = self.config.destination.storage(self.config)
        # this is the actual functional part of the script.  Read rows from
        # source's 'fetch' iterator and spool them into the destination's
        # write function
        for row in source.fetch():
            destination.write(row)

# if you'd rather invoke the app directly with its source file, this will
# allow it.
if __name__ == "__main__":
    import generic_app
    generic_app.main(DynApp)