Skip to content

Commit

Permalink
Added conf handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeide committed Jan 23, 2014
1 parent d9669a0 commit 91c8d09
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
11 changes: 6 additions & 5 deletions poortego/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 31,20 @@ class Dispatcher(Cmd):
#
# Construction
#
def __init__(self):
def __init__(self, conf_settings):
Cmd.__init__(self)
self.conf_settings = conf_settings
self.namespace = 'poortego'
self.prompt = 'poortego> '
self.prompt = self.conf_settings['poortego_prompt'] ' '
self.do_poortego_reinitialize('')

#
# poortego_reinitialize
#
def do_poortego_reinitialize(self, arg):
"""Command to reset poortego settings back to default"""
self.my_graph = Graph()
self.my_session = Session()
self.my_graph = Graph(self.conf_settings)
self.my_session = Session(self.conf_settings)
self.my_graph.set_defaults()
self.my_session.current_node_id = self.my_graph.poortego_root_node._id

Expand All @@ -57,7 58,7 @@ def do_poortego_login(self, arg):
self.stdout.write("\n Password: ")
password_string = (self.stdin.readline()).replace('\n','')
attempted_user = User(username_string, password_string)
if (attempted_user.authenticate()):
if (attempted_user.authenticate(self.conf_settings['password_file'])):
self.my_session.user = attempted_user

#
Expand Down
5 changes: 3 additions & 2 deletions poortego/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 17,10 @@
class Graph:
"""Used for GraphDB interaction"""

def __init__(self):
def __init__(self, conf_settings):
"""Constructor, setup GraphDB connection"""
self.graph_db = neo4j.GraphDatabaseService()
self.conf_settings = conf_settings
self.graph_db = neo4j.GraphDatabaseService(str(self.conf_settings['neo4j_uri']))
self.set_defaults()

def set_defaults(self):
Expand Down
5 changes: 3 additions & 2 deletions poortego/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 11,10 @@

class Session:
"""Used for tracking Poortego session state"""
def __init__(self):
def __init__(self, conf_settings):
self.conf_settings = conf_settings
self.user = User('guest','guest')
self.user.authenticate()
self.user.authenticate(conf_settings['password_file'])
self.home_node_id = -1
self.current_node_id = -1
now_string = time.strftime("%Y-%m-%d %H:%M:%S")
Expand Down
4 changes: 2 additions & 2 deletions poortego/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 10,15 @@
class User:
"""Used for tracking Poortego user"""
def __init__(self, username, password):
self.password_file = 'poortego_passwd.txt'
self.username = username
self.password = password
self.authenticated = False
self.groups = set()

def authenticate(self):
def authenticate(self, password_file):
"""Stupid/basic authentication against a file - update before using in production"""
# TODO - improve authentication
self.password_file = password_file
with open(self.password_file, 'r') as users_file:
userreader = csv.reader(users_file, delimiter=':')
for row in userreader:
Expand Down
16 changes: 12 additions & 4 deletions poortego_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,15 @@
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)

# Fire up command dispatcher
from poortego.dispatcher import Dispatcher
my_dispatcher = Dispatcher()
my_dispatcher.cmdloop()
# Default poortego configuration locations
conf_dir = cmd_folder '/conf/'
conf_file = 'poortego.conf'

# Start Poortego Shell
from poortego.poortego import Poortego
poortego = Poortego(conf_dir, conf_file)
print "[DEBUG] Displaying Poortego Configuration:"
poortego.display_conf_settings()
print "\n[DEBUG] Done Displaying Poortego Configuration\n\n"
poortego.start_shell()

0 comments on commit 91c8d09

Please sign in to comment.