Exemplo n.º 1
0
def perform_command(command):
    """
    Performs the command by name.
    Stores the result in `Storage()`.
    :param command: command name, selected by user.
    """

    command = command.lower()
    routes = get_routes()

    command_class = routes[command]
    command_inst = command_class()

    try:
        storage = Storage()
        if len(storage.items) == 0:
            try:
                with open('data.pkl', 'rb') as fromfile:
                    storage.items = pickle.load(fromfile)
                fromfile.close()
            except:
                print('no file')
        command_inst.perform(storage.items)
    except KeyError:
        print('Bad command, try again.')
    except UserExitException as ex:
        print(ex)
        raise
Exemplo n.º 2
0
def main():
    """
    Main method, works infinitelly until user runs `exit` command.
    Or hits `Ctrl+C` in the console.
    """

    storage = Storage()

    try:
        with open('storage.dat', 'rb') as stor:
            storage.items = pickle.load(stor)
    except IOError:
        pass

    while True:
        try:
            command = parse_user_input()
            perform_command(command)
        except UserExitException:
            break
        except KeyboardInterrupt:
            print('Shutting down, bye!')
            break
Exemplo n.º 3
0
Arquivo: app.py Projeto: andyzt/tceh
    return render_template('home.html',
                           form=form,
                           items=items_to_validate,
                           )

@app.route('/shutdown', methods=['GET'])
def shutdown():
    shutdown_server()
    storage=Storage()
    with open(persons_file, 'w') as _file:
        result_json = PostEncoder().encode(storage.items)
        _file.write(result_json)

    return 'Server shutting down...'


if __name__ == '__main__':
    storage = Storage()

    persons_file = os.path.join('files', 'objects.json')

    with open(persons_file) as _file:
        models = json.load(_file, cls=PostDecoder)
        storage.items = models

    app.run()