Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: cms/translations/xtm/xtm_api.py

Issue 29908581: Issue #7036 - [XTM Integration] Add support for providing workflow name (Closed)
Left Patch Set: Created Oct. 12, 2018, 2:03 p.m.
Right Patch Set: Addressed comments from Patch Set 1 Created Oct. 18, 2018, 4:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 project_id, 383 project_id,
384 ) 384 )
385 headers = {'content-type': 'application/json'} 385 headers = {'content-type': 'application/json'}
386 386
387 response = self._execute(url, data=data, headers=headers) 387 response = self._execute(url, data=data, headers=headers)
388 388
389 if response.status_code != self._SuccessCodes.ADD_TARGET_LANGS: 389 if response.status_code != self._SuccessCodes.ADD_TARGET_LANGS:
390 raise XTMCloudException(response.status_code, response.content, 390 raise XTMCloudException(response.status_code, response.content,
391 'adding target languages to project') 391 'adding target languages to project')
392 392
393 def get_workflows_by_name(self, name, exact=True): 393 def get_workflows_by_name(self, name):
394 """Get workflows with a specific name. 394 """Get workflows with a specific name.
395 395
396 Parameters 396 Parameters
397 ---------- 397 ----------
398 name: str 398 name: str
399 The name of the workflow we're looking for. 399 The name of the workflow we're looking for.
400 exact: bool
Vasily Kuznetsov 2018/10/16 14:52:54 Do we actually use this?
Tudor Avram 2018/10/18 16:29:23 No, we don't. We're only interested in exact match
401 Whether we're looking for exact matches only or if partial ones
402 are ok, too. Default True.
403 400
404 Returns 401 Returns
405 ------- 402 -------
406 iterable 403 iterable
407 Of workflow ids that match the name. 404 Of workflow ids that match the name provided.
408 405
409 """ 406 """
410 url = self.base_url + self._UrlPaths.GET_WORKFLOW_IDS 407 url = self.base_url + self._UrlPaths.GET_WORKFLOW_IDS
411 408
412 response = self._execute(url, params={'name': name}) 409 response = self._execute(url, params={'name': name})
413 410
414 if response.status_code != self._SuccessCodes.GET_WORKFLOW_IDS: 411 if response.status_code != self._SuccessCodes.GET_WORKFLOW_IDS:
415 raise XTMCloudException(response.status_code, response.content, 412 raise XTMCloudException(response.status_code, response.content,
416 'extracting workflow ids') 413 'extracting workflow ids')
417
418 if not exact:
419 return [item['id']
420 for item in json.loads(response.content.encode('utf-8'))]
421 414
422 valid_ids = [] 415 valid_ids = []
423 for item in json.loads(response.content.encode('utf-8')): 416 for item in json.loads(response.content.encode('utf-8')):
424 if name.lower().replace(' ', '') == \ 417 if name.lower().replace(' ', '') == \
425 item['name'].lower().replace(' ', ''): 418 item['name'].lower().replace(' ', ''):
426 valid_ids.append(item['id']) 419 valid_ids.append(item['id'])
427 return valid_ids 420 return valid_ids
428 421
429 422
430 def get_token(username, password, user_id): 423 def get_token(username, password, user_id):
(...skipping 30 matching lines...) Expand all
461 headers = {'content-type': 'application/json'} 454 headers = {'content-type': 'application/json'}
462 455
463 response = requests.post(url, data=request_body, headers=headers) 456 response = requests.post(url, data=request_body, headers=headers)
464 457
465 if response.status_code == 200: 458 if response.status_code == 200:
466 return json.loads(response.text)['token'].encode() 459 return json.loads(response.text)['token'].encode()
467 460
468 raise XTMCloudException(response.status_code, 461 raise XTMCloudException(response.status_code,
469 response.text.encode('utf-8'), 462 response.text.encode('utf-8'),
470 'generating token') 463 'generating token')
LEFTRIGHT

Powered by Google App Engine
This is Rietveld