From 4ef126c4b9d4686f8aff772c20863dd6dbc1d782 Mon Sep 17 00:00:00 2001 From: Adam Fineman Date: Sun, 2 Feb 2020 22:17:01 +0000 Subject: [PATCH 1/2] Fixes issue #124. `tox pep8,py27,py36` now passes. --- rtcclient/template.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/rtcclient/template.py b/rtcclient/template.py index 36bba7e..ccdd183 100644 --- a/rtcclient/template.py +++ b/rtcclient/template.py @@ -351,18 +351,22 @@ def _remove_long_fields(self, wk_raw_data): match_str_list = ["rtc_cm:com.ibm.", "calm:"] + to_delete = [] for key in wk_raw_data.keys(): for match_str in match_str_list: if key.startswith(match_str): - try: - wk_raw_data.pop(key) - self.log.debug("Successfully remove field [%s] from " - "the template", key) - except: - self.log.warning("Cannot remove field [%s] from the " - "template", key) + to_delete.append(key) continue + for key in to_delete: + try: + del wk_raw_data[key] + self.log.debug("Successfully removed field [%s] from " + "the template", key) + except: + self.log.warning("Cannot remove field [%s] from the " + "template", key) + def getTemplates(self, workitems, template_folder=None, template_names=None, keep=False, encoding="UTF-8"): """Get templates from a group of to-be-copied :class:`Workitems` and From 24e55136ef2673f8b447e455d34b49688bbc97a7 Mon Sep 17 00:00:00 2001 From: Adam Fineman Date: Mon, 3 Feb 2020 01:04:36 +0000 Subject: [PATCH 2/2] Added attribute_map to RTCClient constructor. Fixes Issue #108 --- AUTHORS | 1 + ChangeLog | 3 +++ rtcclient/base.py | 19 +++++++++++-------- rtcclient/client.py | 8 +++++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/AUTHORS b/AUTHORS index 46a5d32..d077117 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,4 @@ +Adam Fineman Di Xu Felipe Ruhland stephenhsu diff --git a/ChangeLog b/ChangeLog index 343fba3..d0234fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ CHANGES ======= +* Fixes issue #124 +* remove broken PyPI downloads badge and add saythanks badge + 0.6.0 ----- diff --git a/rtcclient/base.py b/rtcclient/base.py index 91e5ed2..cf99960 100644 --- a/rtcclient/base.py +++ b/rtcclient/base.py @@ -257,20 +257,23 @@ def __initialize(self, resp): def __initializeFromRaw(self): """Initialze from raw data (OrderedDict)""" + attr_map = self.rtc_obj.attribute_map + if attr_map is None: + attr_map = {} + for (key, value) in self.raw_data.items(): if key.startswith("@"): # be compatible with IncludedInBuild if "@oslc_cm:label" != key: continue - attr = key.split(":")[-1].replace("-", "_") - attr_list = attr.split(".") - - # ignore long attributes - if len(attr_list) > 1: - # attr = "_".join([attr_list[-2], - # attr_list[-1]]) - continue + if key in attr_map: + attr = attr_map[key] + else: + # ignore long attributes + if '.' in key: + continue + attr = key.split(":")[-1].replace("-", "_") self.field_alias[attr] = key diff --git a/rtcclient/client.py b/rtcclient/client.py index c3da7d8..437717c 100644 --- a/rtcclient/client.py +++ b/rtcclient/client.py @@ -32,6 +32,11 @@ class RTCClient(RTCBase): the url ends with 'jazz', otherwise to `False` if with 'ccm' (Refer to issue #68 for details) :type ends_with_jazz: bool + :param attribute_map: (optional) Dictionary mapping RTC attributes to + keys. If ommitted, the default mapping will be, for example, + {'ns:some-attr': 'some_attr', 'other_ns:otherattr': 'otherattr', ...} + Also, long attributes with dots in their names will be discarded + unless present in the `attribute_map`. Tips: You can also customize your preferred properties to be returned by specified `returned_properties` when the called methods have @@ -47,7 +52,7 @@ class RTCClient(RTCBase): log = logging.getLogger("client.RTCClient") def __init__(self, url, username, password, proxies=None, searchpath=None, - ends_with_jazz=True): + ends_with_jazz=True, attribute_map=None): """Initialization See params above @@ -56,6 +61,7 @@ def __init__(self, url, username, password, proxies=None, searchpath=None, self.username = username self.password = password self.proxies = proxies + self.attribute_map = attribute_map RTCBase.__init__(self, url) if not isinstance(ends_with_jazz, bool):