Commit 984b8653 authored by Eelco van der Wel's avatar Eelco van der Wel :speech_balloon:
Browse files

state=status

parent d755d314
Pipeline #3413 failed with stage
in 2 minutes and 59 seconds
Showing with 15 additions and 15 deletions
+15 -15
%% Cell type:code id:5b788afc tags:
``` python
# default_exp plugin.schema
```
%% Cell type:code id:f8766d7d tags:
``` python
# export
# hide
import random, string
from pymemri.data.itembase import Item
```
%% Cell type:code id:f36dd7c1 tags:
``` python
# export
# hide
class Account(Item):
properties = Item.properties + ['service', "identifier", "secret", "code", "refreshToken", "errorMessage"]
edges = Item.edges
def __init__(self, service=None, identifier=None, secret=None, code=None, refreshToken=None,
errorMessage=None, **kwargs):
super().__init__(**kwargs)
self.service = service
self.identifier = identifier
self.secret = secret
self.refreshToken = refreshToken
self.code = code
self.errorMessage = errorMessage
```
%% Cell type:code id:21341d97 tags:
``` python
# export
# hide
class PluginRun(Item):
properties = Item.properties + ["containerImage", "pluginModule", "pluginName", "state", "targetItemId",
properties = Item.properties + ["containerImage", "pluginModule", "pluginName", "status", "targetItemId",
"oAuthUrl", "error", "settings"]
edges = Item.edges + ["view", "persistentState", "account"]
def __init__(self, containerImage, pluginModule, pluginName, state=None, settings=None, view=None,
targetItemId=None, oAuthUrl=None, error=None, persistentState=None, account=None,
**kwargs):
"""
PluginRun defines a the run of plugin `plugin_module.plugin_name`,
with an optional `settings` string.
Args:
plugin_module (str): module of the plugin.
plugin_name (str): class name of the plugin.
settings (str, optional): Optional plugin configuration. For example,
this could be a `json.dumps` of a configuration dict. Defaults to None.
"""
super().__init__(**kwargs)
self.pluginModule = pluginModule
self.pluginName = pluginName
self.containerImage=containerImage
id_ = "".join([random.choice(string.hexdigits) for i in range(32)]) if targetItemId is None else targetItemId
self.targetItemId=id_
self.id=id_
self.state = state # for stateful plugins
self.status = status
self.settings = settings
self.oAuthUrl = oAuthUrl # for authenticated plugins
self.error = error # universa
self.oAuthUrl = oAuthUrl
self.error = error
self.account = account if account is not None else []
self.persistentState = persistentState if persistentState is not None else []
self.view = view if view is not None else []
```
%% Cell type:code id:1e94eca2 tags:
``` python
run = PluginRun("image", "module", "name", account=[Account()])
```
%% Cell type:code id:a8f74669 tags:
``` python
# export
# hide
class PersistentState(Item):
""" Persistent state variables saved for plugin such as views, accounts, the last state to resume from etc. """
properties = Item.properties + ["pluginId", "state"]
edges = Item.edges + ["account", "view"]
def __init__(self, pluginName=None, state=None, account=None, view=None, **kwargs):
super().__init__(**kwargs)
self.pluginName = pluginName
self.state = state
self.account = account if account is not None else []
self.view = view if view is not None else []
def get_state(self):
return self.state
def set_state(self, client, state_str):
self.state = state_str
client.update_item(self)
def get_account(self):
if len(self.account) == 0:
return None
else:
return self.account[0]
def set_account(self, client, account):
if len(self.account) == 0:
if not account.id:
client.create(account)
self.add_edge('account', account)
self.update(client)
else:
existing_account = self.account[0]
for prop in account.properties:
value = getattr(account, prop, None)
if value and hasattr(existing_account, prop):
setattr(existing_account, prop, value)
existing_account.update(client)
def get_view_by_name(self, view_name):
for cvu in self.view:
if cvu.name == view_name:
return cvu
def set_views(self, client, views=None):
for view in views:
client.create(view)
self.add_edge('view', view)
self.update(client)
return True
```
......
......@@ -22,25 +22,25 @@ def run_password_simulator(
time.sleep(SLEEP_INTERVAL)
pluginRun = client.get(run_id)
if pluginRun.state == "userActionNeeded":
if pluginRun.status == "userActionNeeded":
username, password = input_credentials()
pluginRun.identifier = username
pluginRun.secret = password
pluginRun.state = "ready"
pluginRun.status = "ready"
client.update(pluginRun)
elif pluginRun.state == "started":
elif pluginRun.status == "started":
print("plugin starting...")
elif pluginRun.state == "ready":
elif pluginRun.status == "ready":
print("no user action needed.")
elif pluginRun.state == "error":
elif pluginRun.status == "error":
print("error occurred in plugin.")
break
elif pluginRun.state == "done":
elif pluginRun.status == "done":
break
else:
print(f"unknown plugin state {pluginRun.state}.")
\ No newline at end of file
print(f"unknown plugin state {pluginRun.status}.")
\ No newline at end of file
......@@ -29,7 +29,7 @@ class Account(Item):
# Cell
# hide
class PluginRun(Item):
properties = Item.properties + ["containerImage", "pluginModule", "pluginName", "state", "targetItemId",
properties = Item.properties + ["containerImage", "pluginModule", "pluginName", "status", "targetItemId",
"oAuthUrl", "error", "settings"]
edges = Item.edges + ["view", "persistentState", "account"]
......@@ -53,10 +53,10 @@ class PluginRun(Item):
id_ = "".join([random.choice(string.hexdigits) for i in range(32)]) if targetItemId is None else targetItemId
self.targetItemId=id_
self.id=id_
self.state = state # for stateful plugins
self.status = status
self.settings = settings
self.oAuthUrl = oAuthUrl # for authenticated plugins
self.error = error # universa
self.oAuthUrl = oAuthUrl
self.error = error
self.account = account if account is not None else []
self.persistentState = persistentState if persistentState is not None else []
self.view = view if view is not None else []
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment