Skip to content

Commit

Permalink
Updates to entire framework
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeide committed Mar 5, 2014
1 parent f50328e commit 16c07ca
Show file tree
Hide file tree
Showing 87 changed files with 1,667 additions and 683 deletions.
1 change: 1 addition & 0 deletions conf/poortego.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 6,7 @@
# with the absolute path of the poortego conf directory.
#

db_type=neo4j
# neo4j URI - set as appropriate, some neo4j installs may need the "db/data/" path removed
neo4j_uri = http://localhost:7474/db/data/
# If using authentication set neo4j_uri like: http://username:password@host:port/db/data/
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions logs/README
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
Make this directory writeable by whichever user/group is running poortego.

Put info / debug / error messages into corresponding log files using log4py
124 changes: 0 additions & 124 deletions poortego/bak/graph.py.bak

This file was deleted.

51 changes: 0 additions & 51 deletions poortego/bak/testing.py

This file was deleted.

File renamed without changes.
76 changes: 36 additions & 40 deletions poortego/dispatcher/command/add.py → poortego/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@

import time

def poortego_add(dispatcher_object, args, opts):
def poortego_add(interface_obj, arg, opts):

# -t / --type
if opts.node_type:
Expand All @@ -15,29 15,29 @@ def poortego_add(dispatcher_object, args, opts):
## -v / --value
#if opts.node_value:
# node_dict = {'name':opts.node_value}
#else:
# dispatcher_object.stdout.write("Object Name or Value: ")
# object_val = (dispatcher_object.stdin.readline()).replace('\n','')
# #else:
# interface_obj.stdout.write("Object Name or Value: ")
# # object_val = (interface_obj.stdin.readline()).replace('\n','')
# node_dict = {'name':object_val}
## Get or Create Node
#node_addition = dispatcher_object.my_graph.get_or_create_indexed_node("NameIdx", "name", node_dict['name'], node_dict)
# #node_addition = interface_obj.my_session.my_db.get_or_create_indexed_node("NameIdx", "name", node_dict['name'], node_dict)
#
## Add type/category (labels in neo4j 2.x)
#dispatcher_object.my_graph.add_labels(node_addition, opts.node_type)
# ## Add type/category (labels in neo4j 2.x)
#interface_obj.my_session.my_db.add_labels(node_addition, opts.node_type)

# -v / --value
elif opts.node_value:
print "TODO: set node value from command option\n"
#node_dict = {'name':opts.node_value}
#node_addition = dispatcher_object.my_graph.get_or_create_indexed_node("NameIdx", "name", node_dict['name'], node_dict)
#node_addition = interface_obj.my_session.my_db.get_or_create_indexed_node("NameIdx", "name", node_dict['name'], node_dict)
#if opts.node_type:
# dispatcher_object.my_graph.add_labels(node_addition, opts.node_type)
# interface_obj.my_session.my_db.add_labels(node_addition, opts.node_type)
#else:
# dispatcher_object.stdout.write("Object Type/Category/Tag: ")
# object_type = (dispatcher_object.stdin.readline()).replace('\n','')
# dispatcher_object.my_graph.add_labels(node_addition, object_type)
# interface_obj.stdout.write("Object Type/Category/Tag: ")
# object_type = (interface_obj.stdin.readline()).replace('\n','')
# interface_obj.my_session.my_db.add_labels(node_addition, object_type)
elif opts.prompt: # DEFAULT option too
add_wizard(dispatcher_object)
add_wizard(interface_obj)
elif opts.csv:
# TODO - add a CSV line
print "TODO: add a CSV line"
Expand All @@ -51,7 51,7 @@ def poortego_add(dispatcher_object, args, opts):
# TODO - support for node that references a file
print "TODO: add values that reference a local file"
else:
dispatcher_object.stdout.write("ERROR- no option provided")
interface_obj.stdout.write("ERROR- no option provided")

# TODO - remove whitespace, lowercase if appropriate, etc
def verify_and_normalize_values(obj_val, obj_types, obj_properties):
Expand All @@ -72,79 72,75 @@ def create_implied_nodes(obj_val, obj_types, obj_properties):
#
# Add wizard - prompt user for appropriate inputs
#
def add_wizard(dispatcher_object):
def add_wizard(interface_obj):

# Determine name/value (primary/unique identification)
dispatcher_object.stdout.write("Node/Object primary, unique name or value: ")
object_val = (dispatcher_object.stdin.readline()).replace('\n','')
interface_obj.stdout.write("Node/Object primary, unique name or value: ")
object_val = (interface_obj.stdin.readline()).replace('\n','')
node_dict = {'name':object_val, 'type':''}

# Ask for and get object type(s)
# TODO - loop for handling multiple object type/category/tag labels
object_type_set = set()
while True:
dispatcher_object.stdout.write("Object Type/Category/Tag ('?' will list existing): ")
object_type = (dispatcher_object.stdin.readline()).replace('\n','')
interface_obj.stdout.write("Object Type/Category/Tag ('?' will list existing): ")
object_type = (interface_obj.stdin.readline()).replace('\n','')
# On-the-fly support for listing existing object labels
if (object_type != "?"):
interface_obj.stdout.write("[DEBUG] Setting node type to %s\n" % object_type)
object_type_set.add(object_type)
node_dict['type'] = object_type
break
object_types = dispatcher_object.my_graph.node_labels()
object_types = interface_obj.my_session.my_db.get_all_labels()
# TODO - sort by alpha and allow "? chars" to search by chars
dispatcher_object.stdout.write(repr(object_types) "\n")
interface_obj.stdout.write(repr(object_types) "\n")

# Ask for and get properties
property_dict = {}
dispatcher_object.stdout.write("Property Key (return for none): ")
property_key = (dispatcher_object.stdin.readline()).replace('\n','')
interface_obj.stdout.write("Property Key (return for none): ")
property_key = (interface_obj.stdin.readline()).replace('\n','')
while (property_key != ""):
dispatcher_object.stdout.write(property_key " Value: ")
property_value = (dispatcher_object.stdin.readline()).replace('\n','')
interface_obj.stdout.write(property_key " Value: ")
property_value = (interface_obj.stdin.readline()).replace('\n','')
property_dict[property_key] = property_value

dispatcher_object.stdout.write("Property Key (return for none): ")
property_key = (dispatcher_object.stdin.readline()).replace('\n','')
interface_obj.stdout.write("Property Key (return for none): ")
property_key = (interface_obj.stdin.readline()).replace('\n','')

# TODO - normalization (e.g., strip, lowercase) based on values (e.g., MD5, domain, etc.)
# verify_and_normalize_values(object_val, object_type_set, property_dict)

# Get or Create Node
node_addition = dispatcher_object.my_graph.create_node_from_dict(node_dict)
node_addition = interface_obj.my_session.my_db.create_node_from_dict(node_dict)

# Add type/category (labels in neo4j 2.x)
dispatcher_object.my_graph.add_labels(node_addition, object_type_set)
interface_obj.my_session.my_db.set_node_labels(node_addition, object_type_set)

# Set properties
# TODO - set default poortego properties from dispathcer_object.my_session.default_node_meta
# TODO - updating if node already exists vs over-writing
now_string = time.strftime("%Y-%m-%d %H:%M:%S")
for meta_key,meta_value in dispatcher_object.my_session.default_node_meta.iteritems():
for meta_key,meta_value in interface_obj.my_session.default_node_meta.iteritems():
if (meta_value == 'datetime'):
meta_value = now_string
elif (meta_value == 'username'):
meta_value = dispatcher_object.my_session.user.username
meta_value = interface_obj.my_session.my_user.username
property_dict[meta_key] = meta_value
dispatcher_object.my_graph.set_properties(node_addition, property_dict)
interface_obj.my_session.my_db.set_node_properties(node_addition, property_dict)

# TODO - create default linkage(s) - such as from current node
# TBD - do we want to link all objects to the ROOT node or not, like this:

# TODO - make default linkage either an option or something set in conf
# Note: this was moved to the create_node_from_dict() method
#new_node_root_path = dispatcher_object.my_graph.poortego_root_node.get_or_create_path(object_type, node_addition)
#new_node_root_path = interface_obj.my_session.my_db.poortego_root_node.get_or_create_path(object_type, node_addition)

# TODO: auto-creation of implied nodes if appropriate, e.g., URL -> FQDN -> Domain
# create_implied_nodes(object_val, object_type_set, property_dict)

# TODO: Feedback/Confirmation: you are adding ..this.., are you sure?
# TODO: standard response - node added with id#
# TODO: Logging / debug
dispatcher_object.stdout.write("You added '" object_val "' of type '" str(object_type_set) "'\n")
interface_obj.stdout.write("You added '" object_val "' of type '" str(object_type_set) "'\n")


#
# Debug - unit testing
#
if __name__ == "__main__":
# TODO
print "TODO - any local unit testing"
11 changes: 11 additions & 0 deletions poortego/commands/cd.py
Original file line number Diff line number Diff line change
@@ -0,0 1,11 @@
# cd.py

#
# Module poortego.command.cd
#

def poortego_cd(interface_obj, arg):
"""Command to change focus"""
# TODO
interface_obj.my_session.current_node_id = arg
interface_obj.stdout.write("Current node changed to: %s\n" % str(interface_obj.my_session.current_node_id))
Loading

0 comments on commit 16c07ca

Please sign in to comment.