
import os, sys
from contextlib import closing
from ..configuration import config

def activate(cmd):
    args = cmd.args
    path = os.path.join(__file__, '..', '..', '..', 'project_data', 'current_project.txt')
    project_path = os.path.join(args.root_dir)
    
    if args.name not in [f for f in os.listdir(project_path)]:
        print 'Unable to locate project: %s in %s' % (args.name, project_path)
        sys.exit(1)
        
    with closing(open(path, 'wb')) as file:
        _ = os.path.join(project_path, args.name, '%s.config' % args.name)
        file.write(os.path.normpath(_))
    
    print '%s has been activated and is the current project.' % args.name