コード例 #1
0
ファイル: slackBot.py プロジェクト: WeatheRay/RaspberryPi
def handle_command(command, channel):
    """
        Executes bot command if the command is known
    """
    # Default response is help text for the user
    default_response = "Not sure what you mean. Try *{}*.".format(
        EXAMPLE_COMMAND)

    # Finds and executes the given command, filling in response
    response = None
    # This is where you start to implement more commands!
    if command.startswith(EXAMPLE_COMMAND):
        response = "Sure...write some more code then I can do that!"
    if command == "/help" or "/h":
        response = "/update : picture of the living room and last change\n/status : last change"
    if command == "/update":
        frontDoor.status()
        response = log.read()
    if command == "/status":
        response = log.read()

    # Sends the response back to the channel
    slack_client.api_call("chat.postMessage",
                          channel=channel,
                          text=response or default_response)
コード例 #2
0
ファイル: resource.py プロジェクト: michaelmp/web-res-scaf
 def render_GET(self, request):
   headers.setContentHeaders(request)
   headers.setAccessControlHeaders(request)
   log.read(self)
   return json.dumps({
     "content": self.data,
     "links": map(lambda(child):{"name": child.name, "location": child.getPath()}, self.children.values()),
     "location": self.getPath(),
     "name": self.name
   })
コード例 #3
0
ファイル: resource.py プロジェクト: michaelmp/web-res-scaf
 def render_GET(self, request):
     headers.setContentHeaders(request)
     headers.setAccessControlHeaders(request)
     log.read(self)
     return json.dumps({
         "content":
         self.data,
         "links":
         map(
             lambda (child): {
                 "name": child.name,
                 "location": child.getPath()
             }, self.children.values()),
         "location":
         self.getPath(),
         "name":
         self.name
     })
コード例 #4
0
ファイル: barsm_utils.py プロジェクト: ktj100/linux
def checkB2AProcs1Child(msg, expectedData, aacm_pid, nameList, log):
    global barsm_pid

    print('Checking BARSM to AACM Processes Message!')

    # navigate to the end of the SYSLOG
    logs = []

    while not logs:
        logs = log.read('BARSM')
    
        if logs:
            gotAppNames = False
            for item in logs:
                if (item['message'][:35] == "DEBUG: Message sent with APP names:"):
                    gotAppNames = True

            if (gotAppNames):
                expectedName = list(filter(lambda t: "DEBUG: Message sent with APP names:" in t['message'], logs))[0]['message']
                expectedNameList = expectedName[-((5*msg[2])-1):].split(',', msg[2])
            else:
                logs = []

    proc_info = [
        { 'pid': barsm_pid, 'name': expectedNameList[0].encode(), 'type': 12 },
        { 'pid': aacm_pid, 'name': expectedNameList[1].encode(), 'type': 2 },
    ]

    print(expectedNameList)
    assert len(expectedNameList) == len(nameList) + 2

    for x in expectedNameList[2:]:
        for n in nameList:
            if x == n['name']:
                app_type = get_app_type(n)
                proc_info.append({ 'pid': int(n['pid']), 'name': n['name'].encode(), 'type': app_type })

    assert msg[0] == CMD_BARSM_TO_AACM_PROCESSES
    assert msg[1] == expectedData['numMsgDataBytes']
    assert msg[2] == expectedData['numProcesses']

    msgIndex = 2
    print('expected {}'.format(proc_info))
    for p in proc_info:
        msgIndex += 1
        assert msg[msgIndex] == p['pid']
        msgIndex += 1
        assert msg[msgIndex] == p['name']
        msgIndex += 1
        assert msg[msgIndex] == p['type']
コード例 #5
0
ファイル: barsm_utils.py プロジェクト: ktj100/linux
def waitForLaunch(log=None):
    notComplete = True

    disabled_pat = re.compile(r'NOTICE: Process for (?P<app>[A-Za-z0-9._]+) in (?P<path>[A-Za-z0-9._/]+) disabled permanently! \(0:Success\)')
    launched_pat = re.compile(r'SUCCESS: launched (?P<path>[A-Za-z0-9._/]+)/(?P<app>[A-Za-z0-9._]+) with name (?P<name>[a-z]{4}) with PID (?P<pid>\d+)')

    nameList = []
    while notComplete:
        check_barsm_running()
        logs = log.read('BARSM')

        msg_list = list(filter(lambda t: "COMPLETED: Launch sequence complete!" in t['message'], logs))
        launched_list = [p.groupdict() for p in [launched_pat.match(t['message']) for t in logs] if p]
        disabled_list = [p.groupdict() for p in [disabled_pat.match(t['message']) for t in logs] if p]

        if launched_list:
            for l in launched_list[:]:
                for n in nameList:
                    if n['app'] == l['app'] and n['path'] == l['path']:
                        n['pid'] = l['pid']
                        launched_list.remove(l)
            nameList.extend(launched_list)

        for d in disabled_list:
            for n in nameList[:]:
                if n['app'] == l['app'] and n['path'] == l['path']:
                    nameList.remove(n)

        if msg_list:
            print("Launch Complete message found!")
            notComplete = False

    global barsm_pid, barsm_spawned_pids
    print('BARSM: {}'.format(barsm_pid))
    all_child = proc.findchild(barsm_pid)

    child_pids = set([int(p['pid']) for p in all_child])
    barsm_spawned_pids = list(set(barsm_spawned_pids).union(child_pids))
    child_amount = len(all_child)
    return child_amount, nameList
コード例 #6
0
            display.user_data(user_data)
            if len(user_data) != 0:
                user_select = user.choice()
                updated_data = book.return_book(user_select, user_data,
                                                book_list)
                user_data = updated_data[0]
                book_list = updated_data[1]
                log_msg = updated_data[2]
                print(log_msg)

                #updating files according to change
                user.update(user_name, user_data)
                log.update(user_name, log_msg)
                book.update(book_list)

        elif user_choice == 3:
            display.heading("here are your logs")
            log.read(user_name)

        elif user_choice == 4:
            display.heading("here are the rules")
            display.library_rule()

        elif user_choice == 5:
            display.heading("program ended")
            run = False

        else:
            display.input_warning()
            invalid = True
コード例 #7
0
ファイル: main.py プロジェクト: jyesselm/BehaviorAssistant
    parser.add_argument('-p', help='program', required=True)
    parser.add_argument('-args', required=False)
    parser.add_argument('-files',required=False)
    args = parser.parse_args()
    return args

if __name__ == '__main__':

    # Brief sketch follows
    args = parse_args()
    config = get_configuration(os.getcwd())
    log = log.Log(config)
    if args.render is not None:
        # This means we render stuff in whatever renderer was specified 
        # in args.render (e.g. html or latex)
        log_entries = log.read(args.since, args.until)
        renderer = render.
        renderer.render(log_entries)
    else:
        # Then this is a commit
        needs_push = log.commit(args.command, args.command_args, template=args.template)
        if needs_push:
            notifications.show('According to your current configuration you need to push now!')
            while True:
                answer = notifications.input('Do you want to push? ([y]/n ').lower().strip()
                if answer[0] == 'n':
                    notifications.show('Skipping push per user input')
                    break
                elif answer[0] == 'y':
                    notifications.show('Pushing...')
                    log.push()