X-Git-Url: http://git.onelab.eu/?p=build.git;a=blobdiff_plain;f=module-tools.py;h=e9f3096517c6e24c7198cde863ca3882cf7a01b3;hp=30c527efba915e3c1179aaaf57700bb9c37ca407;hb=HEAD;hpb=a9a21f9acf96076a37ca12924027b0e1d4d1a3f5 diff --git a/module-tools.py b/module-tools.py index 30c527ef..7678bdce 100755 --- a/module-tools.py +++ b/module-tools.py @@ -109,7 +109,7 @@ class Command: raise Exception("Command {} failed".format(self.command)) # returns stdout, like bash's $(mycommand) - def output_of(self, with_stderr=False): + def output_of(self, with_stderr=False, binary=False): if self.options.dry_run: print('dry_run', self.command) return 'dry_run output' @@ -124,7 +124,8 @@ class Command: command += " > " command += tmp os.system(command) - with open(tmp) as f: + mode = "r" if not binary else "rb" + with open(tmp, mode) as f: result=f.read() os.unlink(tmp) if self.options.debug: @@ -223,11 +224,17 @@ class GitRepository: def diff(self, f=""): c = Command("git diff {}".format(f), self.options) - return self.__run_in_repo(c.output_of, with_stderr=True) + try: + return self.__run_in_repo(c.output_of, with_stderr=True) + except: + return self.__run_in_repo(c.output_of, with_stderr=True, binary=True) def diff_with_tag(self, tagname): c = Command("git diff {}".format(tagname), self.options) - return self.__run_in_repo(c.output_of, with_stderr=True) + try: + return self.__run_in_repo(c.output_of, with_stderr=True) + except: + return self.__run_in_repo(c.output_of, with_stderr=True, binary=True) def commit(self, logfile, branch="master"): self.__run_command_in_repo("git add .", ignore_errors=True) @@ -237,7 +244,7 @@ class GitRepository: self.__run_command_in_repo("git push") else: self.__run_command_in_repo("git push origin {}:{}".format(branch, branch)) - self.__run_command_in_repo("git push --tags") + self.__run_command_in_repo("git push --tags", ignore_errors=True) def revert(self, f=""): if f: