Skip to content

Instantly share code, notes, and snippets.

@oliveagle
Created April 3, 2015 03:26
Show Gist options
  • Save oliveagle/d84cf7fecbdd01cc9adf to your computer and use it in GitHub Desktop.
Save oliveagle/d84cf7fecbdd01cc9adf to your computer and use it in GitHub Desktop.
docker command proxy for windows/cygwin
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 oliveagle <[email protected]>
#
# Distributed under terms of the MIT license.
#
# File: docker_cmd_proxy_win.py
# Date: 2015-04-02 18:37
"""
"""
import os, sys
import argparse
import subprocess
BOOT2DOCKER_BIN = r"/cygdrive/c/Program\ Files/Boot2Docker\ for\ Windows/boot2docker.exe"
# BOOT2DOCKER_BIN = r"/cygdrive/d/Users/rhtang/bin/boot2docker"
SHARE_PATH_LOCAL = r"/cygdrive/d/Users/rhtang/oledev"
SHARE_NAME = "/oledev"
commands = [BOOT2DOCKER_BIN, "ssh", "docker"]
class FakeDocker(object):
def __init__(self):
if len(sys.argv) < 2:
return getattr(self, "default")()
command = sys.argv[1]
if not hasattr(self, command):
return getattr(self, "default")()
# use dispatch pattern to invoke method with same name
return getattr(self, command)()
def default(self):
args = sys.argv[1:]
commands.extend(args)
subprocess.call(" ".join(commands), shell=True)
def build(self):
args = sys.argv[2:]
# print args
if len(args) <= 0:
print 'docker: "build" requires 1 argument. See \'docker build --help\'.'
exit(1)
path = args[-1]
if path == ".":
if not os.getcwd().startswith(SHARE_PATH_LOCAL):
print "Abort. current directory is not under SHARE_PATH_LOCAL. boot2docker won't find the correct path."
exit(1)
args[-1] = SHARE_NAME + os.getcwd()[len(SHARE_PATH_LOCAL):]
commands.append("build")
commands.extend(args)
subprocess.call(" ".join(commands), shell=True)
else:
return getattr(self, "default")()
if __name__ == '__main__':
FakeDocker()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment