/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/update.py

  • Committer: Tim Marston
  • Date: 2014-03-09 01:56:01 UTC
  • Revision ID: tim@ed.am-20140309015601-ptqyjqrngb7i6dmj
changed use of python

Show diffs side-by-side

added added

removed removed

28
28
class UpdateCommand( Command ):
29
29
 
30
30
 
 
31
        def __init__( self ):
 
32
                self.repo = None
 
33
 
 
34
 
31
35
        def print_help( self ):
32
36
                print "Usage: " + the.program.name + " update [--repo=REPO]"
33
37
                print
44
48
                print "Conflicts that arise from files already existing in your home directory must be"
45
49
                print "dealt with by moving those files aside (currently)."
46
50
                print
47
 
                print "After a failed update, you can list outstanding conflicts by typing:"
 
51
                print "You can resume the redeployment of your repository by typing:"
 
52
                print "    " + the.program.name + " resolve"
 
53
                print
 
54
                print "You can list outstanding conflicts by typing:"
48
55
                print "    " + the.program.name + " conflicts"
49
56
                print
50
 
                print "After fixing outstanding conflicts, you can re-attempt the redeployment of"
51
 
                print "your repository by typing:"
52
 
                print "    " + the.program.name + " resolve"
53
 
                print
54
 
                print "To back out of trying to update and revert the local repository, type:"
55
 
                print "    " + the.program.name + " stage-revert"
56
 
                print
57
57
                print "Options:"
58
58
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
59
59
                print "  -v, --verbose    display information about what is being done"
70
70
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
71
71
                                        raise the.program.FatalError(
72
72
                                                'invalid repository name: ' + optarg )
73
 
                                the.repo = optarg
 
73
                                self.repo = optarg
 
74
                        elif opt in [ '--verbose', '-v' ]:
 
75
                                the.verbose += 1
74
76
                        elif opt == "--help":
75
77
                                self.print_help()
76
 
 
 
78
                
77
79
                # discard first argument (the command)
78
80
                args.pop( 0 )
79
81
 
85
87
        def run( self ):
86
88
 
87
89
                # set up repo and check it exists
 
90
                the.set_repo( self.repo )
88
91
                the.repo.check_dir_exists()
89
92
 
90
93
                # initialise deployment (and check it)
95
98
                if the.repo.vcs.has_changes():
96
99
                        raise the.program.FatalError(
97
100
                                'repo has local changes: %s\n'
98
 
                                'Hint: see "%s stage-revert --help"' %
 
101
                                'Hint: see "%s stage-revert --help"' % 
99
102
                                ( the.repo.name, the.program.name ) )
100
103
 
101
104
                # copy-in changes to repo
102
 
                deployment.copy_in()
 
105
                try:
 
106
                        deployment.copy_in()
 
107
                except deployment.CopyInConflicts as e:
 
108
                        raise the.program.FatalError(
 
109
                                'Files in %s differ too severly from %s:\n  %s\n' % \
 
110
                                ( the.hdir, the.repo.dir, '\n  '.join( e.conflicts ) ) )
103
111
 
104
112
                # perform vcs update
105
 
                if the.verbose >= 1: print "updating %s" % the.repo.dir
 
113
                if the.verbose: print "updating %s" % the.repo.dir
106
114
                updated_files = the.repo.vcs.update()
107
115
 
108
116
                message = ''
110
118
                # check for conflicts in repo
111
119
                files = the.repo.vcs.get_conflicts()
112
120
                if files:
113
 
                        message += 'conflicts in %s:\n  %s' % \
 
121
                        message += 'Conflicts in %s:\n  %s' % \
114
122
                                           ( the.repo.name, '\n  '.join( files ) )
115
123
 
116
124
                # check for deployment conclicts
117
125
                conflicts = deployment.get_conflicts( updated_files )
118
126
                if conflicts:
119
 
                        message += 'deployment conflicts:\n  %s' % \
 
127
                        message += 'Deployment conflicts:\n  %s' % \
120
128
                                           '\n  '.join( conflicts )
121
129
 
122
130
                # stop if there are conflicts
123
131
                if message:
124
132
                        raise the.program.FatalError(
125
133
                                'there were conflicts...\n' + message )
126
 
 
127
134
                # copy-out changes from repo
128
135
                deployment.copy_out()
129
136
 
130
137
                # now we've copied-out, revert any copied-in changes!
131
 
                if the.verbose >= 1: print "reverting %s" % the.repo.dir
 
138
                if the.verbose: print "reverting %s" % the.repo.dir
132
139
                the.repo.vcs.revert()