-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
195 changed files
with
10,346 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
# sets up the web servers for the deployment of web_static | ||
|
||
sudo apt-get -y update | ||
sudo apt-get -y upgrade | ||
sudo apt-get -y install nginx | ||
sudo mkdir -p /data/web_static/releases/test /data/web_static/shared | ||
echo "This is a test" | sudo tee /data/web_static/releases/test/index.html | ||
sudo ln -sf /data/web_static/releases/test/ /data/web_static/current | ||
sudo chown -hR ubuntu:ubuntu /data/ | ||
sudo sed -i '38i\\tlocation /hbnb_static/ {\n\t\talias /data/web_static/current/;\n\t}\n' /etc/nginx/sites-available/default | ||
sudo service nginx start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Fabric script that generates a tgz archive from the contents of the web_static | ||
folder of the AirBnB Clone repo | ||
""" | ||
|
||
from datetime import datetime | ||
from fabric.api import local | ||
from os.path import isdir | ||
|
||
|
||
def do_pack(): | ||
"""generates a tgz archive""" | ||
try: | ||
date = datetime.now().strftime("%Y%m%d%H%M%S") | ||
if isdir("versions") is False: | ||
local("mkdir versions") | ||
file_name = "versions/web_static_{}.tgz".format(date) | ||
local("tar -cvzf {} web_static".format(file_name)) | ||
return file_name | ||
except: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Fabric script based on the file 1-pack_web_static.py that distributes an | ||
archive to the web servers | ||
""" | ||
|
||
from fabric.api import put, run, env | ||
from os.path import exists | ||
env.hosts = ['142.44.167.228', '144.217.246.195'] | ||
|
||
|
||
def do_deploy(archive_path): | ||
"""distributes an archive to the web servers""" | ||
if exists(archive_path) is False: | ||
return False | ||
try: | ||
file_n = archive_path.split("/")[-1] | ||
no_ext = file_n.split(".")[0] | ||
path = "/data/web_static/releases/" | ||
put(archive_path, '/tmp/') | ||
run('mkdir -p {}{}/'.format(path, no_ext)) | ||
run('tar -xzf /tmp/{} -C {}{}/'.format(file_n, path, no_ext)) | ||
run('rm /tmp/{}'.format(file_n)) | ||
run('mv {0}{1}/web_static/* {0}{1}/'.format(path, no_ext)) | ||
run('rm -rf {}{}/web_static'.format(path, no_ext)) | ||
run('rm -rf /data/web_static/current') | ||
run('ln -s {}{}/ /data/web_static/current'.format(path, no_ext)) | ||
return True | ||
except: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Fabric script based on the file 2-do_deploy_web_static.py that creates and | ||
distributes an archive to the web servers | ||
""" | ||
|
||
from fabric.api import env, local, put, run | ||
from datetime import datetime | ||
from os.path import exists, isdir | ||
env.hosts = ['142.44.167.228', '144.217.246.195'] | ||
|
||
|
||
def do_pack(): | ||
"""generates a tgz archive""" | ||
try: | ||
date = datetime.now().strftime("%Y%m%d%H%M%S") | ||
if isdir("versions") is False: | ||
local("mkdir versions") | ||
file_name = "versions/web_static_{}.tgz".format(date) | ||
local("tar -cvzf {} web_static".format(file_name)) | ||
return file_name | ||
except: | ||
return None | ||
|
||
|
||
def do_deploy(archive_path): | ||
"""distributes an archive to the web servers""" | ||
if exists(archive_path) is False: | ||
return False | ||
try: | ||
file_n = archive_path.split("/")[-1] | ||
no_ext = file_n.split(".")[0] | ||
path = "/data/web_static/releases/" | ||
put(archive_path, '/tmp/') | ||
run('mkdir -p {}{}/'.format(path, no_ext)) | ||
run('tar -xzf /tmp/{} -C {}{}/'.format(file_n, path, no_ext)) | ||
run('rm /tmp/{}'.format(file_n)) | ||
run('mv {0}{1}/web_static/* {0}{1}/'.format(path, no_ext)) | ||
run('rm -rf {}{}/web_static'.format(path, no_ext)) | ||
run('rm -rf /data/web_static/current') | ||
run('ln -s {}{}/ /data/web_static/current'.format(path, no_ext)) | ||
return True | ||
except: | ||
return False | ||
|
||
|
||
def deploy(): | ||
"""creates and distributes an archive to the web servers""" | ||
archive_path = do_pack() | ||
if archive_path is None: | ||
return False | ||
return do_deploy(archive_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This file lists all individuals having contributed content to the repository. | ||
|
||
|
||
Jennifer Huang <[email protected]> | ||
Alexa Orrico <[email protected]> | ||
Joann Vuong <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,164 @@ | ||
# AirBnB_clone_v4 | ||
# AirBnB Clone - The Console | ||
The console is the first segment of the AirBnB project at Holberton School that will collectively cover fundamental 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. | ||
|
||
#### Functionalities of this command interpreter: | ||
* 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 | ||
|
||
## Table of Content | ||
* [Environment](#environment) | ||
* [Installation](#installation) | ||
* [File Descriptions](#file-descriptions) | ||
* [Usage](#usage) | ||
* [Examples of use](#examples-of-use) | ||
* [Bugs](#bugs) | ||
* [Authors](#authors) | ||
* [License](#license) | ||
|
||
## Environment | ||
This project is interpreted/tested on Ubuntu 14.04 LTS using python3 (version 3.4.3) | ||
|
||
## Installation | ||
* 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` | ||
|
||
## File Descriptions | ||
[console.py](console.py) - the console contains the entry point of the command interpreter. | ||
List of commands this console current supports: | ||
* `EOF` - exits console | ||
* `quit` - exits console | ||
* `<emptyline>` - overwrites default emptyline method and does nothing | ||
* `create` - Creates a new instance of`BaseModel`, saves it (to the JSON file) and prints the id | ||
* `destroy` - 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). | ||
|
||
#### `models/` directory contains classes used for this project: | ||
[base_model.py](/models/base_model.py) - The BaseModel class from which future classes will be derived | ||
* `def __init__(self, *args, **kwargs)` - Initialization of the base model | ||
* `def __str__(self)` - String representation of the BaseModel class | ||
* `def save(self)` - Updates the attribute `updated_at` with the current datetime | ||
* `def to_dict(self)` - returns a dictionary containing all keys/values of the instance | ||
|
||
Classes inherited from Base Model: | ||
* [amenity.py](/models/amenity.py) | ||
* [city.py](/models/city.py) | ||
* [place.py](/models/place.py) | ||
* [review.py](/models/review.py) | ||
* [state.py](/models/state.py) | ||
* [user.py](/models/user.py) | ||
|
||
#### `/models/engine` directory contains File Storage class that handles JASON serialization and deserialization : | ||
[file_storage.py](/models/engine/file_storage.py) - serializes instances to a JSON file & deserializes back to instances | ||
* `def all(self)` - returns the dictionary __objects | ||
* `def new(self, obj)` - sets in __objects the obj with key <obj class name>.id | ||
* `def save(self)` - serializes __objects to the JSON file (path: __file_path) | ||
* ` def reload(self)` - deserializes the JSON file to __objects | ||
|
||
#### `/tests` directory contains all unit test cases for this project: | ||
[/test_models/test_base_model.py](/tests/test_models/test_base_model.py) - Contains the TestBaseModel and TestBaseModelDocs classes | ||
TestBaseModelDocs class: | ||
* `def setUpClass(cls)`- Set up for the doc tests | ||
* `def test_pep8_conformance_base_model(self)` - Test that models/base_model.py conforms to PEP8 | ||
* `def test_pep8_conformance_test_base_model(self)` - Test that tests/test_models/test_base_model.py conforms to PEP8 | ||
* `def test_bm_module_docstring(self)` - Test for the base_model.py module docstring | ||
* `def test_bm_class_docstring(self)` - Test for the BaseModel class docstring | ||
* `def test_bm_func_docstrings(self)` - Test for the presence of docstrings in BaseModel methods | ||
|
||
TestBaseModel class: | ||
* `def test_is_base_model(self)` - Test that the instatiation of a BaseModel works | ||
* `def test_created_at_instantiation(self)` - Test created_at is a pub. instance attribute of type datetime | ||
* `def test_updated_at_instantiation(self)` - Test updated_at is a pub. instance attribute of type datetime | ||
* `def test_diff_datetime_objs(self)` - Test that two BaseModel instances have different datetime objects | ||
|
||
[/test_models/test_amenity.py](/tests/test_models/test_amenity.py) - Contains the TestAmenityDocs class: | ||
* `def setUpClass(cls)` - Set up for the doc tests | ||
* `def test_pep8_conformance_amenity(self)` - Test that models/amenity.py conforms to PEP8 | ||
* `def test_pep8_conformance_test_amenity(self)` - Test that tests/test_models/test_amenity.py conforms to PEP8 | ||
* `def test_amenity_module_docstring(self)` - Test for the amenity.py module docstring | ||
* `def test_amenity_class_docstring(self)` - Test for the Amenity class docstring | ||
|
||
[/test_models/test_city.py](/tests/test_models/test_city.py) - Contains the TestCityDocs class: | ||
* `def setUpClass(cls)` - Set up for the doc tests | ||
* `def test_pep8_conformance_city(self)` - Test that models/city.py conforms to PEP8 | ||
* `def test_pep8_conformance_test_city(self)` - Test that tests/test_models/test_city.py conforms to PEP8 | ||
* `def test_city_module_docstring(self)` - Test for the city.py module docstring | ||
* `def test_city_class_docstring(self)` - Test for the City class docstring | ||
|
||
[/test_models/test_file_storage.py](/tests/test_models/test_file_storage.py) - Contains the TestFileStorageDocs class: | ||
* `def setUpClass(cls)` - Set up for the doc tests | ||
* `def test_pep8_conformance_file_storage(self)` - Test that models/file_storage.py conforms to PEP8 | ||
* `def test_pep8_conformance_test_file_storage(self)` - Test that tests/test_models/test_file_storage.py conforms to PEP8 | ||
* `def test_file_storage_module_docstring(self)` - Test for the file_storage.py module docstring | ||
* `def test_file_storage_class_docstring(self)` - Test for the FileStorage class docstring | ||
|
||
[/test_models/test_place.py](/tests/test_models/test_place.py) - Contains the TestPlaceDoc class: | ||
* `def setUpClass(cls)` - Set up for the doc tests | ||
* `def test_pep8_conformance_place(self)` - Test that models/place.py conforms to PEP8. | ||
* `def test_pep8_conformance_test_place(self)` - Test that tests/test_models/test_place.py conforms to PEP8. | ||
* `def test_place_module_docstring(self)` - Test for the place.py module docstring | ||
* `def test_place_class_docstring(self)` - Test for the Place class docstring | ||
|
||
[/test_models/test_review.py](/tests/test_models/test_review.py) - Contains the TestReviewDocs class: | ||
* `def setUpClass(cls)` - Set up for the doc tests | ||
* `def test_pep8_conformance_review(self)` - Test that models/review.py conforms to PEP8 | ||
* `def test_pep8_conformance_test_review(self)` - Test that tests/test_models/test_review.py conforms to PEP8 | ||
* `def test_review_module_docstring(self)` - Test for the review.py module docstring | ||
* `def test_review_class_docstring(self)` - Test for the Review class docstring | ||
|
||
[/test_models/state.py](/tests/test_models/test_state.py) - Contains the TestStateDocs class: | ||
* `def setUpClass(cls)` - Set up for the doc tests | ||
* `def test_pep8_conformance_state(self)` - Test that models/state.py conforms to PEP8 | ||
* `def test_pep8_conformance_test_state(self)` - Test that tests/test_models/test_state.py conforms to PEP8 | ||
* `def test_state_module_docstring(self)` - Test for the state.py module docstring | ||
* `def test_state_class_docstring(self)` - Test for the State class docstring | ||
|
||
[/test_models/user.py](/tests/test_models/test_user.py) - Contains the TestUserDocs class: | ||
* `def setUpClass(cls)` - Set up for the doc tests | ||
* `def test_pep8_conformance_user(self)` - Test that models/user.py conforms to PEP8 | ||
* `def test_pep8_conformance_test_user(self)` - Test that tests/test_models/test_user.py conforms to PEP8 | ||
* `def test_user_module_docstring(self)` - Test for the user.py module docstring | ||
* `def test_user_class_docstring(self)` - Test for the User class docstring | ||
|
||
|
||
## Examples of use | ||
``` | ||
vagrantAirBnB_clone$./console.py | ||
(hbnb) help | ||
Documented commands (type help <topic>): | ||
======================================== | ||
EOF all create destroy help quit show update | ||
(hbnb) all MyModel | ||
** class doesn't exist ** | ||
(hbnb) create BaseModel | ||
7da56403-cc45-4f1c-ad32-bfafeb2bb050 | ||
(hbnb) all BaseModel | ||
[[BaseModel] (7da56403-cc45-4f1c-ad32-bfafeb2bb050) {'updated_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772167), 'id': '7da56403-cc45-4f1c-ad32-bfafeb2bb050', 'created_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772123)}] | ||
(hbnb) show BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050 | ||
[BaseModel] (7da56403-cc45-4f1c-ad32-bfafeb2bb050) {'updated_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772167), 'id': '7da56403-cc45-4f1c-ad32-bfafeb2bb050', 'created_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772123)} | ||
(hbnb) destroy BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050 | ||
(hbnb) show BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050 | ||
** no instance found ** | ||
(hbnb) quit | ||
``` | ||
|
||
## Bugs | ||
No known bugs at this time. | ||
|
||
## Authors | ||
Alexa Orrico - [Github](https://github.com/alexaorrico) / [Twitter](https://twitter.com/alexa_orrico) | ||
Jennifer Huang - [Github](https://github.com/jhuang10123) / [Twitter](https://twitter.com/earthtojhuang) | ||
Jhoan Zamora - [Github](https://github.com/jzamora5) / [Twitter](https://twitter.com/JhoanZamora10) | ||
David Ovalle - [Github](https://github.com/Nukemenonai) / [Twitter](https://twitter.com/disartDave) | ||
|
||
Second part of Airbnb: Joann Vuong | ||
## License | ||
Public Domain. No copy write protection. |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/python3 | ||
""" Flask Application """ | ||
from models import storage | ||
from api.v1.views import app_views | ||
from os import environ | ||
from flask import Flask, render_template, make_response, jsonify | ||
from flask_cors import CORS | ||
from flasgger import Swagger | ||
from flasgger.utils import swag_from | ||
|
||
app = Flask(__name__) | ||
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True | ||
app.register_blueprint(app_views) | ||
cors = CORS(app, resources={r"/api/v1/*": {"origins": "*"}}) | ||
|
||
|
||
@app.teardown_appcontext | ||
def close_db(error): | ||
""" Close Storage """ | ||
storage.close() | ||
|
||
|
||
@app.errorhandler(404) | ||
def not_found(error): | ||
""" 404 Error | ||
--- | ||
responses: | ||
404: | ||
description: a resource was not found | ||
""" | ||
return make_response(jsonify({'error': "Not found"}), 404) | ||
|
||
app.config['SWAGGER'] = { | ||
'title': 'AirBnB clone Restful API', | ||
'uiversion': 3 | ||
} | ||
|
||
Swagger(app) | ||
|
||
|
||
if __name__ == "__main__": | ||
""" Main Function """ | ||
host = environ.get('HBNB_API_HOST') | ||
port = environ.get('HBNB_API_PORT') | ||
if not host: | ||
host = '0.0.0.0' | ||
if not port: | ||
port = '5000' | ||
app.run(host=host, port=port, threaded=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/python3 | ||
""" Blueprint for API """ | ||
from flask import Blueprint | ||
|
||
app_views = Blueprint('app_views', __name__, url_prefix='/api/v1') | ||
|
||
from api.v1.views.index import * | ||
from api.v1.views.states import * | ||
from api.v1.views.places import * | ||
from api.v1.views.places_reviews import * | ||
from api.v1.views.cities import * | ||
from api.v1.views.amenities import * | ||
from api.v1.views.users import * | ||
from api.v1.views.places_amenities import * |
Oops, something went wrong.