/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: 2014-04-05 22:30:23 UTC
  • Revision ID: tim@ed.am-20140405223023-3co87mbvnxwk1l65
added revert command

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
26
27
 
27
28
 
28
29
class InitCommand( Command ):
57
58
                                        raise the.program.FatalError(
58
59
                                                'invalid repository name: ' + optarg )
59
60
                                the.repo = optarg
 
61
                        elif opt in [ '--verbose', '-v' ]:
 
62
                                the.verbose += 1
60
63
                        elif opt == "--help":
61
64
                                self.print_help()
62
 
 
 
65
                
63
66
                # discard first argument (the command)
64
67
                args.pop( 0 )
65
68
 
66
69
                # URL argument
67
70
                self.url = args[ 0 ].strip() if len( args ) else None
68
71
 
69
 
                # check remaining arguments
 
72
                # remaining arguments
70
73
                if len( args ) > 1:
71
74
                        raise the.program.UsageError( 'too many arguments' )
72
75
 
85
88
 
86
89
                        # expand url if it's a simple hostname
87
90
                        if re.match( '^[0-9a-zA-z.]+$', self.url ):
88
 
                                self.url = 'bzr+ssh://%s/%s/%s' % \
 
91
                                self.url = 'sftp://%s/%s/%s' % \
89
92
                                                   ( self.url, the.dir, the.repo.name )
90
93
 
91
94
                        # initialise deployment (with an empty repo)
93
96
                        deployment.copy_in()
94
97
 
95
98
                        # perform bzr checkout
96
 
                        if the.verbose >= 1: print "checking out %s" % the.repo.dir
 
99
                        if the.verbose: print "checking out %s" % the.repo.dir
97
100
                        try:
98
101
                                the.repo.vcs.checkout( self.url )
99
102
                        except Exception as e:
106
109
 
107
110
                                raise e
108
111
 
109
 
                        message = ''
110
 
 
111
 
                        # check for deployment conclicts
112
 
                        conflicts = deployment.get_conflicts()
113
 
                        if conflicts:
114
 
                                message += 'deployment conflicts:\n  %s' % \
115
 
                                                   '\n  '.join( conflicts )
116
 
 
117
 
                        # stop if there are conflicts
118
 
                        if message:
119
 
                                raise the.program.FatalError(
120
 
                                        'there were conflicts...\n' + message )
121
 
 
122
112
                        # perform deployment
123
 
                        deployment.copy_out()
 
113
                        try:
 
114
                                deployment.copy_out()
 
115
                        except deployment.Conflict as e:
 
116
                                raise the.program.FatalError( e.msg )
124
117
 
125
118
                else:
126
119
 
127
120
                        # perform bzr init
128
 
                        if the.verbose >= 1: print 'initialising %s' % the.repo.dir
 
121
                        if the.verbose: print 'initialising %s' % the.repo.dir
129
122
                        try:
130
123
                                the.repo.vcs.init()
131
124
                        except Exception as e: