~rogpeppe/juju-core/438-local-instance-Addresses

« back to all changes in this revision

Viewing changes to cmd/juju/synctools.go

  • Committer: John Arbash Meinel
  • Date: 2013-09-15 07:36:52 UTC
  • mfrom: (1817 juju-core)
  • mto: This revision was merged to the branch mainline in revision 1882.
  • Revision ID: john@arbash-meinel.com-20130915073652-80jnupeguvr1klea
Merge trunk, resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
        "launchpad.net/juju-core/cmd"
11
11
        "launchpad.net/juju-core/environs"
 
12
        "launchpad.net/juju-core/environs/filestorage"
12
13
        "launchpad.net/juju-core/environs/sync"
 
14
        "launchpad.net/juju-core/version"
13
15
)
14
16
 
15
17
var syncTools = sync.SyncTools
19
21
type SyncToolsCommand struct {
20
22
        cmd.EnvCommandBase
21
23
        allVersions  bool
 
24
        versionStr   string
 
25
        majorVersion int
 
26
        minorVersion int
22
27
        dryRun       bool
23
 
        publicBucket bool
24
28
        dev          bool
25
29
        source       string
 
30
        destination  string
26
31
}
27
32
 
28
33
var _ cmd.Command = (*SyncToolsCommand)(nil)
47
52
func (c *SyncToolsCommand) SetFlags(f *gnuflag.FlagSet) {
48
53
        c.EnvCommandBase.SetFlags(f)
49
54
        f.BoolVar(&c.allVersions, "all", false, "copy all versions, not just the latest")
 
55
        f.StringVar(&c.versionStr, "version", "", "copy a specific major[.minor] version")
50
56
        f.BoolVar(&c.dryRun, "dry-run", false, "don't copy, just print what would be copied")
51
57
        f.BoolVar(&c.dev, "dev", false, "consider development versions as well as released ones")
52
 
        f.BoolVar(&c.publicBucket, "public", false, "write to the public-bucket of the account, instead of the bucket private to the environment.")
53
58
        f.StringVar(&c.source, "source", "", "chose a location on the file system as source")
 
59
        f.StringVar(&c.destination, "destination", "", "chose a location on the file system as destination")
54
60
 
55
61
        // BUG(lp:1163164)  jam 2013-04-2 we would like to add a "source"
56
62
        // location, rather than only copying from us-east-1
57
63
}
58
64
 
59
65
func (c *SyncToolsCommand) Init(args []string) error {
 
66
        if c.versionStr != "" {
 
67
                var err error
 
68
                if c.majorVersion, c.minorVersion, err = version.ParseMajorMinor(c.versionStr); err != nil {
 
69
                        return err
 
70
                }
 
71
        }
60
72
        return cmd.CheckEmpty(args)
61
73
}
62
74
 
63
75
func (c *SyncToolsCommand) Run(ctx *cmd.Context) error {
64
76
        // Register writer for output on screen.
65
 
        loggo.RegisterWriter("synctools", sync.NewSyncLogWriter(ctx.Stdout, ctx.Stderr), loggo.INFO)
 
77
        loggo.RegisterWriter("synctools", cmd.NewCommandLogWriter("juju.environs.sync", ctx.Stdout, ctx.Stderr), loggo.INFO)
66
78
        defer loggo.RemoveWriter("synctools")
67
79
        environ, err := environs.PrepareFromName(c.EnvName)
68
80
        if err != nil {
69
81
                return err
70
82
        }
 
83
 
 
84
        target := environ.Storage()
 
85
        if c.destination != "" {
 
86
                target, err = filestorage.NewFileStorageWriter(c.destination)
 
87
                if err != nil {
 
88
                        return err
 
89
                }
 
90
        }
 
91
 
71
92
        // Prepare syncing.
72
93
        sctx := &sync.SyncContext{
73
 
                Target:       environ,
 
94
                Target:       target,
74
95
                AllVersions:  c.allVersions,
 
96
                MajorVersion: c.majorVersion,
 
97
                MinorVersion: c.minorVersion,
75
98
                DryRun:       c.dryRun,
76
 
                PublicBucket: c.publicBucket,
77
99
                Dev:          c.dev,
78
100
                Source:       c.source,
79
101
        }