/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-19 20:01:06 UTC
  • Revision ID: tim@ed.am-20140319200106-ou5y1nat6y2auaue
removed square brackets from AC_INIT parameter

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
41
46
                print "hostname, it is internally expanded to scp://HOSTNAME/~/.stdhome/REPO)."
42
47
                print
43
48
                print "Options:"
44
 
                print "      --quiet      do not report changes to the home directory"
45
49
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
46
50
                print "  -v, --verbose    display information about what is being done"
47
51
                print "      --help       display help and exit"
51
55
        def parse_command_line( self ):
52
56
                opts, args = getopt.gnu_getopt(
53
57
                        sys.argv[ 1: ], "r:v",
54
 
                        [ "quiet", "repo=", "verbose", "help" ] )
 
58
                        [ "repo=", "verbose", "help" ] )
55
59
                for opt, optarg in opts:
56
 
                        if opt == "--quiet":
57
 
                                self.quiet = True
58
 
                        elif opt in [ '--repo', '-r' ]:
59
 
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
 
60
                        if opt in [ '--repo', '-r' ]:
 
61
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
60
62
                                        raise the.program.FatalError(
61
63
                                                'invalid repository name: ' + optarg )
62
 
                                the.repo = optarg
 
64
                                self.repo = optarg
 
65
                        elif opt in [ '--verbose', '-v' ]:
 
66
                                the.verbose += 1
63
67
                        elif opt == "--help":
64
68
                                self.print_help()
65
 
 
 
69
                
66
70
                # discard first argument (the command)
67
71
                args.pop( 0 )
68
72
 
69
73
                # URL argument
70
74
                self.url = args[ 0 ].strip() if len( args ) else None
71
75
 
72
 
                # check remaining arguments
 
76
                # remaining arguments
73
77
                if len( args ) > 1:
74
78
                        raise the.program.UsageError( 'too many arguments' )
75
79
 
77
81
        def run( self ):
78
82
 
79
83
                # set up repo and check it *doesn't* already exists
 
84
                the.set_repo( self.repo )
80
85
                the.repo.check_dir_exists( False )
81
86
 
82
87
                # ensure our top-level directory exists
87
92
                if self.url:
88
93
 
89
94
                        # expand url if it's a simple hostname
90
 
                        if re.search( '^[0-9a-zA-z.]+$', self.url ):
91
 
                                self.url = 'bzr+ssh://%s/%s/%s' % \
 
95
                        if re.match( '^[0-9a-zA-z.]+$', self.url ):
 
96
                                self.url = 'sftp://%s/%s/%s' % \
92
97
                                                   ( self.url, the.dir, the.repo.name )
93
98
 
94
99
                        # initialise deployment (with an empty repo)
96
101
                        deployment.copy_in()
97
102
 
98
103
                        # perform bzr checkout
99
 
                        if the.verbose >= 1: print "checking out %s" % the.repo.dir
 
104
                        if the.verbose: print "checking out %s" % the.repo.dir
100
105
                        try:
101
106
                                the.repo.vcs.checkout( self.url )
102
107
                        except Exception as e:
109
114
 
110
115
                                raise e
111
116
 
112
 
                        message = ''
113
 
 
114
 
                        # check for deployment conclicts
115
 
                        conflicts = deployment.get_conflicts()
116
 
                        if conflicts:
117
 
                                message += 'deployment conflicts:\n  %s' % \
118
 
                                                   '\n  '.join( conflicts )
119
 
 
120
 
                        # stop if there are conflicts
121
 
                        if message:
122
 
                                raise the.program.FatalError(
123
 
                                        'there were conflicts...\n' + message )
124
 
 
125
117
                        # perform deployment
126
 
                        deployment.copy_out( self.quiet )
 
118
                        try:
 
119
                                deployment.copy_out()
 
120
                        except deployment.Conflict as e:
 
121
                                raise the.program.FatalError( e.msg )
127
122
 
128
123
                else:
129
124
 
130
125
                        # perform bzr init
131
 
                        if the.verbose >= 1: print 'initialising %s' % the.repo.dir
 
126
                        if the.verbose: print 'initialising %s' % the.repo.dir
132
127
                        try:
133
128
                                the.repo.vcs.init()
134
129
                        except Exception as e: