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