/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 13:25:21 UTC
  • Revision ID: tim@ed.am-20160213132521-46v5774k6ql7tdfn
fixed uninitialised variable

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:
123
115
                else:
124
116
 
125
117
                        # perform bzr init
126
 
                        if the.verbose: print 'initialising %s' % the.repo.dir
 
118
                        if the.verbose >= 1: print 'initialising %s' % the.repo.dir
127
119
                        try:
128
120
                                the.repo.vcs.init()
129
121
                        except Exception as e: