Example #1
0
    def __init__(self, version):
        Publisher.__init__(self)

        self.conf = Configuration(version)
        self.lastfocus = None
        self.unknown = None
        self.nav = {"bo": "bs", "bs": "lo", "lo": "ls", "ls": "bo"}
        self.index3 = {
            (True, True, True, False): ("ls", self.__calcLS),
            (True, True, False, True): ("lo", self.__calcLO),
            (True, False, True, True): ("bs", self.__calcBS),
            (False, True, True, True): ("bo", self.__calcBO)
        }
Example #2
0
def photo(ctx, photo):
    """ Publish a photo. """
    config = ctx.obj['config']

    local_file = config.path('data:path', "photos/%s" % (photo))
    remote_file = config.path('publisher:remote_path', 'static/%s/photos/%s' % (config.org.lower(), photo))

    with Publisher(config.get('publisher')) as publish:
        publish.file(local_file, remote_file)

    print("Successfully published '%s' to '%s'" % (local_file, remote_file))
Example #3
0
def txt(ctx):
    """ Publish the text version."""
    config = ctx.obj['config']

    local_file = config.path('data:path', 'MCUMC.md')
    remote_file = config.path('publisher:remote_path', 'MemberDirectory.txt')

    with Publisher(config.get('publisher')) as publish:
        publish.file(local_file, remote_file)

    print("Successfully published '%s' to '%s'" % (local_file, remote_file))
Example #4
0
def data(ctx):
    """ Publish the data file, directory.json. """
    config = ctx.obj['config']

    local_file = config.path('data:path', 'directory.json')
    remote_file = config.path('publisher:remote_path', 'static/%s/directory.json' % (config.org.lower()))

    with Publisher(config.get('publisher')) as publish:
        publish.file(local_file, remote_file)

    print("Successfully published '%s' to '%s'" % (local_file, remote_file))
Example #5
0
def pdf(ctx):
    """ Publish the PDF version. """
    config = ctx.obj['config']

    dir_local_file = config.path('data:path', '%s.pdf' % (config.org))
    dir_remote_file = config.path('publisher:remote_path', 'MemberDirectory.pdf')

    bdays_local_file = config.path('data:path', '%s-BDays.pdf' % (config.org))
    bdays_remote_file = config.path('publisher:remote_path', 'Birthdays.pdf')

    with Publisher(config.get('publisher')) as publish:
        publish.file(dir_local_file, dir_remote_file, binmode=True)
        print("Successfully published '%s' to '%s'" % (dir_local_file, dir_remote_file))

        publish.file(bdays_local_file, bdays_remote_file, binmode=True)
        print("Successfully published '%s' to '%s'" % (bdays_local_file, bdays_remote_file))
Example #6
0
def app(ctx):
    """ Publish the Plebeians Web App. """
    config = ctx.obj['config']

    # Organization data will NOT be published.
    org_path = "static/%s" % (config.org.lower())

    local_base_path = os.path.dirname(os.path.realpath(__file__+'../../..'))
    local_base_path += "/dist"

    remote_base_path = config.get('publisher:remote_path')

    count = 0
    with Publisher(config.get('publisher')) as publish:
        count = publish.directory(local_base_path, remote_base_path, [org_path])

    print("Successfully published %d files from '%s' to '%s'" % (count, local_base_path, remote_base_path))
Example #7
0
File: client.py Project: Ivoz/Modum
 def __init__(self, name, config):
     self.name = name
     self.config = config  # Overall config
     self.options = config.clients[name]  # Client options
     self.publisher = Publisher()
     # Initialize Irc connection object
     self.server = config.servers[self.options['server']]
     self.irc = Irc(self.server, self.publisher)
     # Configuration
     self.nick = self.options['nick']
     self.stdio = StdIO()
     self.sending = Queue()
     self.receiving = Queue()
     # Plugins
     self.plugins = {}
     plugins = ['Base'] + self.options['plugins'].keys()
     [self.load_plugin(p) for p in plugins]
     self.instance = None
Example #8
0
File: client.py Project: Ivoz/Modum
class Client(object):
    """An IRC Client, designed to be pluggable"""

    def __init__(self, name, config):
        self.name = name
        self.config = config  # Overall config
        self.options = config.clients[name]  # Client options
        self.publisher = Publisher()
        # Initialize Irc connection object
        self.server = config.servers[self.options['server']]
        self.irc = Irc(self.server, self.publisher)
        # Configuration
        self.nick = self.options['nick']
        self.stdio = StdIO()
        self.sending = Queue()
        self.receiving = Queue()
        # Plugins
        self.plugins = {}
        plugins = ['Base'] + self.options['plugins'].keys()
        [self.load_plugin(p) for p in plugins]
        self.instance = None

    def start(self):
        if self.instance is not None:
            raise
        self.publisher.subscribe(self.irc.sender, self.sending)
        self.publisher.subscribe(self.receiving, self.irc.receiver)
# TODO: Remove, debugging
        self.publisher.subscribe(self.stdio.output,
                self.irc.receiver, str)
        self.publisher.subscribe(self.stdio.output,
                self.irc.sender, str)
        from lib.irc import Msg
        self.publisher.subscribe(self.sending,
                self.stdio.input, Msg.from_msg)
        self.irc.connect()
        self.instance = gevent.spawn(self._event_loop)
        return self.instance

    def kill(self):
        """Completely close connection to server"""
        while not self.sending.empty():
            gevent.sleep(0.5)
        self.irc.kill()
# TODO: Remove, debugging
        self.publisher.unsubscribe(self.irc.sender, self.sending)
        self.publisher.unsubscribe(self.receiving, self.irc.receiver)
        self.publisher.unsubscribe(self.stdio.output,
            self.irc.receiver)
        self.publisher.unsubscribe(self.stdio.output,
            self.irc.sender)
        self.stdio.stop()
        self.receiving.put(FinishLoop)

    def load_plugin(self, plugin):
        if self._load_module(plugin):
            if hasattr(self.plugins[plugin], 'setup'):
                settings = None
                if plugin in self.config.plugins:
                    settings = self.config.plugins[plugin]
                botSettings = None
                if plugin in self.options['plugins']:
                    botSettings = self.options['plugins'][plugin]
                self.plugins[plugin].setup(settings, botSettings)

    def _event_loop(self):
        gevent.spawn(self.plugins['Base'].on_connect)
        for msg in self.receiving:
            if msg is FinishLoop:
                break
            for plugin in self.plugins.values():
                cmd = 'on_' + msg.cmd.lower()
                if hasattr(plugin, cmd):
                    func = getattr(plugin, cmd)
                    gevent.spawn(func, msg)
                if msg.ctcp is not None:
                    cmd = 'on_ctcp_' + msg.ctcp[0].lower()
                    if hasattr(plugin, cmd):
                        func = getattr(plugin, cmd)
                        gevent.spawn(func, msg)

    def _load_module(self, plugin):
        try:
            p_name = 'plugin.' + plugin.lower()
            p = __import__(p_name, fromlist=[plugin], level=-1)
            self.plugins[plugin] = getattr(p, plugin)(self)
            return True
        except ImportError as e:
            print str(e)
            return False
Example #9
0
# borrowed from https://github.com/aranaea/kafka-demo/blob/master/producer/src/app.py
from flask import Flask, request
import json
import lib.poisson as poisson
from lib.publisher import Publisher
import time
import logging
logging.basicConfig(level=logging.DEBUG)

app = Flask(__name__)

dispatcher = Publisher(logging) #TODO: There's probably a better way to encapsulate logging

@app.route("/")
def index():
    return "This is job trigger, please use /startjobs to trigger all the jobs"

@app.route("/startjobs", methods=['POST'])
def post_event():
   arrival_interval = 0
   for num in range(0,13):
       arrival_interval = arrival_interval + poisson.next_arrival_time()*10
       time.sleep(arrival_interval)
       app.logger.debug("Job ID: workload-%s produced at %s seconds" %(num,
             int(arrival_interval)))

       #message = request.get_json()
       message = "schedule : workload-%s" %num 
       app.logger.debug("request had the following data: {0}".format(message))
       #dispatcher.push(message)