/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:30:50 UTC
  • Revision ID: tim@ed.am-20160213133050-4xw8cgs2lp34zq9c
remove set declaration syntax (not compatible w/ python 2.6)

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