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

  • Committer: Tim Marston
  • Date: 2014-04-05 22:30:23 UTC
  • Revision ID: tim@ed.am-20140405223023-3co87mbvnxwk1l65
added revert command

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# command_resolve.py
 
1
# resolve.py
2
2
#
3
3
# Copyright (C) 2014 Tim Marston <tim@edm.am>
4
4
#
20
20
 
21
21
 
22
22
import sys, re, getopt
23
 
import the
24
 
from deployment import Deployment
25
 
 
26
 
 
27
 
class CommandResolve:
28
 
 
29
 
 
30
 
        def __init__( self ):
31
 
                self.repo = None
 
23
from command import Command
 
24
import stdhome.the as the
 
25
from stdhome.deployment import Deployment
 
26
 
 
27
 
 
28
class ResolveCommand( Command ):
32
29
 
33
30
 
34
31
        def print_help( self ):
62
59
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
63
60
                                        raise the.program.FatalError(
64
61
                                                'invalid repository name: ' + optarg )
65
 
                                self.repo = optarg
 
62
                                the.repo = optarg
66
63
                        elif opt in [ '--verbose', '-v' ]:
67
 
                                the.verbose = True
 
64
                                the.verbose += 1
68
65
                        elif opt == "--help":
69
66
                                self.print_help()
70
67
                
79
76
        def run( self ):
80
77
 
81
78
                # set up repo and check it exists
82
 
                the.set_repo( self.repo )
83
79
                the.repo.check_dir_exists()
84
80
 
85
81
                # initialise deployment (check it's valid)
86
82
                deployment = Deployment()
87
83
                deployment.check_ongoing( True )
88
84
 
89
 
                # check for conflicts
90
85
                message = ''
91
 
                conflicts = the.repo.vcs.has_conflicts()
92
 
                if conflicts:
93
 
                        message += 'Conflicts in %s:\n  %s' % \
94
 
                                           ( the.repo.name, '\n  '.join( conflicts ) )
95
 
                conflicts = deployment.check_conflicts()
96
 
                if conflicts:
97
 
                        message += 'Deployment conflicts:\n  %s' % \
 
86
 
 
87
                # check for conflicts in repo
 
88
                files = the.repo.vcs.get_conflicts()
 
89
                if files:
 
90
                        message += 'conflicts in %s:\n  %s' % \
 
91
                                           ( the.repo.name, '\n  '.join( files ) )
 
92
 
 
93
                # check for deployment conclicts
 
94
                conflicts = deployment.get_conflicts()
 
95
                if conflicts:
 
96
                        message += 'deployment conflicts:\n  %s' % \
98
97
                                           '\n  '.join( conflicts )
 
98
 
 
99
                # stop if there are conflicts
99
100
                if message:
100
 
                        raise the.program.FatalError( 'there are conflicts:\n' + message )
 
101
                        raise the.program.FatalError(
 
102
                                'there were conflicts...\n' + message )
101
103
 
102
104
                # copy-out changes from repo
103
 
                try:
104
 
                        deployment.copy_out()
105
 
                except deployment.Conflict as e:
106
 
                        raise the.program.FatalError( e.msg )
 
105
                deployment.copy_out()
107
106
 
108
107
                # now we've copied-out, revert any copied-in changes!
109
108
                if the.verbose: print "reverting %s" % the.repo.dir