Fix some bugs in weblate system
offlate/systems/weblate.py
| 61 | 61 | l = json.loads(ans.text)['results'] | |
| 62 | 62 | self.files = l | |
| 63 | 63 | else: | |
| 64 | + | print(ans.text) | |
| 64 | 65 | raise ProjectNotFoundSystemException(self.name) | |
| 65 | 66 | ||
| 66 | 67 | def update(self, askmerge, callback=None): | |
| 67 | 68 | self.updateFileList() | |
| 68 | 69 | i = 0 | |
| 69 | 70 | for ff in self.files: | |
| 70 | - | callback.reportProgress(100.0 * i / len(self.files)) | |
| 71 | + | if callback is not None: | |
| 72 | + | callback.reportProgress(100.0 * i / len(self.files)) | |
| 71 | 73 | slug = ff['slug'] | |
| 72 | 74 | fname = self.filename(slug, False) | |
| 73 | 75 | sname = self.filename(slug, True) | |
… | |||
| 89 | 91 | raise UnsupportedFormatException(ff['file_format']) | |
| 90 | 92 | currentformat.merge(oldformat, askmerge) | |
| 91 | 93 | i += 1 | |
| 92 | - | callback.reportProgress(100) | |
| 94 | + | if callback is not None: | |
| 95 | + | callback.reportProgress(100) | |
| 93 | 96 | ||
| 94 | 97 | def filename(self, slug, is_source): | |
| 95 | 98 | ext = '' | |
… | |||
| 116 | 119 | ans = requests.get(self.data['instance'] + '/api/translations/' + | |
| 117 | 120 | self.data['project'] + '/' + slug + '/' + self.lang + '/file', | |
| 118 | 121 | auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 122 | + | encoding = ans.encoding if ans.encoding is not None else 'utf-8' | |
| 119 | 123 | if ans.status_code == 200: | |
| 120 | 124 | with open(self.filename(slug, False), 'wb') as f: | |
| 121 | - | f.write(ans.text.encode(ans.encoding)) | |
| 125 | + | f.write(ans.text.encode(encoding)) | |
| 122 | 126 | ||
| 123 | 127 | ans = requests.get(self.data['instance'] + '/api/translations/' + | |
| 124 | 128 | self.data['project'] + '/' + slug + '/' + source_lang + '/file', | |
| 125 | 129 | auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 130 | + | encoding = ans.encoding if ans.encoding is not None else 'utf-8' | |
| 126 | 131 | if ans.status_code == 200: | |
| 127 | 132 | with open(self.filename(slug, True), 'wb') as f: | |
| 128 | - | f.write(ans.text.encode(ans.encoding)) | |
| 133 | + | f.write(ans.text.encode(encoding)) | |
| 129 | 134 | else: | |
| 130 | 135 | print(ans.text) | |
| 131 | 136 | ||
… | |||
| 136 | 141 | callback.reportProgress(100.0 * i / len(self.files)) | |
| 137 | 142 | print('{} => {}'.format(slug['slug'], slug['file_format'])) | |
| 138 | 143 | filename = self.filename(slug['slug'], False) | |
| 139 | - | with open(filename, 'rb') as f: | |
| 140 | - | ans = requests.get(self.data['instance'] + '/api/translations/' + | |
| 141 | - | self.data['project'] + '/' + slug['slug'] + '/' + | |
| 142 | - | self.lang + '/file', | |
| 143 | - | files={'file': f}, | |
| 144 | - | auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 145 | - | print(ans) | |
| 146 | - | print(ans.text) | |
| 144 | + | ans = requests.post( | |
| 145 | + | self.data['instance'] + '/api/translations/' + | |
| 146 | + | self.data['project'] + '/' + slug['slug'] + '/' + | |
| 147 | + | self.lang + '/file/', | |
| 148 | + | files={'file': (os.path.basename(filename), open(filename, 'rb'))}, | |
| 149 | + | #data={'conflicts': 'replace-translated', | |
| 150 | + | # 'method': 'translate'}, | |
| 151 | + | auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 152 | + | print(ans) | |
| 153 | + | print(ans.text) | |
| 147 | 154 | i += 1 | |
| 148 | 155 | callback.reportProgress(100) | |
| 149 | 156 | ||