diff options
author | Slava Shishkin <slavashishkin@gmail.com> | 2022-04-16 17:50:45 +0300 |
---|---|---|
committer | Slava Shishkin <slavashishkin@gmail.com> | 2022-04-21 18:54:21 +0300 |
commit | 5ccece311489e366b017600404a4d163dd5215c2 (patch) | |
tree | ee291b33cba85f33d44fb1365e4f60a3988116e9 | |
parent | 880804bcfc0a774d0cc00beb8211653df9bca2e6 (diff) | |
download | git-bz-5ccece311489e366b017600404a4d163dd5215c2.tar.gz |
Partial conversions for Bytes and Strings to needed format
- update for bz commands [apply] and [attach]
-rwxr-xr-x | git-bz | 61 |
1 files changed, 33 insertions, 28 deletions
@@ -82,6 +82,7 @@ git_config = { import http.client import optparse import os +import configparser import pickle as pickle import urllib.error import urllib.parse @@ -168,16 +169,20 @@ def git_run(command, *args, **kwargs): if not quiet and not interactive: # Using print here could result in Python adding a stray space # before the next print - sys.stderr.write(error.decode()) - sys.stdout.write(output.decode()) + if error: + sys.stderr.write(error.decode()) + sys.stdout.flush() + if output: + sys.stdout.write(output.decode()) + sys.stdout.flush() raise CalledProcessError(process.returncode, " ".join(to_run)) if interactive: return None else: if strip: - output = output.strip() - error = error.strip() + output = output.strip().decode() + error = error.strip().decode() if return_stderr: return output, error @@ -189,7 +194,8 @@ def git_run(command, *args, **kwargs): class Git: def __getattr__(self, command): def f(*args, **kwargs): - return git_run(command, *args, **kwargs) + o = git_run(command, *args, **kwargs) + return o if o else u"" return f @@ -206,19 +212,19 @@ class GitCommit: def rev_list_commits(*args, **kwargs): kwargs_copy = dict(kwargs) kwargs_copy['pretty'] = 'format:%s' - output = git.rev_list(*args, **kwargs_copy).decode() + output = git.rev_list(*args, **kwargs_copy) if output == "": lines = [] else: lines = output.split("\n") if (len(lines) % 2 != 0): - raise RuntimeException("git rev-list didn't return an even number of lines") + raise RuntimeError("git rev-list didn't return an even number of lines") result = [] for i in range(0, len(lines), 2): m = re.match("commit\s+([A-Fa-f0-9]+)", lines[i]) if not m: - raise RuntimeException("Can't parse commit it '%s'", lines[i]) + raise RuntimeError("Can't parse commit it '%s'", lines[i]) commit_id = m.group(1) subject = lines[i + 1] result.append(GitCommit(commit_id, subject)) @@ -275,7 +281,7 @@ def commit_is_merge(commit): def init_git_config(): try: - config_options = git.config(r'^bz\.', get_regexp=True).decode() + config_options = git.config(r'^bz\.', get_regexp=True) except CalledProcessError: return @@ -346,7 +352,7 @@ def split_local_config(config_text): def get_git_config(name): try: name = name.replace(".", r"\.") - config_options = git.config(r'bz-tracker\.' + name + r'\..*', get_regexp=True).decode() + config_options = git.config(r'bz-tracker\.' + name + r'\..*', get_regexp=True) except CalledProcessError: return {} @@ -664,7 +670,7 @@ def get_bugzilla_cookies_ff3(host): profiles_dir = os.path.expanduser('~/.mozilla/firefox') profile_path = None - cp = RawConfigParser() + cp = configparser.ConfigParser() cp.read(os.path.join(profiles_dir, "profiles.ini")) for section in cp.sections(): if not cp.has_option(section, "Path"): @@ -772,7 +778,7 @@ def encode_multipart_formdata(fields, files=None): Return (content_type, body) ready for httplib.HTTPContent instance """ BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' - CRLF = '\r\n' + CRLF = u'\r\n' L = [] for key in sorted(fields.keys()): value = fields[key] @@ -814,7 +820,7 @@ class Cache(object): def __ensure(self, host): if self.cfp == None: - self.cfp = RawConfigParser() + self.cfp = configparser.ConfigParser() self.cfp.read(os.path.expanduser("~/.git-bz-cache")) if self.cfp.has_section(host): @@ -1019,10 +1025,9 @@ class BugServer(object): if self.use_git_credential: protocol = 'https' if self.https else 'http' - git_credential_input = "protocol={protocol}\nhost={host}\npath={path}\n\n".format(protocol=protocol, - host=self.host, - path=self.path.lstrip( - '/')) + git_credential_input = "protocol={protocol}\n" \ + "host={host}\npath={path}\n" \ + "\n".format(protocol=protocol, host=self.host, path=self.path.lstrip('/')) process = Popen(["git", "credential", "fill"], stdout=PIPE, stdin=PIPE) @@ -1076,6 +1081,8 @@ class BugServer(object): seen_urls = [] connection = get_connection(self.host, self.https) while True: + if data: + data = data.encode('UTF-8') connection.request(method, url, data, headers) response = connection.getresponse() seen_urls.append(url) @@ -1221,7 +1228,7 @@ class BugServer(object): return values -# mixin for xmlrpclib.Transport classes to add cookies +# mixin for xmlrpc.client.Transport classes to add cookies class CookieTransportMixin(object): def send_request(self, connection, *args): xmlrpc.client.Transport.send_request(self, connection, *args) @@ -1357,8 +1364,7 @@ class Bug(object): if response.status != 200: return None - match = re.search(r'name="token" value="([^"]+)', - response.read()) + match = re.search(r'name="token" value="([^"]+)', response.read().decode()) if not match: return None return match.group(1) @@ -1416,7 +1422,7 @@ class Bug(object): fields['bug_file_loc'] = '' response = self.server.send_post("/post_bug.cgi", fields) - response_data = response.read() + response_data = response.read().decode() m = check_for_success(response, response_data, r"<title>\s*Bug\s+([0-9]+)") if not m: @@ -1455,7 +1461,7 @@ class Bug(object): files = {'data': (filename, 'text/plain; charset=UTF-8', data)} response = self.server.send_post("/attachment.cgi", fields, files) - response_data = response.read() + response_data = response.read().decode() if not check_for_success(response, response_data, # Older bugzilla's used this for successful attachments r"<title>\s*Changes\s+Submitted", @@ -1489,9 +1495,8 @@ class Bug(object): # This is probably a good thing response = self.server.send_post("/process_bug.cgi", changes) - response_data = response.read() - if not check_for_success(response, response_data, - r"<title>\s*[Bug]*[\S\s]*processed\s*</title>"): + response_data = response.read().decode() + if not check_for_success(response, response_data, r"<title>\s*[Bug]*[\S\s]*processed\s*</title>"): # Mid-air collisions would be indicated by # "<title>Mid-air collision!</title>" print(response_data) @@ -1524,7 +1529,7 @@ class Bug(object): fields[field] = value response = self.server.send_post("/attachment.cgi", fields) - response_data = response.read() + response_data = response.read().decode() if not check_for_success(response, response_data, r"<title>\s*Changes\s+Submitted"): print(response_data) @@ -1768,7 +1773,7 @@ To restore the original branch and stop patching run "git bz apply --abort".''' def do_apply(*args): - git_dir = git.rev_parse(git_dir=True).decode() + git_dir = git.rev_parse(git_dir=True) resuming = global_options.resolved or global_options.skip or global_options.abort do_not_add_url = 0 @@ -1965,7 +1970,7 @@ FIXME: need commit message. # git-mailinfo to parse each patch, calling # add_url_to_subject_body(), and then reassembling. That would # be much more complicated though. - commits = rev_list_commits(orig_head.decode() + "..") + commits = rev_list_commits(orig_head + "..") add_url(bug, commits) bugs_applied.append(bug_ref) |