-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridgerunner.py
85 lines (72 loc) · 3.04 KB
/
bridgerunner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from sys import argv
import traceback
import bridge
import logging
import logging.handlers
import util
import optparse
desc = 'A Git-Clearcase bridge aimed to synchronize between a designated area in a Cleacase snapshot view and a corresponding bare git repository.'
usage = '%prog [-c PATH] tocc|togit|update'
def initLogging(cfg):
logger = logging.getLogger()
logger.setLevel(logging.NOTSET)
h = logging.StreamHandler()
h.setFormatter(logging.Formatter('> %(message)s'))
h.setLevel(logging.INFO)
logger.addHandler(h)
logger = logging.getLogger('log.bgcc.file')
h = logging.handlers.RotatingFileHandler(cfg.logFile(), maxBytes=130000, backupCount=1)
h.setFormatter(logging.Formatter('%(asctime)s [%(module)s.%(funcName)s] %(message)s'))
h.setLevel(logging.DEBUG)
logger.addHandler(h)
## Log errors to email recipient
h = logging.handlers.SMTPHandler(cfg.smtpServer(), cfg.emailSender(), cfg.emailRecipients(), 'Bridge error alert!')
h.setFormatter(logging.Formatter('%(message)s'))
h.setLevel(logging.ERROR)
logger.addHandler(h)
def printUsage():
print 'You need to specify an action: [tocc|togit|update]'
def main():
parser = optparse.OptionParser(description=desc, usage=usage)
parser.add_option('-c', '--config', metavar='PATH', action='store', type='string', dest='config', help='Let\'s you rovide a custom path to a configuration file')
options, args = parser.parse_args()
if len(args) < 1:
printUsage()
exit(1)
cfg = util.GitConfigParser(options.config)
initLogging(cfg)
logger = logging.getLogger('log.bgcc.file')
logger.info('Git repository at: %s', cfg.gitRoot())
logger.info('Clearcase view at: %s', cfg.ccRoot())
bb = bridge.GitCCBridge(cfg)
try:
if args[0] == 'tocc':
bb.onDoCheckinToClearcase()
elif args[0] == 'togit':
if bridge.isPendingClearcaseChanges():
bb.onNewClearcaseChanges()
elif args[0] == 'init':
bb.newBridge(args[1])
elif args[0] == 'update':
if not bridge.cc.needUpdate():
logger.info('Clearcase view is up to date')
else:
logger.info('Updating Clearcase view')
bridge.cc.update()
else:
printUsage()
exit(1)
except bridge.MergeConflictException as mce:
logger.error('Error: Could not merge commit %s onto branch %s\n %s' % mce.args)
traceback.print_exc()
except bridge.CheckoutReservedException as cre:
logger.error('Error: Could not checkout files [%s]\n %s' % cre.args)
traceback.print_exc()
except bridge.UpdateCCAreaException as uae:
logger.error('Error: Could not update files for commit %s\n %s' % uae.args)
traceback.print_exc()
except Exception as e:
logger.error('Something unexpected has happened: %s', str(e))
traceback.print_exc()
if __name__ == '__main__':
main()