/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/command/init.py

  • Committer: Tim Marston
  • Date: 2016-02-13 14:18:32 UTC
  • Revision ID: tim@ed.am-20160213141832-o0odt4p3nuj97211
switched init command (and update command) to checking for conflicts prior to
deployment.copy_out(), and removed remaining references to CopyInConflict
(supposedly done in r24)

Show diffs side-by-side

added added

removed removed

23
23
from command import Command
24
24
import stdhome.the as the
25
25
from stdhome.deployment import Deployment
26
 
from stdhome.subprocess import Popen
27
26
 
28
27
 
29
28
class InitCommand( Command ):
30
29
 
31
30
 
32
 
        def __init__( self ):
33
 
                self.repo = None
34
 
 
35
 
 
36
31
        def print_help( self ):
37
32
                print "Usage: " + the.program.name + " init [URL] [--repo=REPO]"
38
33
                print
61
56
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
62
57
                                        raise the.program.FatalError(
63
58
                                                'invalid repository name: ' + optarg )
64
 
                                self.repo = optarg
65
 
                        elif opt in [ '--verbose', '-v' ]:
66
 
                                the.verbose += 1
 
59
                                the.repo = optarg
67
60
                        elif opt == "--help":
68
61
                                self.print_help()
69
 
                
 
62
 
70
63
                # discard first argument (the command)
71
64
                args.pop( 0 )
72
65
 
73
66
                # URL argument
74
67
                self.url = args[ 0 ].strip() if len( args ) else None
75
68
 
76
 
                # remaining arguments
 
69
                # check remaining arguments
77
70
                if len( args ) > 1:
78
71
                        raise the.program.UsageError( 'too many arguments' )
79
72
 
81
74
        def run( self ):
82
75
 
83
76
                # set up repo and check it *doesn't* already exists
84
 
                the.set_repo( self.repo )
85
77
                the.repo.check_dir_exists( False )
86
78
 
87
79
                # ensure our top-level directory exists
93
85
 
94
86
                        # expand url if it's a simple hostname
95
87
                        if re.match( '^[0-9a-zA-z.]+$', self.url ):
96
 
                                self.url = 'sftp://%s/%s/%s' % \
 
88
                                self.url = 'bzr+ssh://%s/%s/%s' % \
97
89
                                                   ( self.url, the.dir, the.repo.name )
98
90
 
99
91
                        # initialise deployment (with an empty repo)
101
93
                        deployment.copy_in()
102
94
 
103
95
                        # perform bzr checkout
104
 
                        if the.verbose: print "checking out %s" % the.repo.dir
 
96
                        if the.verbose >= 1: print "checking out %s" % the.repo.dir
105
97
                        try:
106
98
                                the.repo.vcs.checkout( self.url )
107
99
                        except Exception as e:
114
106
 
115
107
                                raise e
116
108
 
 
109
                        # check for deployment conclicts
 
110
                        conflicts = deployment.get_conflicts()
 
111
                        if conflicts:
 
112
                                message += 'deployment conflicts:\n  %s' % \
 
113
                                                   '\n  '.join( conflicts )
 
114
 
117
115
                        # perform deployment
118
 
                        try:
119
 
                                deployment.copy_out()
120
 
                        except deployment.Conflict as e:
121
 
                                raise the.program.FatalError( e.msg )
 
116
                        deployment.copy_out()
122
117
 
123
118
                else:
124
119
 
125
120
                        # perform bzr init
126
 
                        if the.verbose: print 'initialising %s' % the.repo.dir
 
121
                        if the.verbose >= 1: print 'initialising %s' % the.repo.dir
127
122
                        try:
128
123
                                the.repo.vcs.init()
129
124
                        except Exception as e: