/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-03-12 22:36:44 UTC
  • Revision ID: tim@ed.am-20140312223644-9pehua402pww0op7
fixed incorrect variable name

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