/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-07-30 19:08:15 UTC
  • Revision ID: tim@ed.am-20140730190815-f3fs5cgtwb88jbvb
added checks to not die when information is missing in deployment

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
59
                                the.repo = optarg
65
60
                        elif opt in [ '--verbose', '-v' ]:
66
61
                                the.verbose += 1
67
62
                        elif opt == "--help":
73
68
                # URL argument
74
69
                self.url = args[ 0 ].strip() if len( args ) else None
75
70
 
76
 
                # remaining arguments
 
71
                # check remaining arguments
77
72
                if len( args ) > 1:
78
73
                        raise the.program.UsageError( 'too many arguments' )
79
74
 
81
76
        def run( self ):
82
77
 
83
78
                # set up repo and check it *doesn't* already exists
84
 
                the.set_repo( self.repo )
85
79
                the.repo.check_dir_exists( False )
86
80
 
87
81
                # ensure our top-level directory exists
93
87
 
94
88
                        # expand url if it's a simple hostname
95
89
                        if re.match( '^[0-9a-zA-z.]+$', self.url ):
96
 
                                self.url = 'sftp://%s/%s/%s' % \
 
90
                                self.url = 'bzr+ssh://%s/%s/%s' % \
97
91
                                                   ( self.url, the.dir, the.repo.name )
98
92
 
99
93
                        # initialise deployment (with an empty repo)
101
95
                        deployment.copy_in()
102
96
 
103
97
                        # perform bzr checkout
104
 
                        if the.verbose: print "checking out %s" % the.repo.dir
 
98
                        if the.verbose >= 1: print "checking out %s" % the.repo.dir
105
99
                        try:
106
100
                                the.repo.vcs.checkout( self.url )
107
101
                        except Exception as e:
123
117
                else:
124
118
 
125
119
                        # perform bzr init
126
 
                        if the.verbose: print 'initialising %s' % the.repo.dir
 
120
                        if the.verbose >= 1: print 'initialising %s' % the.repo.dir
127
121
                        try:
128
122
                                the.repo.vcs.init()
129
123
                        except Exception as e: