SiebelsTim / hack-sublime

Hack's typechecker & autocompletion inside Sublime Text
30 stars 4 forks source link

Trying to run in a Docker container on Vagrant (Mac OSX) #7

Closed digra5319 closed 8 years ago

digra5319 commented 9 years ago

It looks like the piece of code below from the hack.py file is looking for the path to run hh_client. But the commands in my terminal I take to get into my docker container and run hh_client is...

  1. cd /Users/adigregorio/projects/boot2coreos
  2. vagrant ssh
  3. docker exec -it leonardo bash
  4. cd var/www/leonardo
  5. hh_client

In order to accomplish this I thought I could modify the code below but I get FileNotFoundError: [Errno 2] No such file or directory: cd /Users/adigregorio/projects/boot2coreos in the console.

Is what I am trying to do possible?

ORIGINAL:

def getOutput(self):
        settings = self.window.active_view().settings()
        directory = os.path.dirname(self.window.active_view().file_name())
        ssh = settings.get("hack_ssh_enable")
        address = settings.get("hack_ssh_address")
        folder = settings.get("hack_ssh_folder")
        if (ssh and folder != None and address != None):
            ret = subprocess.Popen(
                [
                    "ssh", address, "cd " + folder + "; hh_client"
                ],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE
            )

MODIFIED:

def getOutput(self):
        settings = self.window.active_view().settings()
        directory = os.path.dirname(self.window.active_view().file_name())
        ssh = settings.get("hack_ssh_enable")
        address = settings.get("hack_ssh_address")
        folder = settings.get("hack_ssh_folder")
        if (folder != None):
            ret = subprocess.Popen(
                [
                   "cd /Users/adigregorio/projects/boot2coreos", "vagrant ssh", "docker exec -it leonardo bash", "cd " + folder + "; hh_client"
                ],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE
            )
SiebelsTim commented 9 years ago

Hi,

I'm glad to see you're trying to get your hands dirty :P

subprocess.Popen doesn't accept multiple commands per array entry. It uses every entry as new argument.

So you might want to concatenate these with && so they get executed one after the other.

"cd /Users/adigregorio/projects/boot2coreos && vagrant ssh && docker exec -it leonardo bash && cd " + folder + "; hh_client"

I don't know if it will work though.

digra5319 commented 9 years ago

I tried concatenating the string and got this error, not sure what it means:

File "/Users/adigregorio/Library/Application Support/Sublime Text 3/Packages/hack-sublime/hack.py", line 16, in run
    typechecker_output = self.getOutput().decode('utf-8')
AttributeError: 'str' object has no attribute 'decode
SiebelsTim commented 9 years ago

Okay, I guess the process didn't do what we expected.

I expect to get an encoded bytes object. But yours is actually a plain str.

Either way, removing decode('utf-8') will get you more information about whats going on.

Replace typechecker_output = self.getOutput().decode('utf-8') with typechecker_output = self.getOutput()

It should open a box with the result, if you aren't getting a different error. You could also print typechecker_output to see what's the content of that variable.

SiebelsTim commented 8 years ago

This is stalled. Happy to get conversion about this going on again.