/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-17 18:17:18 UTC
  • Revision ID: tim@ed.am-20140717181718-gxi5lpi8qszsigxf
switch to using bzr+ssh, rather than sftp (to work around broken pimiko)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# command_init.py
 
1
# init.py
2
2
#
3
3
# Copyright (C) 2013 Tim Marston <tim@edm.am>
4
4
#
20
20
 
21
21
 
22
22
import sys, os, re, getopt, shutil, subprocess
23
 
import the
24
 
from deployment import Deployment
25
 
from subprocess import Popen
26
 
 
27
 
 
28
 
class CommandInit:
29
 
 
30
 
 
31
 
        def __init__( self ):
32
 
                self.repo = None
 
23
from command import Command
 
24
import stdhome.the as the
 
25
from stdhome.deployment import Deployment
 
26
 
 
27
 
 
28
class InitCommand( Command ):
33
29
 
34
30
 
35
31
        def print_help( self ):
60
56
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
61
57
                                        raise the.program.FatalError(
62
58
                                                'invalid repository name: ' + optarg )
63
 
                                self.repo = optarg
 
59
                                the.repo = optarg
64
60
                        elif opt in [ '--verbose', '-v' ]:
65
 
                                the.verbose = True
 
61
                                the.verbose += 1
66
62
                        elif opt == "--help":
67
63
                                self.print_help()
68
64
                
72
68
                # URL argument
73
69
                self.url = args[ 0 ].strip() if len( args ) else None
74
70
 
75
 
                # remaining arguments
 
71
                # check remaining arguments
76
72
                if len( args ) > 1:
77
73
                        raise the.program.UsageError( 'too many arguments' )
78
74
 
80
76
        def run( self ):
81
77
 
82
78
                # set up repo and check it *doesn't* already exists
83
 
                the.set_repo( self.repo )
84
79
                the.repo.check_dir_exists( False )
85
80
 
86
81
                # ensure our top-level directory exists
92
87
 
93
88
                        # expand url if it's a simple hostname
94
89
                        if re.match( '^[0-9a-zA-z.]+$', self.url ):
95
 
                                self.url = 'sftp://%s/%s/%s' % \
 
90
                                self.url = 'bzr+ssh://%s/%s/%s' % \
96
91
                                                   ( self.url, the.dir, the.repo.name )
97
92
 
98
93
                        # initialise deployment (with an empty repo)
100
95
                        deployment.copy_in()
101
96
 
102
97
                        # perform bzr checkout
103
 
                        if the.verbose: print "checking out %s" % the.repo.dir
 
98
                        if the.verbose >= 1: print "checking out %s" % the.repo.dir
104
99
                        try:
105
100
                                the.repo.vcs.checkout( self.url )
106
101
                        except Exception as e:
122
117
                else:
123
118
 
124
119
                        # perform bzr init
125
 
                        if the.verbose: print 'initialising %s' % the.repo.dir
 
120
                        if the.verbose >= 1: print 'initialising %s' % the.repo.dir
126
121
                        try:
127
122
                                the.repo.vcs.init()
128
123
                        except Exception as e: