Last active
May 25, 2019 22:21
-
-
Save leblanc-simon/7facab4a37231e4ce8bd to your computer and use it in GitHub Desktop.
Bazaar merge utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import os | |
from datetime import date | |
import argparse | |
import ConfigParser | |
class CommandPrepare: | |
def __init__(self, project_name): | |
self.config = ConfigParser.RawConfigParser() | |
self.config.read(os.path.expanduser(os.path.join("~", '.bzr-merge', project_name + '.ini'))) | |
self.base_path = None | |
self.direction = None | |
self.from_directory = None | |
self.to_directory = None | |
self.commit = None | |
def configure(self): | |
self.base_path = self.config.get('project', 'base_path') | |
self.from_directory = self.config.get(self.direction, 'from').replace('{ticket}', str(self.ticket)) | |
self.to_directory = self.config.get(self.direction, 'to') | |
def setParameters(self, commit, direction, ticket = None): | |
self.commit = commit | |
self.direction = direction | |
self.ticket = ticket | |
def build(self): | |
command = 'cd ' + os.path.join(self.base_path, self.to_directory) + ' && \\' + "\n" | |
command += 'bzr pull && \\' + "\n" | |
command += 'bzr merge -r ' + self.commit + ' ' + os.path.join(self.base_path, self.from_directory) + ' && \\' + "\n" | |
command += 'bzr commit -m \'MERGE : ' + self._buildMessage() + '\' && \\' + "\n" | |
command += 'bzr push' | |
return command | |
def _buildMessage(self): | |
command = 'cd ' + os.path.join(self.base_path, self.from_directory) + '; ' | |
command += 'bzr log --line | grep -Ee "^' + self.commit + ':" | sed "s/^' + self.commit + ': //"' | |
message = os.popen(command).read().strip() | |
return message | |
parser = argparse.ArgumentParser(description='Build a bzr merge command.') | |
parser.add_argument('project', type = str, help = 'The project name') | |
parser.add_argument('direction', type = str, help = 'The direction to merge') | |
parser.add_argument('commit', type = str, help = 'The commit to merge') | |
parser.add_argument('-t', '--ticket', type = str, help = 'The Redmine ticket', default = None) | |
args = parser.parse_args() | |
command = CommandPrepare(args.project) | |
command.setParameters(args.commit, args.direction, args.ticket) | |
command.configure() | |
print command.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[project] | |
base_path = /home/username/project/project_name | |
[trunk] | |
from=trunk_{ticket} | |
to=trunk | |
[preprod] | |
from=trunk | |
to=preprod | |
[prod] | |
from=preprod | |
to=prod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment