Show More
@@ -106,6 +106,23 b' class filebundlestore(object):' | |||||
106 | return None |
|
106 | return None | |
107 |
|
107 | |||
108 |
|
108 | |||
|
109 | def format_placeholders_args(args, filename=None, handle=None): | |||
|
110 | """Formats `args` with Infinitepush replacements. | |||
|
111 | ||||
|
112 | Hack to get `str.format()`-ed strings working in a BC way with | |||
|
113 | bytes. | |||
|
114 | """ | |||
|
115 | formatted_args = [] | |||
|
116 | for arg in args: | |||
|
117 | if filename and arg == b'{filename}': | |||
|
118 | formatted_args.append(filename) | |||
|
119 | elif handle and arg == b'{handle}': | |||
|
120 | formatted_args.append(handle) | |||
|
121 | else: | |||
|
122 | formatted_args.append(arg) | |||
|
123 | return formatted_args | |||
|
124 | ||||
|
125 | ||||
109 | class externalbundlestore(abstractbundlestore): |
|
126 | class externalbundlestore(abstractbundlestore): | |
110 | def __init__(self, put_binary, put_args, get_binary, get_args): |
|
127 | def __init__(self, put_binary, put_args, get_binary, get_args): | |
111 | """ |
|
128 | """ | |
@@ -144,9 +161,9 b' class externalbundlestore(abstractbundle' | |||||
144 | temp.write(data) |
|
161 | temp.write(data) | |
145 | temp.flush() |
|
162 | temp.flush() | |
146 | temp.seek(0) |
|
163 | temp.seek(0) | |
147 |
formatted_args = |
|
164 | formatted_args = format_placeholders_args( | |
148 |
|
|
165 | self.put_args, filename=temp.name | |
149 |
|
|
166 | ) | |
150 | returncode, stdout, stderr = self._call_binary( |
|
167 | returncode, stdout, stderr = self._call_binary( | |
151 | [self.put_binary] + formatted_args |
|
168 | [self.put_binary] + formatted_args | |
152 | ) |
|
169 | ) | |
@@ -166,12 +183,10 b' class externalbundlestore(abstractbundle' | |||||
166 | def read(self, handle): |
|
183 | def read(self, handle): | |
167 | # Won't work on windows because you can't open file second time without |
|
184 | # Won't work on windows because you can't open file second time without | |
168 | # closing it |
|
185 | # closing it | |
169 | # TODO: rewrite without str.format() |
|
|||
170 | with pycompat.namedtempfile() as temp: |
|
186 | with pycompat.namedtempfile() as temp: | |
171 |
formatted_args = |
|
187 | formatted_args = format_placeholders_args( | |
172 |
|
|
188 | self.get_args, filename=temp.name, handle=handle | |
173 | for arg in self.get_args |
|
189 | ) | |
174 | ] |
|
|||
175 | returncode, stdout, stderr = self._call_binary( |
|
190 | returncode, stdout, stderr = self._call_binary( | |
176 | [self.get_binary] + formatted_args |
|
191 | [self.get_binary] + formatted_args | |
177 | ) |
|
192 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now