The console is the first segment of the AirBnB project at Holberton School that will collectively cover fundamentals concepts of higher level programming. The goal of AirBnB project is to eventually deploy our server a simple copy of the AirBnB Website(HBnB). A command interpreter is created in this segment to manage objects for the AirBnB(HBnB) website.
- Create a new object (ex: a new User or a new Place)
- Retrieve an object from a file, a database etc...
- Do operations on objects (count, compute stats, etc...)
- Update attributes of an object
- Destroy an object
This project is interpreted/tested on Ubuntu 14.04 LTS using python3 (version 3.4.3)
- Clone this repository:
git clone "https://github.com/alexaorrico/AirBnB_clone.git"
- Access AirBnb directory:
cd AirBnB_clone
- Run hbnb(interactively):
./console
and enter command - Run hbnb(non-interactively):
echo "<command>" | ./console.py
console.py - the console contains the entry point of the command interpreter. List of commands this console current supports:
EOF
- exits consolequit
- exits console<emptyline>
- overwrites default emptyline method and does nothingcreate
- Creates a new instance ofBaseModel
, saves it (to the JSON file) and prints the iddestroy
- Deletes an instance based on the class name and id (save the change into the JSON file).show
- Prints the string representation of an instance based on the class name and id.all
- Prints all string representation of all instances based or not on the class name.update
- Updates an instance based on the class name and id by adding or updating attribute (save the change into the JSON file).
base_model.py - The BaseModel class from which future classes will be derived
def __init__(self, *args, **kwargs)
- Initialization of the base modeldef __str__(self)
- String representation of the BaseModel classdef save(self)
- Updates the attributeupdated_at
with the current datetimedef to_dict(self)
- returns a dictionary containing all keys/values of the instance
Classes inherited from Base Model:
/models/engine
: directory contains File Storage class that handles JASON serialization and deserialization :
file_storage.py - serializes instances to a JSON file & deserializes back to instances
def all(self)
- returns the dictionary __objectsdef new(self, obj)
- sets in __objects the obj with key .iddef save(self)
- serializes __objects to the JSON file (path: __file_path)def reload(self)
- deserializes the JSON file to __objects
Interactive mode: Non-interactive mode:
No known bugs at this time.
Alexa Orrico - Github | Twitter
Jennifer Huang - Github | Twitter
Public Domain. No copy write protection.