Skip to content

Commit

Permalink
GitHub commands return ret_code. Output data can be get with get_outp…
Browse files Browse the repository at this point in the history
…ut_data()

Signed-off-by: Petr Hracek <phracek@redhat.com>
  • Loading branch information
phracek committed Apr 9, 2015
1 parent 1c8a767 commit d2551b8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
37 changes: 20 additions & 17 deletions rebasehelper/patch_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ def apply_patch(git_helper, patch_name):

@classmethod
def _prepare_git(cls, upstream_name):
ret_code = cls.git_helper.command_remote_add(upstream_name, cls.new_sources)
ret_code = cls.git_helper.command_fetch(upstream_name)
cls.git_helper.command_remote_add(upstream_name, cls.new_sources)
cls.git_helper.command_fetch(upstream_name)
cls.output_data = cls.git_helper.command_log(parameters='--pretty=oneline')
last_hash = GitHelper.get_commit_hash_log(cls.output_data, number=0)
init_hash = GitHelper.get_commit_hash_log(cls.output_data, len(cls.output_data)-1)
return init_hash, last_hash

@classmethod
def _get_git_helper_data(cls):
cls.output_data = cls.git_helper.get_output_data()

@classmethod
def _git_rebase(cls):
# in old_sources do.
Expand All @@ -115,15 +119,13 @@ def _git_rebase(cls):
logger.info('Git-rebase operation to %s is ongoing...', os.path.basename(cls.new_sources))
upstream = 'new_upstream'
init_hash, last_hash = cls._prepare_git(upstream)
ret_code, cls.output_data = cls.git_helper.command_rebase(parameters='--onto',
upstream_name=upstream,
first_hash=init_hash,
last_hash=last_hash)
ret_code = cls.git_helper.command_rebase(parameters='--onto', upstream_name=upstream,
first_hash=init_hash, last_hash=last_hash)
else:
logger.info('Git-rebase operation continues...')
ret_code, cls.output_data = cls.git_helper.command_rebase(parameters='--skip')
logger.debug(cls.output_data)
patch_name = ""
ret_code = cls.git_helper.command_rebase(parameters='--skip')
cls._get_git_helper_data()
logger.debug(cls.output_data)
modified_patches = []
deleted_patches = []
unapplied_patches = []
Expand All @@ -132,26 +134,27 @@ def _git_rebase(cls):
patch_name = cls.git_helper.get_unapplied_patch(cls.output_data)
logger.info("Git has problems with rebasing patch %s", patch_name)
if not cls.non_interactive:
ret_code = cls.git_helper.command_mergetool()
cls.git_helper.command_mergetool()
else:
unapplied_patches.append(patch_name)
modified_files = cls.git_helper.command_diff_status()
ret_code = cls.git_helper.command_add_files(parameters=modified_files)
cls.git_helper.command_add_files(parameters=modified_files)
base_name = os.path.join(cls.kwargs['results_dir'], patch_name)
ret_code = cls.git_helper.command_diff('HEAD', output_file=base_name)
cls.git_helper.command_diff('HEAD', output_file=base_name)
with open(base_name, "r") as f:
cls.output_data = f.readlines()
if not cls.output_data:
del_patches = f.readlines()
if not del_patches:
deleted_patches.append(base_name)
else:
logger.info('Following files were modified: %s', ','.join(modified_files).decode(defenc))
ret_code = cls.git_helper.command_commit(message=patch_name)
ret_code, cls.output_data = cls.git_helper.command_diff('HEAD~1', output_file=base_name)
cls.git_helper.command_commit(message=patch_name)
cls.git_helper.command_diff('HEAD~1', output_file=base_name)
modified_patches.append(base_name)
if not cls.non_interactive:
if not ConsoleHelper.get_message('Do you want to continue with another patch'):
raise KeyboardInterrupt
ret_code, cls.output_data = cls.git_helper.command_rebase('--skip')
ret_code = cls.git_helper.command_rebase('--skip')
cls._get_git_helper_data()
else:
break

Expand Down
53 changes: 24 additions & 29 deletions rebasehelper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class GitHelper(object):
"""Class which operates with git repositories"""

GIT = 'git'
output_data = []

def __init__(self, git_directory):
self.git_directory = git_directory
Expand All @@ -504,7 +505,7 @@ def _call_git_command(self, command, input_file=None, output_file=None):
cmd = []
cmd.append(self.GIT)
cmd.extend(command)
output_data = []
self.output_data = []
if not output_file:
output = StringIO()
else:
Expand All @@ -516,8 +517,8 @@ def _call_git_command(self, command, input_file=None, output_file=None):
if not output_file:
out = output.readlines()
for o in out:
output_data.append(o.strip())
return ret_code, output_data
self.output_data.append(o.strip())
return ret_code

def check_git_config(self):

Expand Down Expand Up @@ -587,8 +588,7 @@ def get_unapplied_patch(output):
def command_init(self, directory):
cmd = ['init']
cmd.append(directory)
ret_code, output = self._call_git_command(cmd)
return ret_code
return self._call_git_command(cmd)

def command_commit(self, message=None):

Expand All @@ -604,8 +604,7 @@ def command_commit(self, message=None):
else:
cmd.extend(['-m', 'Empty message'])

ret_code, output = self._call_git_command(cmd)
return ret_code
return self._call_git_command(cmd)

def command_remote_add(self, upstream_name, directory):

Expand All @@ -616,8 +615,7 @@ def command_remote_add(self, upstream_name, directory):
cmd.append('add')
cmd.append(upstream_name)
cmd.append(directory)
ret_code, output = self._call_git_command(cmd)
return ret_code
return self._call_git_command(cmd)

def command_diff_status(self):

Expand All @@ -627,14 +625,13 @@ def command_diff_status(self):
cmd.append('diff')
cmd.append('--name-only')
cmd.append('--staged')
ret_code, output = self._call_git_command(cmd)
return output
self._call_git_command(cmd)
return self.output_data

def command_fetch(self, upstream_name):
cmd = ['fetch']
cmd.append(upstream_name)
ret_code, output = self._call_git_command(cmd)
return ret_code
return self._call_git_command(cmd)

def command_log(self, parameters=None):

Expand All @@ -646,18 +643,18 @@ def command_log(self, parameters=None):
cmd = ['log']
if parameters:
cmd.append(parameters)
ret_code, output = self._call_git_command(cmd)
ret_code = self._call_git_command(cmd)
if int(ret_code) != 0:
return None
else:
return output
return self.output_data

def command_mergetool(self):

"""Function calls git mergetool program"""

cmd = ['mergetool']
ret_code, output = self._call_git_command(cmd)
ret_code = self._call_git_command(cmd)
return ret_code

def command_rebase(self, parameters, upstream_name=None, first_hash=None, last_hash=None):
Expand All @@ -672,39 +669,37 @@ def command_rebase(self, parameters, upstream_name=None, first_hash=None, last_h
cmd.append(last_hash)
else:
cmd.append(parameters)
ret_code, output = self._call_git_command(cmd)
return ret_code, output
return self._call_git_command(cmd)

def command_add_files(self, parameters=None):
cmd = ['add']
if parameters:
cmd.extend(parameters)
ret_code, output = self._call_git_command(cmd)
return ret_code
return self._call_git_command(cmd)

def command_diff(self, head, output_file=None):
cmd = ['diff']
cmd.append(head)
ret_code = self._call_git_command(cmd, output_file=output_file)
return ret_code
return self._call_git_command(cmd, output_file=output_file)

def command_am(self, parameters=None, input_file=None):
cmd = ['am']
if parameters:
cmd.append(parameters)
ret_code, output = self._call_git_command(cmd, input_file=input_file)
return ret_code
return self._call_git_command(cmd, input_file=input_file)

def command_apply(self, input_file=None):
cmd = ['apply']
ret_code, output = self._call_git_command(cmd, input_file=input_file)
return ret_code
return self._call_git_command(cmd, input_file=input_file)

def command_config(self, parameters, variable=None):
cmd = ['config']
cmd.append(parameters)
cmd.append(variable)
ret_code, output = self._call_git_command(cmd)
if not output:
self._call_git_command(cmd)
if not self.output_data:
return None
return output[0]
return self.output_data[0]

def get_output_data(self):
return self.output_data

0 comments on commit d2551b8

Please sign in to comment.