"""
This module is the connect command of bowl.

Created on 15 March 2014
@author: Charlie Lewis
"""

import os

class connect(object):
    """
    This class is responsible for the connect command of the cli.
    """
    @classmethod
    def main(self, args):
        directory = "~/.bowl"
        directory = os.path.expanduser(directory)
        if not os.path.exists(directory):
            os.makedirs(directory)
        # !! TODO
        #    test connection
        #    allow different port
        try:
            with open(os.path.join(directory, "hosts"), 'a') as f:
                f.write("{" +
                        "'title': '"+args.DOCKER_HOST+"'," +
                        " 'type': 'choice_menu'" +
                        "}\n")
        except:
            print "unable to add docker host"
            return False
        return True

@@ -504,13 +504,404 @@
     
-try:%0A
+exists = False%0A        try:%0A            if os.path.exists(os.path.join(directory, %22hosts%22)):%0A                with open(os.path.join(directory, %22hosts%22), 'r') as f:%0A                    for line in f:%0A                        repo = ast.literal_eval(line.strip())%0A                        if repo%5B'title'%5D == args.DOCKER_HOST:%0A                            exists = True%0A            if not exists:%0A    
     
@@ -979,16 +979,20 @@
         
+    
 f.write(
@@ -993,24 +993,28 @@
 write(%22%7B%22 +%0A
+    
             
@@ -1086,16 +1086,20 @@
         
+    
 %22 'type'
@@ -1145,15 +1145,93 @@
     
+   
+ 
 %22%7D%5Cn%22)%0A
+            else:%0A                print %22host has already been connected%22%0A
     

fix up connect