def execute_backup(commands_to_execute): """perform the backup. return an array of any problems encountered""" problems = [] for command in commands_to_execute: command_state = system_command(command, return_state=True, exception_on_error=False, echo=True) if command_state["status"] != 0: problems.append(command_state) return problems
def parse_commits(): ''' parse the output of the git whatchanged command. return an array of dicts. ''' command_state \ = system_command( ['git', 'whatchanged', '--no-color'], return_state=True) output = command_state['stdout'].split('\n') count = 0 commits = [] buf = {'files': {}} for line in output: count += 1 if len(line) == 0 or line[0] in [' ', ' ']: continue if re.search('^commit ', line): sha = re.sub('^commit ', '', line) if count != 1: commits.append(buf) buf = {'files': {}} buf['sha'] = sha elif re.search('^:[0-7]{6} ', line): match = re.match(FILE_STATS_LINE_REGEX, line) previous_mode = match.group(1) current_mode = match.group(2) previous_sha = match.group(3) current_sha = match.group(4) change_type = match.group(5) path = match.group(6) buf['files'][path] = { 'previous_mode': previous_mode, 'current_mode': current_mode, 'previous_sha': previous_sha, 'current_sha': current_sha, 'change_type': change_type, } elif re.search('^Date: ', line): buf['date'] = re.sub('^Date: ', '', line) elif re.search('^Author: ', line): buf['author'] = line buf['author'] = re.sub('^Author: ', '', line) elif re.search('^Merge: ', line): buf['merge'] = re.sub('^Merge: ', '', line) commits.append(buf) return commits
def parse_commits(): ''' parse the output of the git whatchanged command. return an array of dicts. ''' command_state \ = system_command( ['git', 'whatchanged', '--no-color'], return_state=True) output = command_state['stdout'].split('\n') count = 0 commits = [] buf = {'files': {}} for line in output: count += 1 if len(line) == 0 or line[0] in [' ', ' ']: continue if re.search('^commit ', line): sha = re.sub('^commit ', '', line) if count != 1: commits.append(buf) buf = {'files': {}} buf['sha'] = sha elif re.search('^:[0-7]{6} ', line): match = re.match(FILE_STATS_LINE_REGEX, line) previous_mode = match.group(1) current_mode = match.group(2) previous_sha = match.group(3) current_sha = match.group(4) change_type = match.group(5) path = match.group(6) buf['files'][path] = { 'previous_mode': previous_mode, 'current_mode': current_mode, 'previous_sha': previous_sha, 'current_sha': current_sha, 'change_type': change_type, } elif re.search('^Date: ', line): buf['date'] = re.sub('^Date: ', '', line) elif re.search('^Author: ', line): buf['author'] = line buf['author'] = re.sub('^Author: ', '', line) elif re.search('^Merge: ', line): buf['merge'] = re.sub('^Merge: ', '', line) commits.append(buf) return commits