Exemplo n.º 1
0
def main():
    arg = docopt.docopt("""
    Usage: diarybot2.py [options]

    -v                    Verbose
    --no-chat             Don't talk to slack at all
    --drew-bot            Limit to just drewp healthbot
    """)
    verboseLogging(arg['-v'])

    configGraph = Graph()
    configGraph.parse('bots-secret.n3', format='n3')
    if arg['--drew-bot']:
        os.environ['DIARYBOT_AGENT'] = 'http://bigasterisk.com/foaf.rdf#drewp'
        for botSubj in configGraph.subjects(RDF.type, DB['DiaryBot']):
            if botSubj != BOT['healthBot']:
                print(f'remove {botSubj}')
                configGraph.remove((botSubj, RDF.type, DB['DiaryBot']))

    ich = None
    if not arg['--no-chat']:
        ich = IncomingChatHandler()
        chat = ChatInterface(ich.onMsg)
    else:
        chat = NoChat()
    bots = makeBots(chat, configGraph)
    if ich:
        ich.lateInit(bots, chat)

    for s, p, o in configGraph.triples((None, FOAF['name'], None)):
        _foafName[s] = o

    reactor.listenTCP(
        9048,
        cyclone.web.Application([
            (r'/', index),
            (r'/dist/(bundle\.js)', cyclone.web.StaticFileHandler, {
                'path': 'dist'
            }),
            (r'/([^/]+)/message', message),
            (r'/([^/]+)/structuredInput', StructuredInput),
            (r'/([^/]+)/history(/[^/]+)?', history),
            (r'/([^/]+)/([^/]+)', EditForm),
        ],
                                bots=bots,
                                configGraph=configGraph,
                                debug=True),
        interface='::')
    reactor.run()
Exemplo n.º 2
0
def main():
    args = docopt.docopt('''
Usage:
  hg_status.py [options]

Options:
  -v, --verbose  more logging
''')
    verboseLogging(args['--verbose'])

    import sys
    sys.path.append('/usr/lib/python3/dist-packages')
    import OpenSSL

    yaml = YAML(typ='safe')
    config = yaml.load(open('config.yaml'))
    repos = [Repo(Path(row['dir']), row['github']) for row in config['hg_repos']]

    class Application(cyclone.web.Application):

        def __init__(self):
            handlers = [
                (r"/()", cyclone.web.StaticFileHandler, {
                    'path': '.',
                    'default_filename': 'index.html'
                }),
                (r'/build/(bundle\.js)', cyclone.web.StaticFileHandler, {
                    'path': './build/'
                }),
                (r'/status/events', Statuses),
                (r'/githubSync', GithubSync),
            ]
            cyclone.web.Application.__init__(
                self,
                handlers,
                repos=repos,
                debug=args['--verbose'],
                template_path='.',
            )

    reactor.listenTCP(10001, Application())
    reactor.run()
Exemplo n.º 3
0
def main():
    arg = docopt("""
    Usage: report.py [options]

    -v                    Verbose
    """)
    verboseLogging(arg['-v'])
    log.info('startup')

    masterGraph = PatchableGraph()
    eventsInGraph: Set[URIRef] = set()
    coll = MongoClient(
        'mongodb',
        tz_aware=True).get_database('timebank').get_collection('webproxy')

    class Application(cyclone.web.Application):
        def __init__(self):
            handlers = [
                (r"/()", cyclone.web.StaticFileHandler, {
                    "path": ".",
                    "default_filename": "index.html"
                }),
                (r'/build/(bundle\.js)', cyclone.web.StaticFileHandler, {
                    "path": "build"
                }),
                (r'/graph/webevents', CycloneGraphHandler, {
                    'masterGraph': masterGraph
                }),
                (r'/graph/webevents/events', CycloneGraphEventsHandler, {
                    'masterGraph': masterGraph
                }),
            ]
            cyclone.web.Application.__init__(self,
                                             handlers,
                                             masterGraph=masterGraph,
                                             coll=coll)

    task.LoopingCall(update, masterGraph, eventsInGraph, coll).start(10)
    reactor.listenTCP(10001, Application())
    log.info('serving')
    reactor.run()
Exemplo n.º 4
0
def main():
    args = docopt.docopt('''
Usage:
  net_route_input.py [options]

Options:
  -v, --verbose  more logging
''')
    verboseLogging(args['--verbose'])

    db = pymongo.MongoClient('mongodb.default.svc.cluster.local',
                             tz_aware=True).get_database('timebank')
    hosts = db.get_collection('hosts')
    routes = db.get_collection('routes')
    fillHosts(hosts)

    poller = Poller(routes)

    reactor.listenTCP(
        8000,
        cyclone.web.Application(
            [
                (r'/(|bundle\.js|main\.css)', cyclone.web.StaticFileHandler, {
                    'path': 'build',
                    'default_filename': 'index.html'
                }),
                (r'/hosts', Hosts),
                (r'/modeSettings', ModeSettings),
                (r'/modeSet', SetMode),
                (r'/metrics', Metrics),
            ],
            debug=args['--verbose'],
            hosts=hosts,
            routes=routes,
            poller=poller,
        ))
    reactor.run()
Exemplo n.º 5
0
def main():
    arg = docopt("""
    Usage: environment.py [options]

    -v                    Verbose
    """)
    verboseLogging(arg['-v'])

    masterGraph = PatchableGraph()

    class Application(cyclone.web.Application):
        def __init__(self):
            handlers = [
                (r"/()", cyclone.web.StaticFileHandler, {
                    "path": ".",
                    "default_filename": "index.html"
                }),
                (r'/graph/environment', CycloneGraphHandler, {
                    'masterGraph': masterGraph
                }),
                (r'/graph/environment/events',
                 CycloneGraphEventsHandlerWithCors, {
                     'masterGraph': masterGraph
                 }),
                (r'/doc', Doc),  # to be shared
                (r'/stats/(.*)', StatsHandler, {
                    'serverName': 'environment'
                }),
            ]
            cyclone.web.Application.__init__(self,
                                             handlers,
                                             masterGraph=masterGraph)

    task.LoopingCall(update, masterGraph).start(1)
    reactor.listenTCP(9075, Application())
    reactor.run()
Exemplo n.º 6
0
                g.add((uri, ROOM['assignedIp'], Literal(ip), ctx))

                if hostname != '*':
                    g.add((uri, ROOM['dhcpHostname'], Literal(hostname), ctx))

            self.graph.setToGraph(g)
            
if __name__ == '__main__':
    arg = docopt("""
    Usage: store.py [options]

    -v           Verbose
    --port PORT  Serve on port [default: 9073].
    """)

    verboseLogging(arg['-v'])

    masterGraph = PatchableGraph()
    poller = Poller(masterGraph)

    reactor.listenTCP(
        int(arg['--port']),
        cyclone.web.Application(
            [
                (r"/()", cyclone.web.StaticFileHandler,
                 {"path": ".", "default_filename": "index.html"}),
                (r'/graph', CycloneGraphHandler, {'masterGraph': masterGraph}),
                (r'/graph/events', CycloneGraphEventsHandler, {'masterGraph': masterGraph}),
                (r'/stats/(.*)', StatsHandler, {'serverName': 'dhcpleases'}),
            ], masterGraph=masterGraph
        ))
Exemplo n.º 7
0
class Metrics(cyclone.web.RequestHandler):
    def get(self):
        self.add_header('content-type', 'text/plain')
        self.write(generate_latest(REGISTRY))


class Application(cyclone.web.Application):
    def __init__(self):
        handlers = [
            (r"/", Index),
            (r'/metrics', Metrics),
            (r"/(sw-import\.js)", cyclone.web.StaticFileHandler, {
                "path": "./"
            }),
            (r'/icons/(.*\.svg)', cyclone.web.StaticFileHandler, {
                "path":
                "node_modules/.pnpm/[email protected]/node_modules/flat-color-icons/svg/"
            }),
            (r"/((?:components/)?[a-zA-Z0-9-]+\.(?:png|jpg|js|css|html))",
             cyclone.web.StaticFileHandler, {
                 "path": "./build/"
             }),
        ]
        cyclone.web.Application.__init__(self, handlers)


if __name__ == '__main__':
    verboseLogging(True)
    reactor.listenTCP(8010, Application())
    reactor.run()
Exemplo n.º 8
0
                    "value": 1 if lastMinActive else 0
                },
                "time": now
            })
            self.lastSent = lastMinActive
            self.lastSentTime = now

            try:
                client.write_points(self.points, time_precision='s')
            except influxdb.exceptions.InfluxDBServerError as e:
                log.error(repr(e))
                reactor.crash()
            self.points = []


verboseLogging(False)

masterGraph = PatchableGraph()
poller = Poller()

reactor.listenTCP(9107,
                  cyclone.web.Application([
                      (r'/', Root),
                      (r'/idle', Idle),
                      (r'/graph/xidle', CycloneGraphHandler, {
                          'masterGraph': masterGraph
                      }),
                      (r'/graph/xidle/events', CycloneGraphEventsHandler, {
                          'masterGraph': masterGraph
                      }),
                  ]),
Exemplo n.º 9
0
    def bind(self):
        self.loop = task.LoopingCall(self.watch)
        self.loop.start(1, now=True)

    def unbind(self):
        self.loop.stop()


if __name__ == '__main__':
    arg = docopt("""
    Usage: mqtt_to_rdf.py [options]

    -v        Verbose
    --cs=STR  Only process config filenames with this substring
    """)
    verboseLogging(arg['-v'])

    config = Graph()
    for fn in Path('.').glob('conf/*.n3'):
        if not arg['--cs'] or str(arg['--cs']) in str(fn):
            log.debug(f'loading {fn}')
            config.parse(str(fn), format='n3')
        else:
            log.debug(f'skipping {fn}')

    masterGraph = PatchableGraph()

    brokerHost = 'mosquitto-frontdoor.default.svc.cluster.local'
    brokerPort = 10210

    debugPageData = {
Exemplo n.º 10
0
    """
    return Response(text=d, content_type='text/html')

arguments = docopt('''
this

Usage:
  this [-v] [--cam host] [--port to_serve]

Options:
  -v --verbose       more log
  --port n           http server [default: 10020]
  --cam host         hostname of esphome server
''')

verboseLogging(arguments['--verbose'])
logging.getLogger('aioesphomeapi.connection').setLevel(logging.INFO)

loop = asyncio.get_event_loop()

recv = CameraReceiver(loop, arguments['--cam'])
detector = apriltag.Detector()

f = recv.start()
loop.create_task(f)

start_time = time.time()
app = web.Application()
app.router.add_route('GET', '/stream', stream)
app.router.add_route('GET', '/', index)
try: