#!/usr/bin/env python2

import os
import sys
sys.path.append(os.path.abspath(
	os.path.join(os.path.dirname(__file__), '..'))
)
from optparse import OptionParser
from lairdrone import api
from lairdrone import dirb

def main():
	"""
	main point of execution

	:return:
	"""

	usage = "usage: %prog <project_id> <file>"
	description = "%prog imports dirb files into Lair"
	parser = OptionParser(usage=usage, description=description,
							version="%prog 0.0.1")

	(options, args) = parser.parse_args()
	if len(args) < 2:
		print parser.get_usage()
		sys.exit(1)

	project_id, result_resource = args
	project = dirb.parse(project_id, result_resource)

	# Connect to the database
	db = api.db_connect()
	api.save(project, db, dirb.TOOL)
	sys.exit(0)

if __name__ == '__main__':
	main()
