示例#1
0
 def do_all(self, arg):
     """ """
     args = parse(arg)
     data = args[0] + '.' + args[1]
     if data not in objects.keys:
         print("** class doesn't exist **")
     elif data in objects.keys:
         return list(str(data))
     else:
         return list(str(objects))
示例#2
0
    def do_show(self, arg):
        """ Prints the string representation of an instance\
        based on the class name and id """
        args = parse(arg)
        objects = models.storage.all()
        data = args[0] + '.' + args[1]

        if args == []:
            print("** class name missing **")
        elif args[0] not in self.classes:
            print("** class doesn't exist **")
        elif len(args) == 1:
            print("** instance id missing **")

        if data in objects.keys():
            print(objects[data])
示例#3
0
    def do_destroy(self, arg):
        """ Deletes an instance based on the class name and id"""
        args = parse(arg)
        if arg == []:
            print("** class name missing **")
        elif args[0] not in self.classes:
            print("** class doesn't exist **")
        elif len(args) == 1:
            print("** instance id missing **")

        else:
            data = args[0] + '.' + args[1]
            if data in objects.keys():
                objects.pop(data, None)
                objects.storage.save()
            else:
                print('** no instance found **')
def main():
    """Interface to the hardware of my noticeboard.
    This is meant for my noticeboard Emacs software to send commands to."""
    config_file_name = "/etc/noticeboard.conf"
    if os.path.isfile(config_file_name):
        with open(os.path.expanduser(
                os.path.expandvars(config_file_name))) as config_file:
            more_config = yaml.safe_load(config_file)
            rec_update(config, more_config)
    global expected_at_home_times
    expected_at_home_times = {
        day: [
            convert_interval(interval_string)
            for interval_string in interval_string_list
        ]
        for day, interval_string_list in config['expected_occupancy'].items()
    }
    print("noticeboard hardware controller starting")
    global photographing
    global photographing_duration
    photographing_duration = datetime.timedelta(0,
                                                config['camera']['duration'])

    controller = NoticeBoardHardware(config)

    print("noticeboard hardware controller started")
    while running:
        active = controller.step()
        # if we're stepping through an activity, ignore commands for now:
        if active:
            time.sleep(self.config['delays']['motor'])
        else:
            ready, _, _ = select.select([sys.stdin], [], [], main_loop_delay)
            if sys.stdin in ready:
                command = shlex.parse(sys.stdin.readline().strip())
                if command[0] in actions:
                    getattr(controller, command)(command)
                else:
                    print('(error "Unknown noticeboard command" ', command,
                          ')')

        # if photographing:
        #     take_photo()
        #     if datetime.datetime.now() >= photographing:
        #         photographing = False
    print("noticeboard hardware controller stopped")
示例#5
0
def arguments(p):
    arguments = [c.split('=', 1)[1] for c in parse(p)]
    return arguments
示例#6
0
def simple_call(command):
    try:
        return check_output(parse(command))
    except Exception as e:
        return 1