Camelize some snake_case variable names

This commit is contained in:
Jonathan Rudenberg 2013-03-28 20:12:23 -04:00
parent 0636c11f0b
commit a6da7f138c
6 changed files with 96 additions and 96 deletions

View File

@ -76,13 +76,13 @@ func LoadConfig(rootPath string) (*AuthConfig, error) {
return nil, err
}
arr := strings.Split(string(b), "\n")
orig_auth := strings.Split(arr[0], " = ")
orig_email := strings.Split(arr[1], " = ")
authConfig, err := DecodeAuth(orig_auth[1])
origAuth := strings.Split(arr[0], " = ")
origEmail := strings.Split(arr[1], " = ")
authConfig, err := DecodeAuth(origAuth[1])
if err != nil {
return nil, err
}
authConfig.Email = orig_email[1]
authConfig.Email = origEmail[1]
authConfig.rootPath = rootPath
return authConfig, nil
}

View File

@ -493,7 +493,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
cmd := rcli.Subcmd(stdout, "images", "[OPTIONS] [NAME]", "List images")
//limit := cmd.Int("l", 0, "Only show the N most recent versions of each image")
quiet := cmd.Bool("q", false, "only show numeric IDs")
fl_a := cmd.Bool("a", false, "show all images")
flAll := cmd.Bool("a", false, "show all images")
if err := cmd.Parse(args); err != nil {
return nil
}
@ -511,7 +511,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
}
var allImages map[string]*Image
var err error
if *fl_a {
if *flAll {
allImages, err = srv.runtime.graph.Map()
} else {
allImages, err = srv.runtime.graph.Heads()
@ -583,8 +583,8 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
cmd := rcli.Subcmd(stdout,
"ps", "[OPTIONS]", "List containers")
quiet := cmd.Bool("q", false, "Only display numeric IDs")
fl_all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
fl_full := cmd.Bool("notrunc", false, "Don't truncate output")
flAll := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
flFull := cmd.Bool("notrunc", false, "Don't truncate output")
if err := cmd.Parse(args); err != nil {
return nil
}
@ -593,12 +593,12 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tCOMMENT\n")
}
for _, container := range srv.runtime.List() {
if !container.State.Running && !*fl_all {
if !container.State.Running && !*flAll {
continue
}
if !*quiet {
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
if !*fl_full {
if !*flFull {
command = Trunc(command, 20)
}
for idx, field := range []string{
@ -630,7 +630,7 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...stri
cmd := rcli.Subcmd(stdout,
"commit", "[OPTIONS] CONTAINER [REPOSITORY [TAG]]",
"Create a new image from a container's changes")
fl_comment := cmd.String("m", "", "Commit message")
flComment := cmd.String("m", "", "Commit message")
if err := cmd.Parse(args); err != nil {
return nil
}
@ -639,7 +639,7 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...stri
cmd.Usage()
return nil
}
img, err := srv.runtime.Commit(containerName, repository, tag, *fl_comment)
img, err := srv.runtime.Commit(containerName, repository, tag, *flComment)
if err != nil {
return err
}
@ -704,20 +704,20 @@ func (srv *Server) CmdLogs(stdin io.ReadCloser, stdout io.Writer, args ...string
}
name := cmd.Arg(0)
if container := srv.runtime.Get(name); container != nil {
log_stdout, err := container.ReadLog("stdout")
logStdout, err := container.ReadLog("stdout")
if err != nil {
return err
}
log_stderr, err := container.ReadLog("stderr")
logStderr, err := container.ReadLog("stderr")
if err != nil {
return err
}
// FIXME: Interpolate stdout and stderr instead of concatenating them
// FIXME: Differentiate stdout and stderr in the remote protocol
if _, err := io.Copy(stdout, log_stdout); err != nil {
if _, err := io.Copy(stdout, logStdout); err != nil {
return err
}
if _, err := io.Copy(stdout, log_stderr); err != nil {
if _, err := io.Copy(stdout, logStderr); err != nil {
return err
}
return nil
@ -727,9 +727,9 @@ func (srv *Server) CmdLogs(stdin io.ReadCloser, stdout io.Writer, args ...string
func (srv *Server) CmdAttach(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
cmd := rcli.Subcmd(stdout, "attach", "[OPTIONS]", "Attach to a running container")
fl_i := cmd.Bool("i", false, "Attach to stdin")
fl_o := cmd.Bool("o", true, "Attach to stdout")
fl_e := cmd.Bool("e", true, "Attach to stderr")
flStdin := cmd.Bool("i", false, "Attach to stdin")
flStdout := cmd.Bool("o", true, "Attach to stdout")
flStderr := cmd.Bool("e", true, "Attach to stderr")
if err := cmd.Parse(args); err != nil {
return nil
}
@ -743,29 +743,29 @@ func (srv *Server) CmdAttach(stdin io.ReadCloser, stdout io.Writer, args ...stri
return errors.New("No such container: " + name)
}
var wg sync.WaitGroup
if *fl_i {
c_stdin, err := container.StdinPipe()
if *flStdin {
cStdin, err := container.StdinPipe()
if err != nil {
return err
}
wg.Add(1)
go func() { io.Copy(c_stdin, stdin); wg.Add(-1) }()
go func() { io.Copy(cStdin, stdin); wg.Add(-1) }()
}
if *fl_o {
c_stdout, err := container.StdoutPipe()
if *flStdout {
cStdout, err := container.StdoutPipe()
if err != nil {
return err
}
wg.Add(1)
go func() { io.Copy(stdout, c_stdout); wg.Add(-1) }()
go func() { io.Copy(stdout, cStdout); wg.Add(-1) }()
}
if *fl_e {
c_stderr, err := container.StderrPipe()
if *flStderr {
cStderr, err := container.StderrPipe()
if err != nil {
return err
}
wg.Add(1)
go func() { io.Copy(stdout, c_stderr); wg.Add(-1) }()
go func() { io.Copy(stdout, cStderr); wg.Add(-1) }()
}
wg.Wait()
return nil
@ -843,46 +843,46 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
}
}
if config.OpenStdin {
cmd_stdin, err := container.StdinPipe()
cmdStdin, err := container.StdinPipe()
if err != nil {
return err
}
if !config.Detach {
Go(func() error {
_, err := io.Copy(cmd_stdin, stdin)
cmd_stdin.Close()
_, err := io.Copy(cmdStdin, stdin)
cmdStdin.Close()
return err
})
}
}
// Run the container
if !config.Detach {
cmd_stderr, err := container.StderrPipe()
cmdStderr, err := container.StderrPipe()
if err != nil {
return err
}
cmd_stdout, err := container.StdoutPipe()
cmdStdout, err := container.StdoutPipe()
if err != nil {
return err
}
if err := container.Start(); err != nil {
return err
}
sending_stdout := Go(func() error {
_, err := io.Copy(stdout, cmd_stdout)
sendingStdout := Go(func() error {
_, err := io.Copy(stdout, cmdStdout)
return err
})
sending_stderr := Go(func() error {
_, err := io.Copy(stdout, cmd_stderr)
sendingStderr := Go(func() error {
_, err := io.Copy(stdout, cmdStderr)
return err
})
err_sending_stdout := <-sending_stdout
err_sending_stderr := <-sending_stderr
if err_sending_stdout != nil {
return err_sending_stdout
errSendingStdout := <-sendingStdout
errSendingStderr := <-sendingStderr
if errSendingStdout != nil {
return errSendingStdout
}
if err_sending_stderr != nil {
return err_sending_stderr
if errSendingStderr != nil {
return errSendingStderr
}
container.Wait()
} else {

View File

@ -66,16 +66,16 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
cmd.SetOutput(ioutil.Discard)
}
fl_user := cmd.String("u", "", "Username or UID")
fl_detach := cmd.Bool("d", false, "Detached mode: leave the container running in the background")
fl_stdin := cmd.Bool("i", false, "Keep stdin open even if not attached")
fl_tty := cmd.Bool("t", false, "Allocate a pseudo-tty")
fl_memory := cmd.Int64("m", 0, "Memory limit (in bytes)")
var fl_ports ports
flUser := cmd.String("u", "", "Username or UID")
flDetach := cmd.Bool("d", false, "Detached mode: leave the container running in the background")
flStdin := cmd.Bool("i", false, "Keep stdin open even if not attached")
flTty := cmd.Bool("t", false, "Allocate a pseudo-tty")
flMemory := cmd.Int64("m", 0, "Memory limit (in bytes)")
var flPorts ports
cmd.Var(&fl_ports, "p", "Map a network port to the container")
var fl_env ListOpts
cmd.Var(&fl_env, "e", "Set environment variables")
cmd.Var(&flPorts, "p", "Map a network port to the container")
var flEnv ListOpts
cmd.Var(&flEnv, "e", "Set environment variables")
if err := cmd.Parse(args); err != nil {
return nil, err
}
@ -89,13 +89,13 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
runCmd = parsedArgs[1:]
}
config := &Config{
Ports: fl_ports,
User: *fl_user,
Tty: *fl_tty,
OpenStdin: *fl_stdin,
Memory: *fl_memory,
Detach: *fl_detach,
Env: fl_env,
Ports: flPorts,
User: *flUser,
Tty: *flTty,
OpenStdin: *flStdin,
Memory: *flMemory,
Detach: *flDetach,
Env: flEnv,
Cmd: runCmd,
Image: image,
}
@ -150,52 +150,52 @@ func (container *Container) generateLXCConfig() error {
}
func (container *Container) startPty() error {
stdout_master, stdout_slave, err := pty.Open()
stdoutMaster, stdoutSlave, err := pty.Open()
if err != nil {
return err
}
container.cmd.Stdout = stdout_slave
container.cmd.Stdout = stdoutSlave
stderr_master, stderr_slave, err := pty.Open()
stderrMaster, stderrSlave, err := pty.Open()
if err != nil {
return err
}
container.cmd.Stderr = stderr_slave
container.cmd.Stderr = stderrSlave
// Copy the PTYs to our broadcasters
go func() {
defer container.stdout.Close()
io.Copy(container.stdout, stdout_master)
io.Copy(container.stdout, stdoutMaster)
}()
go func() {
defer container.stderr.Close()
io.Copy(container.stderr, stderr_master)
io.Copy(container.stderr, stderrMaster)
}()
// stdin
var stdin_slave io.ReadCloser
var stdinSlave io.ReadCloser
if container.Config.OpenStdin {
stdin_master, stdin_slave, err := pty.Open()
stdinMaster, stdinSlave, err := pty.Open()
if err != nil {
return err
}
container.cmd.Stdin = stdin_slave
container.cmd.Stdin = stdinSlave
// FIXME: The following appears to be broken.
// "cannot set terminal process group (-1): Inappropriate ioctl for device"
// container.cmd.SysProcAttr = &syscall.SysProcAttr{Setctty: true, Setsid: true}
go func() {
defer container.stdin.Close()
io.Copy(stdin_master, container.stdin)
io.Copy(stdinMaster, container.stdin)
}()
}
if err := container.cmd.Start(); err != nil {
return err
}
stdout_slave.Close()
stderr_slave.Close()
if stdin_slave != nil {
stdin_slave.Close()
stdoutSlave.Close()
stderrSlave.Close()
if stdinSlave != nil {
stdinSlave.Close()
}
return nil
}

View File

@ -17,11 +17,11 @@ func main() {
return
}
// FIXME: Switch d and D ? (to be more sshd like)
fl_daemon := flag.Bool("d", false, "Daemon mode")
fl_debug := flag.Bool("D", false, "Debug mode")
flDaemon := flag.Bool("d", false, "Daemon mode")
flDebug := flag.Bool("D", false, "Debug mode")
flag.Parse()
rcli.DEBUG_FLAG = *fl_debug
if *fl_daemon {
rcli.DEBUG_FLAG = *flDebug
if *flDaemon {
if flag.NArg() != 0 {
flag.Usage()
return
@ -59,22 +59,22 @@ func runCommand(args []string) error {
// closing the connection.
// See http://code.google.com/p/go/issues/detail?id=3345
if conn, err := rcli.Call("tcp", "127.0.0.1:4242", args...); err == nil {
receive_stdout := docker.Go(func() error {
receiveStdout := docker.Go(func() error {
_, err := io.Copy(os.Stdout, conn)
return err
})
send_stdin := docker.Go(func() error {
sendStdin := docker.Go(func() error {
_, err := io.Copy(conn, os.Stdin)
if err := conn.CloseWrite(); err != nil {
log.Printf("Couldn't send EOF: " + err.Error())
}
return err
})
if err := <-receive_stdout; err != nil {
if err := <-receiveStdout; err != nil {
return err
}
if !term.IsTerminal(0) {
if err := <-send_stdin; err != nil {
if err := <-sendStdin; err != nil {
return err
}
}

View File

@ -234,9 +234,9 @@ func NewRuntime() (*Runtime, error) {
}
func NewRuntimeFromDirectory(root string) (*Runtime, error) {
runtime_repo := path.Join(root, "containers")
runtimeRepo := path.Join(root, "containers")
if err := os.MkdirAll(runtime_repo, 0700); err != nil && !os.IsExist(err) {
if err := os.MkdirAll(runtimeRepo, 0700); err != nil && !os.IsExist(err) {
return nil, err
}
@ -260,7 +260,7 @@ func NewRuntimeFromDirectory(root string) (*Runtime, error) {
runtime := &Runtime{
root: root,
repository: runtime_repo,
repository: runtimeRepo,
containers: list.New(),
networkManager: netManager,
graph: g,

View File

@ -63,25 +63,25 @@ func Debugf(format string, a ...interface{}) {
// Reader with progress bar
type progressReader struct {
reader io.ReadCloser // Stream to read from
output io.Writer // Where to send progress bar to
read_total int // Expected stream length (bytes)
read_progress int // How much has been read so far (bytes)
last_update int // How many bytes read at least update
reader io.ReadCloser // Stream to read from
output io.Writer // Where to send progress bar to
readTotal int // Expected stream length (bytes)
readProgress int // How much has been read so far (bytes)
lastUpdate int // How many bytes read at least update
}
func (r *progressReader) Read(p []byte) (n int, err error) {
read, err := io.ReadCloser(r.reader).Read(p)
r.read_progress += read
r.readProgress += read
// Only update progress for every 1% read
update_every := int(0.01 * float64(r.read_total))
if r.read_progress-r.last_update > update_every || r.read_progress == r.read_total {
updateEvery := int(0.01 * float64(r.readTotal))
if r.readProgress-r.lastUpdate > updateEvery || r.readProgress == r.readTotal {
fmt.Fprintf(r.output, "%d/%d (%.0f%%)\r",
r.read_progress,
r.read_total,
float64(r.read_progress)/float64(r.read_total)*100)
r.last_update = r.read_progress
r.readProgress,
r.readTotal,
float64(r.readProgress)/float64(r.readTotal)*100)
r.lastUpdate = r.readProgress
}
// Send newline when complete
if err == io.EOF {