Skip to content

Commit

Permalink
core.Action: Remember apiurl
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Feb 14, 2023
1 parent 770217b commit f5da27a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2879,6 +2879,7 @@ class Action:
prefix_to_elm = {'src': 'source', 'tgt': 'target', 'opt': 'options'}

def __init__(self, type, **kwargs):
self.apiurl = kwargs.pop("apiurl", None)
if type not in Action.type_args.keys():
raise oscerr.WrongArgs('invalid action type: \'%s\'' % type)
self.type = type
Expand Down Expand Up @@ -2935,7 +2936,7 @@ def to_str(self):
return ET.tostring(root, encoding=ET_ENCODING)

@staticmethod
def from_xml(action_node):
def from_xml(action_node, apiurl=None):
"""create action from XML"""
if action_node is None or \
action_node.get('type') not in Action.type_args.keys() or \
Expand All @@ -2960,6 +2961,7 @@ def from_xml(action_node):
l.append(v)
else:
kwargs[k] = v
kwargs["apiurl"] = apiurl
return Action(action_node.get('type'), **kwargs)


Expand Down Expand Up @@ -3006,9 +3008,10 @@ def issues(self):
self._issues = get_request_issues(self.apiurl, self.id)
return self._issues

def read(self, root):
def read(self, root, apiurl=None):
"""read in a request"""
self._init_attributes()
self.apiurl = apiurl
if not root.get('id'):
raise oscerr.APIError('invalid request: %s\n' % ET.tostring(root, encoding=ET_ENCODING))
self.reqid = root.get('id')
Expand All @@ -3025,7 +3028,7 @@ def read(self, root):
i.set('type', 'submit')
action_nodes.append(i)
for action in action_nodes:
self.actions.append(Action.from_xml(action))
self.actions.append(Action.from_xml(action, self.apiurl))
for review in root.findall('review'):
self.reviews.append(ReviewState(review))
for history_element in root.findall('history'):
Expand Down Expand Up @@ -4517,8 +4520,7 @@ def get_request(apiurl: str, reqid):
root = ET.parse(f).getroot()

r = Request()
r.read(root)
r.apiurl = apiurl
r.read(root, apiurl=apiurl)
return r


Expand Down

0 comments on commit f5da27a

Please sign in to comment.