Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a0f3849
Initial commit
faithngetich Mar 19, 2017
c2e774e
add gitignore content
faithngetich Mar 24, 2017
d448eb3
add test cases
faithngetich Mar 30, 2017
09768e6
create models
faithngetich Apr 6, 2017
6e25acf
add logic
faithngetich Apr 12, 2017
ae804a3
[Chore] create class person
faithngetich Apr 13, 2017
14595cc
[Chore] add sub class staff
faithngetich Apr 13, 2017
1fca985
[Chore] create sub class Staff
faithngetich Apr 13, 2017
dd77b82
[Chore] create super class Room
faithngetich Apr 13, 2017
a5d7e88
[Chore] create sub class Office
faithngetich Apr 13, 2017
09f8ec8
[Chore] create sub class living space
faithngetich Apr 13, 2017
193e906
[Chore] Add attribute room capacity
faithngetich Apr 13, 2017
08c0046
[Chore] Remove existing functionality
faithngetich Apr 13, 2017
b311633
[chore] Add create room function
faithngetich Apr 16, 2017
fa0aaed
[chore] test create room method works
faithngetich Apr 16, 2017
9ccf89f
[chore] Add an add person method
faithngetich Apr 17, 2017
d24108c
[chore] Add reallocate function
faithngetich Apr 17, 2017
34fe90c
[chore] refactor the reallocation method
faithngetich Apr 18, 2017
42d7496
[chore] Add load people method
faithngetich Apr 18, 2017
eb37b18
[chore] Refactor the create room method
faithngetich Apr 18, 2017
2deaae9
[chore] Add print allocation method
faithngetich Apr 19, 2017
47f641c
[chore] Add print room method
faithngetich Apr 19, 2017
658095a
[chore] Refactor add person method
faithngetich Apr 19, 2017
6c8ae3d
[chore] Add a docopt app file
faithngetich Apr 20, 2017
c57049b
[chore] Add a save state method
faithngetich Apr 20, 2017
bda2874
[chore] Remove commented code
faithngetich Apr 20, 2017
5088d4f
[chore] Ignore and delete all db files
faithngetich Apr 20, 2017
47488ea
[chore] Refactor docopt file
faithngetich Apr 21, 2017
df0a0a2
[chore] Remove unused code
faithngetich Apr 21, 2017
337deb5
[chore] make all the functionality work
faithngetich Apr 21, 2017
9793ebc
[chore] deny staff accomodation
faithngetich Apr 23, 2017
1b8ecb4
[chore] Test reallocate function works
faithngetich Apr 24, 2017
9c33212
[chore] Test staff is added to all staff list
faithngetich Apr 24, 2017
456f7e4
[chore] Test office is created successfully
faithngetich Apr 24, 2017
68aa22d
[chore] Add more test methods
faithngetich Apr 25, 2017
00da78c
[chore] Update requirements
faithngetich Apr 25, 2017
2f81055
[chore] Refactor docopt file
faithngetich Apr 25, 2017
0b40614
[chore] Add load state test
faithngetich Apr 25, 2017
49ab8ae
[chore] Refactor docopt
faithngetich Apr 26, 2017
68d9542
[chore] Refactor models file
faithngetich Apr 26, 2017
833fbf3
[chore] Refactor and remove commented code
faithngetich Apr 26, 2017
89058ff
[chore] Add docstrings
faithngetich Apr 26, 2017
56e745b
[chore] Add docstrings
faithngetich Apr 26, 2017
e9a02c9
[chore] Delete unused files
faithngetich Apr 27, 2017
d05ad1b
[chore] Add a delete employee method
faithngetich May 1, 2017
0735b7e
[chore] Add a delete rooms method
faithngetich May 1, 2017
efee5b6
[chore] Name test methods correctly
faithngetich May 1, 2017
6668ed8
[chore] Add missing methods
faithngetich May 1, 2017
e712832
[chore] Refactor code
faithngetich May 1, 2017
e43c46b
[chore] Remove unused space
faithngetich May 1, 2017
ee58988
[chore] Refactor delete methods
faithngetich May 2, 2017
fee538c
[chore] Refactor delete room
faithngetich May 2, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[report]
omit=
*tests/*
*/python?.?/*
106 changes: 105 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
__pycache__/
*.py[cod]
*$py.class

*.pyc
# C extensions
*.so


# Distribution / packaging
.Python
env/
Expand Down Expand Up @@ -44,6 +45,7 @@ nosetests.xml
coverage.xml
*,cover
.hypothesis/
cover/

# Translations
*.mo
Expand Down Expand Up @@ -87,3 +89,105 @@ ENV/

# Rope project settings
.ropeproject


# Created by https://www.gitignore.io/api/python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing files and directories that you do not have in your project.

*.so
*.db

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

# End of https://www.gitignore.io/api/python
Empty file added FETCH_HEAD
Empty file.
Empty file added __init__.py
Empty file.
193 changes: 193 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@

"""
Usage:
amity create_room (O|L) <room_name>...
amity delete_rooms(args['<room_name>'])
amity add_person <first_name> <last_name> (F | S) [--wants_accomodation=value]
amity delete_employee(int(args['<person_id>']))
amity print_allocations [-output=<filename>]
amity reallocate_person <person_id> <new_room>
amity print_room <room_name>
amity print_unallocated [-output=<filename>]
amity load_people <filename>
amity delete_rooms(args['<room_name>'])
amity save_state (--database=<sqlite_database>)
amity load_state
amity (-i | --interactive)
amity (-h | --help | --version)
Options:
-i, --interactive Interactive Mode
-h, --help Show this screen and exit.
-a, --wants_accomodation=<opt> Person wants accomodation [default: N]
-d, --database=<sqlite_database> Save state to specified database [default: amity_db]
"""
import cmd, os, sys
from docopt import docopt, DocoptExit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a line of separation between all your import statements, e.g:

# system imports first
import os

#imports from packages imported
from docopt import docopt

#imports from your file system/ structure
from views import Amity

from pyfiglet import figlet_format
from termcolor import cprint
from views import Amity


amity = Amity()

def docopt_cmd(func):
"""
This decorator is used to simplify the try/except block and pass the result
of the docopt parsing to the called action.
"""
def fn(self, arg):
try:
opt = docopt(fn.__doc__,arg)
except DocoptExit as e:
# The DocoptExit is thrown when the args do not match.
# We print a message to the user and the usage block.

print('Invalid command!')
print(e)
return

except SystemExit:
# The SystemExit exception prints the usage for --help
# We do not need to do the print here.
return
return func(self, opt)

fn.__name__ = func.__name__
fn.__doc__ = func.__doc__
fn.__dict__.update(func.__dict__)
return fn

def intro():
cprint(figlet_format('Space Allocator', font='slant'),
'blue', attrs=['bold'])
print("Welcome to Amity! Here is a list of commands to get you started." +
" Type 'help' anytime to access documented commands")
print("\n\n")
cprint(__doc__, 'magenta')


class AmitySystem(cmd.Cmd):
prompt = '(Amity) '
file = None

@docopt_cmd
def do_create_room(self, args):
"""Usage: create_room (O|L) <room_name>..."""
room_type = None
if args["O"].upper() == 'O':
room_type = "O"
else:
room_type = "L"
amity.create_room(room_type, args["<room_name>"])


@docopt_cmd
def do_add_person(self, args):
"""
Usage: add_person <first_name> <last_name> (F | S) [--wants_accomodation=value]
"""
if args["F"].upper() == 'F':
category = "F"
else:
category = "S"
first_name = args["<first_name>"]
last_name = args["<last_name>"]
amity.add_person(first_name, last_name, category, args["--wants_accomodation"])

@docopt_cmd
def do_reallocate_person(self, args):
"""Usage: reallocate_person <person_id> <new_room>"""
if args["<person_id>"].isalpha():
print("person id cannot be string")
return
else:
(amity.reallocate_person(int(args['<person_id>']),
args['<new_room>']))

@docopt_cmd
def do_save_state(self, args):
"""Persists app data into the given db
Usage: save_state (--db_name=sqlite_db)
"""
db = args['--db_name']
amity.save_state(db)

@docopt_cmd
def do_print_unallocated(self, args):
"""Usage: print_unallocated [--file=text_file]"""
amity.print_unallocated(args['--file'])

@docopt_cmd
def do_print_allocations(self, args):
"""
Prints all rooms and the people in them.
Usage: print_allocations [--o=filename]
"""
filename = args["--o"] or ""
amity.print_allocations(filename)

@docopt_cmd
def do_delete_employee(self, args):
"""Usage: delete_employee <person_id>"""
if args["<person_id>"].isalpha():
print("person id cannot be string")
return
else:
(amity.delete_employee(int(args['<person_id>'])))

@docopt_cmd
def do_delete_rooms(self, args):
"""Usage: delete_room <room_name>"""
amity.delete_rooms(args['<room_name>'])


@docopt_cmd
def do_load_state(self, arg):
"""
Loads data from the specified db into the app.
Usage: load_state <filename>
"""
amity.load_state(arg["<filename>"])

@docopt_cmd
def do_load_people(self, args):
"""Usage: load_state <text_file>"""
amity.load_people(args["<text_file>"])


@docopt_cmd
def do_print_room(self, args):
"""Usage: print_room <room_name>"""

room_name = args["<room_name>"]
amity.print_room(room_name)
@docopt_cmd
def do_clear(self, arg):
"""Clears screen"""

os.system('clear')

@docopt_cmd
def do_load_people(self, args):
"""Usage: load_state <text_file>"""
amity.load_people(args["<text_file>"])



def do_quit(self, arg):
"""Quits out of Interactive Mode."""

print('Thank you for using Amity. Adios!')
exit()


opt = docopt(__doc__, sys.argv[1:])

if opt['--interactive']:
os.system('clear')
intro()
AmitySystem().cmdloop()

print(opt)


Empty file added models/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions models/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
import sys
import sqlalchemy

from sqlalchemy import Column, Integer, String, ForeignKey, Text, Boolean
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker

from sqlalchemy import create_engine




Base = declarative_base()


class Person(Base):
"""creates a people's table"""
__tablename__ = "People"

id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
first_name = Column(String, nullable=False)
last_name = Column(String, nullable=False)
category = Column(String, nullable=False)
wants_accomodation = Column(Boolean)

def __repr__(self):
return 'first name{} last name{}'.format(self.first_name,self.last_name)


class Room(Base):
"""creates rooms tables"""
__tablename__ = "Rooms"

id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String, nullable=False)
room_type = Column(String, nullable=False)
room_capacity = Column(Integer, nullable=False)
occupants = Column(String,nullable=True)


class DatabaseCreator(object):
"""creating database connection to object"""
def __init__(self, db_name=None):
self.db_name = db_name + '.db'
self.engine = create_engine('sqlite:///' + self.db_name)
Base.metadata.create_all(self.engine)
session_maker = sessionmaker(bind=self.engine)
self.session = session_maker()




Loading