Compare commits
No commits in common. "795754f858af31df0beb8eedbe797d4bb2fdebe3" and "72797e73ffbc05c25d681666d4f567f3360b0713" have entirely different histories.
795754f858
...
72797e73ff
|
@ -641,7 +641,11 @@ of Platypush to your fingertips.
|
|||
## Tests
|
||||
|
||||
To run the tests simply run `pytest` either from the project root folder or the
|
||||
`tests/` folder.
|
||||
`tests/` folder. Or run the following command from the project root folder:
|
||||
|
||||
```shell
|
||||
python -m tests
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><link rel="stylesheet" href="/fonts/poppins.css"><title>platypush</title><script defer="defer" type="module" src="/static/js/chunk-vendors.95bedba1.js"></script><script defer="defer" type="module" src="/static/js/app.8fd4b02d.js"></script><link href="/static/css/chunk-vendors.0fcd36f0.css" rel="stylesheet"><link href="/static/css/app.7cb6eac2.css" rel="stylesheet"><script defer="defer" src="/static/js/chunk-vendors-legacy.79dede0c.js" nomodule></script><script defer="defer" src="/static/js/app-legacy.2bd8b862.js" nomodule></script></head><body><noscript><strong>We're sorry but platypush doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><link rel="stylesheet" href="/fonts/poppins.css"><title>platypush</title><script defer="defer" type="module" src="/static/js/chunk-vendors.95bedba1.js"></script><script defer="defer" type="module" src="/static/js/app.5b73356c.js"></script><link href="/static/css/chunk-vendors.0fcd36f0.css" rel="stylesheet"><link href="/static/css/app.7cb6eac2.css" rel="stylesheet"><script defer="defer" src="/static/js/chunk-vendors-legacy.79dede0c.js" nomodule></script><script defer="defer" src="/static/js/app-legacy.d7eee501.js" nomodule></script></head><body><noscript><strong>We're sorry but platypush doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
1
platypush/backend/http/webapp/dist/static/css/201.fc29aeae.css
vendored
Normal file
2
platypush/backend/http/webapp/dist/static/js/7643-legacy.5b846090.js
vendored
Normal file
1
platypush/backend/http/webapp/dist/static/js/7643-legacy.5b846090.js.map
vendored
Normal file
2
platypush/backend/http/webapp/dist/static/js/7643.48f991b1.js
vendored
Normal file
1
platypush/backend/http/webapp/dist/static/js/7643.48f991b1.js.map
vendored
Normal file
2932
platypush/backend/http/webapp/package-lock.json
generated
|
@ -13,7 +13,6 @@
|
|||
"core-js": "^3.23.4",
|
||||
"lato-font": "^3.0.0",
|
||||
"mitt": "^2.1.0",
|
||||
"register-service-worker": "^1.7.2",
|
||||
"sass": "^1.53.0",
|
||||
"sass-loader": "^10.3.1",
|
||||
"vue": "^3.2.13",
|
||||
|
@ -26,7 +25,6 @@
|
|||
"@babel/eslint-parser": "^7.12.16",
|
||||
"@vue/cli-plugin-babel": "~5.0.0",
|
||||
"@vue/cli-plugin-eslint": "~5.0.0",
|
||||
"@vue/cli-plugin-pwa": "~5.0.0",
|
||||
"@vue/cli-service": "~5.0.0",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-plugin-vue": "^8.0.3"
|
||||
|
|
Before Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 4 KiB |
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 4.2 KiB |
|
@ -1,3 +0,0 @@
|
|||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8.00251 14.9297L0 1.07422H6.14651L8.00251 4.27503L9.84583 1.07422H16L8.00251 14.9297Z" fill="black"/>
|
||||
</svg>
|
Before Width: | Height: | Size: 215 B |
|
@ -2,26 +2,19 @@ function autocomplete(inp, arr, listener) {
|
|||
/*the autocomplete function takes two arguments,
|
||||
the text field element and an array of possible autocompleted values:*/
|
||||
let currentFocus;
|
||||
|
||||
/*execute a function when someone writes in the text field:*/
|
||||
inp.addEventListener("input", function() {
|
||||
let a, b, i, val = this.value;
|
||||
/*close any already open lists of autocompleted values*/
|
||||
closeAllLists();
|
||||
if (!val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!val) { return false;}
|
||||
currentFocus = -1;
|
||||
|
||||
/*create a DIV element that will contain the items (values):*/
|
||||
a = document.createElement("DIV");
|
||||
a.setAttribute("id", this.id + "autocomplete-list");
|
||||
a.setAttribute("class", "autocomplete-items");
|
||||
|
||||
/*append the DIV element as a child of the autocomplete container:*/
|
||||
this.parentNode.appendChild(a);
|
||||
|
||||
/*for each item in the array...*/
|
||||
for (i = 0; i < arr.length; i++) {
|
||||
/*check if the item starts with the same letters as the text field value:*/
|
||||
|
@ -50,13 +43,10 @@ function autocomplete(inp, arr, listener) {
|
|||
}
|
||||
});
|
||||
|
||||
inp.addEventListener("keyup", function(e) {
|
||||
if (["ArrowUp", "ArrowDown", "Tab", "Enter"].indexOf(e.key) >= 0) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
if (e.key === "Enter") {
|
||||
this.blur();
|
||||
inp.addEventListener("keydown", function(e) {
|
||||
if (e.keyCode === 9) {
|
||||
/*Reset the list if tab has been pressed*/
|
||||
closeAllLists();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -64,21 +54,19 @@ function autocomplete(inp, arr, listener) {
|
|||
inp.addEventListener("keydown", function(e) {
|
||||
let x = document.getElementById(this.id + "autocomplete-list");
|
||||
if (x) x = x.getElementsByTagName("div");
|
||||
if (e.key === 'ArrowDown' || (e.key === 'Tab' && !e.shiftKey)) {
|
||||
if (e.keyCode === 40) {
|
||||
/*If the arrow DOWN key is pressed,
|
||||
increase the currentFocus variable:*/
|
||||
currentFocus++;
|
||||
/*and and make the current item more visible:*/
|
||||
addActive(x);
|
||||
e.preventDefault();
|
||||
} else if (e.key === 'ArrowUp' || (e.key === 'Tab' && e.shiftKey)) { //up
|
||||
} else if (e.keyCode === 38) { //up
|
||||
/*If the arrow UP key is pressed,
|
||||
decrease the currentFocus variable:*/
|
||||
currentFocus--;
|
||||
/*and and make the current item more visible:*/
|
||||
addActive(x);
|
||||
e.preventDefault();
|
||||
} else if (e.key === 'Enter') {
|
||||
} else if (e.keyCode === 13) {
|
||||
/*If the ENTER key is pressed, prevent the form from being submitted,*/
|
||||
if (currentFocus > -1 && x && x.length) {
|
||||
e.preventDefault();
|
||||
|
@ -89,7 +77,6 @@ function autocomplete(inp, arr, listener) {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
function addActive(x) {
|
||||
/*a function to classify an item as "active":*/
|
||||
if (!x) return false;
|
||||
|
@ -100,14 +87,12 @@ function autocomplete(inp, arr, listener) {
|
|||
/*add class "autocomplete-active":*/
|
||||
x[currentFocus].classList.add("autocomplete-active");
|
||||
}
|
||||
|
||||
function removeActive(x) {
|
||||
/*a function to remove the "active" class from all autocomplete items:*/
|
||||
for (let i = 0; i < x.length; i++) {
|
||||
x[i].classList.remove("autocomplete-active");
|
||||
}
|
||||
}
|
||||
|
||||
function closeAllLists(elmnt) {
|
||||
/*close all autocomplete lists in the document,
|
||||
except the one passed as an argument:*/
|
||||
|
@ -118,7 +103,6 @@ function autocomplete(inp, arr, listener) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*execute a function when someone clicks in the document:*/
|
||||
document.addEventListener("click", function (e) {
|
||||
closeAllLists(e.target);
|
||||
|
|
|
@ -509,7 +509,6 @@ export default {
|
|||
|
||||
@include until(#{$tablet - 1}) {
|
||||
padding: 0;
|
||||
margin-bottom: $main-margin;
|
||||
}
|
||||
|
||||
@include from($tablet) {
|
||||
|
@ -525,8 +524,11 @@ export default {
|
|||
flex-direction: column;
|
||||
flex-grow: 1;
|
||||
position: relative;
|
||||
border-radius: 1em;
|
||||
box-shadow: $group-shadow;
|
||||
|
||||
@include from($tablet) {
|
||||
border-radius: 1em;
|
||||
box-shadow: $group-shadow;
|
||||
}
|
||||
}
|
||||
|
||||
.header {
|
||||
|
@ -577,6 +579,10 @@ export default {
|
|||
overflow: auto;
|
||||
flex-grow: 1;
|
||||
|
||||
@include until(#{$tablet - 1}) {
|
||||
background: $default-bg-4;
|
||||
}
|
||||
|
||||
@include from($tablet) {
|
||||
background: $default-bg-2;
|
||||
}
|
||||
|
@ -584,8 +590,16 @@ export default {
|
|||
.entity-frame {
|
||||
background: $background-color;
|
||||
|
||||
&:last-child {
|
||||
border-radius: 0 0 1em 1em;
|
||||
@include until(#{$tablet - 1}) {
|
||||
margin: 0.75em 0.25em;
|
||||
border: $default-border-2;
|
||||
border-radius: 1em;
|
||||
}
|
||||
|
||||
@include from($tablet) {
|
||||
&:last-child {
|
||||
border-radius: 0 0 1em 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@ $collapse-toggler-width: 2em;
|
|||
background: $selected-bg;
|
||||
font-weight: bold;
|
||||
box-shadow: 0 0 3px 2px $default-shadow-color;
|
||||
|
||||
@include until(#{$tablet - 1}) {
|
||||
border-radius: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
.entity-container {
|
||||
|
@ -14,7 +18,18 @@ $collapse-toggler-width: 2em;
|
|||
align-items: center;
|
||||
position: relative;
|
||||
padding: 0 !important;
|
||||
border-bottom: $default-border-3;
|
||||
|
||||
@include until(#{$tablet - 1}) {
|
||||
border-radius: 1em;
|
||||
|
||||
&:not(:last-child) {
|
||||
border-bottom: $default-border-3;
|
||||
}
|
||||
}
|
||||
|
||||
@include from($tablet) {
|
||||
border-bottom: $default-border-3;
|
||||
}
|
||||
|
||||
&.with-children:not(.collapsed) {
|
||||
@include expanded-entity();
|
||||
|
@ -35,6 +50,12 @@ $collapse-toggler-width: 2em;
|
|||
}
|
||||
|
||||
@include until(#{$tablet - 1}) {
|
||||
.entity-container {
|
||||
.children {
|
||||
border-radius: 0 0 1em 1em;
|
||||
}
|
||||
}
|
||||
|
||||
.child {
|
||||
&:not(:last-child) {
|
||||
.entity-container {
|
||||
|
@ -218,8 +239,38 @@ $collapse-toggler-width: 2em;
|
|||
&.with-children:not(.collapsed) {
|
||||
box-shadow: 0 3px 4px 0 $default-shadow-color;
|
||||
|
||||
.children .child:last-child {
|
||||
box-shadow: 0 3px 4px 0 $default-shadow-color;
|
||||
@include until(#{$tablet - 1}) {
|
||||
border-radius: 1em;
|
||||
}
|
||||
|
||||
@include from($tablet) {
|
||||
.children .child:last-child {
|
||||
box-shadow: 0 3px 4px 0 $default-shadow-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@include until(#{$tablet - 1}) {
|
||||
box-shadow: 0 3px 4px 0 $default-shadow-color;
|
||||
|
||||
&.collapsed {
|
||||
border-radius: 1em;
|
||||
}
|
||||
|
||||
.children {
|
||||
.entity-container-wrapper {
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
|
||||
&.with-children:not(.collapsed) {
|
||||
border-radius: 1em;
|
||||
box-shadow: 0 3px 4px 0 $default-shadow-color;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-radius: 0 0 1em 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
@change="actionChanged=true" @blur="updateAction">
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" class="run-btn btn-primary"
|
||||
:disabled="running || !action?.name?.length" title="Run">
|
||||
<button type="submit" class="run-btn btn-primary" :disabled="running" title="Run">
|
||||
<i class="fas fa-play" />
|
||||
</button>
|
||||
|
||||
|
@ -31,10 +30,8 @@
|
|||
Action documentation
|
||||
</div>
|
||||
|
||||
<div class="doc html">
|
||||
<Loading v-if="docLoading" />
|
||||
<span v-html="selectedDoc" v-else />
|
||||
</div>
|
||||
<div class="doc html" v-html="selectedDoc" v-if="htmlDoc" />
|
||||
<div class="doc raw" v-text="selectedDoc" v-else />
|
||||
</div>
|
||||
|
||||
<div class="options" v-if="action.name in actions && (Object.keys(action.args).length ||
|
||||
|
@ -54,10 +51,8 @@
|
|||
Attribute: <div class="attr-name" v-text="selectedAttr" />
|
||||
</div>
|
||||
|
||||
<div class="doc html">
|
||||
<Loading v-if="docLoading" />
|
||||
<span v-html="selectedAttrDoc" v-else />
|
||||
</div>
|
||||
<div class="doc html" v-html="selectedAttrDoc" v-if="htmlDoc" />
|
||||
<div class="doc raw" v-text="selectedAttrDoc" v-else />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -67,11 +62,11 @@
|
|||
<input type="text" class="action-extra-param-name" :disabled="running"
|
||||
placeholder="Name" v-model="action.extraArgs[i].name">
|
||||
</label>
|
||||
<label class="col-6">
|
||||
<label class="col-5">
|
||||
<input type="text" class="action-extra-param-value" :disabled="running"
|
||||
placeholder="Value" v-model="action.extraArgs[i].value">
|
||||
</label>
|
||||
<label class="col-1 buttons">
|
||||
<label class="col-2 buttons">
|
||||
<button type="button" class="action-extra-param-del" title="Remove parameter"
|
||||
@click="removeParameter(i)">
|
||||
<i class="fas fa-trash" />
|
||||
|
@ -92,24 +87,22 @@
|
|||
Attribute: <div class="attr-name" v-text="selectedAttr" />
|
||||
</div>
|
||||
|
||||
<div class="doc html">
|
||||
<Loading v-if="docLoading" />
|
||||
<span v-html="selectedAttrDoc" v-else />
|
||||
</div>
|
||||
<div class="doc html" v-html="selectedAttrDoc" v-if="htmlDoc" />
|
||||
<div class="doc raw" v-text="selectedAttrDoc" v-else />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="output-container">
|
||||
<div class="title" v-text="error != null ? 'Error' : 'Output'" v-if="error != null || response != null" />
|
||||
<div class="response" v-html="response" v-if="response != null" />
|
||||
<div class="error" v-html="error" v-else-if="error != null" />
|
||||
<div class="output-container">
|
||||
<div class="title" v-text="error != null ? 'Error' : 'Output'" v-if="error != null || response != null" />
|
||||
<div class="response" v-html="response" v-if="response != null" />
|
||||
<div class="error" v-html="error" v-else-if="error != null" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="request raw-request" :class="structuredInput ? 'hidden' : ''">
|
||||
<div class="first-row">
|
||||
<label>
|
||||
<textarea v-model="rawRequest" ref="rawAction" :placeholder="rawRequestPlaceholder" />
|
||||
<textarea v-model="rawRequest" placeholder="Raw JSON request" />
|
||||
</label>
|
||||
<button type="submit" :disabled="running" class="run-btn btn-primary" title="Run">
|
||||
<i class="fas fa-play" />
|
||||
|
@ -170,7 +163,6 @@ export default {
|
|||
return {
|
||||
loading: false,
|
||||
running: false,
|
||||
docLoading: false,
|
||||
structuredInput: true,
|
||||
actionChanged: false,
|
||||
selectedDoc: undefined,
|
||||
|
@ -183,13 +175,11 @@ export default {
|
|||
|
||||
response: undefined,
|
||||
error: undefined,
|
||||
htmlDoc: false,
|
||||
rawRequest: undefined,
|
||||
rawRequestPlaceholder: 'Raw JSON request. Example:\n\n' +
|
||||
'{"type": "request", "action": "file.list", "args": {"path": "/"}}',
|
||||
actions: {},
|
||||
plugins: {},
|
||||
procedures: {},
|
||||
actionDocsCache: {},
|
||||
action: {
|
||||
name: undefined,
|
||||
args: {},
|
||||
|
@ -205,12 +195,15 @@ export default {
|
|||
|
||||
try {
|
||||
this.procedures = await this.request('inspect.get_procedures')
|
||||
this.plugins = await this.request('inspect.get_all_plugins')
|
||||
this.plugins = await this.request('inspect.get_all_plugins', {html_doc: false})
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
|
||||
for (const plugin of Object.values(this.plugins)) {
|
||||
if (plugin.html_doc)
|
||||
this.htmlDoc = true
|
||||
|
||||
for (const action of Object.values(plugin.actions)) {
|
||||
action.name = plugin.name + '.' + action.name
|
||||
action.supportsExtraArgs = !!action.has_kwargs
|
||||
|
@ -220,20 +213,20 @@ export default {
|
|||
}
|
||||
|
||||
const self = this
|
||||
autocomplete(this.$refs.actionName, Object.keys(this.actions).sort(), (_, value) => {
|
||||
autocomplete(this.$refs.actionName, Object.keys(this.actions).sort(), (evt, value) => {
|
||||
this.action.name = value
|
||||
self.updateAction()
|
||||
})
|
||||
},
|
||||
|
||||
async updateAction() {
|
||||
updateAction() {
|
||||
if (!(this.action.name in this.actions))
|
||||
this.selectedDoc = undefined
|
||||
|
||||
if (!this.actionChanged || !(this.action.name in this.actions))
|
||||
return
|
||||
|
||||
this.docLoading = true
|
||||
this.loading = true
|
||||
try {
|
||||
this.action = {
|
||||
...this.actions[this.action.name],
|
||||
|
@ -248,27 +241,32 @@ export default {
|
|||
extraArgs: [],
|
||||
}
|
||||
} finally {
|
||||
this.docLoading = false
|
||||
this.loading = false
|
||||
}
|
||||
|
||||
this.selectedDoc =
|
||||
this.actionDocsCache[this.action.name]?.html ||
|
||||
await this.parseDoc(this.action.doc)
|
||||
|
||||
if (!this.actionDocsCache[this.action.name])
|
||||
this.actionDocsCache[this.action.name] = {}
|
||||
this.actionDocsCache[this.action.name].html = this.selectedDoc
|
||||
|
||||
this.selectedDoc = this.parseDoc(this.action.doc)
|
||||
this.actionChanged = false
|
||||
this.response = undefined
|
||||
this.error = undefined
|
||||
},
|
||||
|
||||
async parseDoc(docString) {
|
||||
if (!docString?.length)
|
||||
parseDoc(docString) {
|
||||
if (!docString?.length || this.htmlDoc)
|
||||
return docString
|
||||
|
||||
return await this.request('utils.rst_to_html', {text: docString})
|
||||
let lineNo = 0
|
||||
let trailingSpaces = 0
|
||||
|
||||
return docString.split('\n').reduce((doc, line) => {
|
||||
if (++lineNo === 2)
|
||||
trailingSpaces = line.match(/^(\s*)/)[1].length
|
||||
|
||||
if (line.trim().startsWith('.. code-block'))
|
||||
return doc
|
||||
|
||||
doc += line.slice(trailingSpaces).replaceAll('``', '') + '\n'
|
||||
return doc
|
||||
}, '')
|
||||
},
|
||||
|
||||
updateProcedure(name, event) {
|
||||
|
@ -310,16 +308,11 @@ export default {
|
|||
this.action.extraArgs.pop(i)
|
||||
},
|
||||
|
||||
async selectAttrDoc(name) {
|
||||
selectAttrDoc(name) {
|
||||
this.response = undefined
|
||||
this.error = undefined
|
||||
this.selectedAttr = name
|
||||
this.selectedAttrDoc =
|
||||
this.actionDocsCache[this.action.name]?.[name]?.html ||
|
||||
await this.parseDoc(this.action.args[name].doc)
|
||||
|
||||
if (!this.actionDocsCache[this.action.name])
|
||||
this.actionDocsCache[this.action.name] = {}
|
||||
|
||||
this.actionDocsCache[this.action.name][name] = {html: this.selectedAttrDoc}
|
||||
this.selectedAttrDoc = this.parseDoc(this.action.args[name].doc)
|
||||
},
|
||||
|
||||
resetAttrDoc() {
|
||||
|
@ -333,13 +326,6 @@ export default {
|
|||
this.structuredInput = structuredInput
|
||||
this.response = undefined
|
||||
this.error = undefined
|
||||
this.$nextTick(() => {
|
||||
if (structuredInput) {
|
||||
this.$refs.actionName.focus()
|
||||
} else {
|
||||
this.$refs.rawAction.focus()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onResponse(response) {
|
||||
|
@ -436,10 +422,6 @@ export default {
|
|||
},
|
||||
|
||||
mounted() {
|
||||
this.$nextTick(() => {
|
||||
this.$refs.actionName.focus()
|
||||
})
|
||||
|
||||
this.refresh()
|
||||
},
|
||||
}
|
||||
|
@ -468,12 +450,11 @@ $params-tablet-width: 20em;
|
|||
}
|
||||
|
||||
.action-form {
|
||||
background: $default-bg-2;
|
||||
padding: 1em .5em;
|
||||
}
|
||||
|
||||
.title {
|
||||
background: $header-bg;
|
||||
background: $title-bg;
|
||||
padding: .5em;
|
||||
border: $title-border;
|
||||
box-shadow: $title-shadow;
|
||||
|
@ -563,26 +544,12 @@ $params-tablet-width: 20em;
|
|||
display: flex;
|
||||
margin-bottom: .5em;
|
||||
|
||||
label {
|
||||
margin-left: 0.25em;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
justify-content: right;
|
||||
}
|
||||
|
||||
.action-extra-param-del {
|
||||
border: 0;
|
||||
text-align: right;
|
||||
padding: 0 .5em;
|
||||
}
|
||||
|
||||
input[type=text] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
@ -602,6 +569,11 @@ $params-tablet-width: 20em;
|
|||
.doc-container,
|
||||
.output-container {
|
||||
margin-top: .5em;
|
||||
.doc {
|
||||
&.raw {
|
||||
white-space: pre;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.output-container {
|
||||
|
@ -618,6 +590,7 @@ $params-tablet-width: 20em;
|
|||
}
|
||||
|
||||
.doc {
|
||||
white-space: pre-line;
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
@ -640,6 +613,11 @@ $params-tablet-width: 20em;
|
|||
.attr-doc-container {
|
||||
.doc {
|
||||
padding: 1em !important;
|
||||
|
||||
&.raw {
|
||||
font-family: monospace;
|
||||
font-size: .8em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -769,30 +747,11 @@ $params-tablet-width: 20em;
|
|||
}
|
||||
|
||||
.run-btn {
|
||||
background: $background-color;
|
||||
border-radius: .25em;
|
||||
padding: .5em 1.5em;
|
||||
box-shadow: $primary-btn-shadow;
|
||||
cursor: pointer;
|
||||
border-radius: 2em;
|
||||
padding: .5em .75em;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.7;
|
||||
color: $default-fg-2;
|
||||
cursor: initial;
|
||||
box-shadow: none;
|
||||
|
||||
&:hover {
|
||||
background: $background-color;
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
&:not(disabled) {
|
||||
opacity: .8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ $response-bg: #edfff2;
|
|||
$response-border: 1px dashed #98ff98;
|
||||
$error-bg: #ffbcbc;
|
||||
$error-border: 1px dashed #ff5353;
|
||||
$doc-bg: $background-color;
|
||||
$doc-border: 1px dashed $border-color-2;
|
||||
$doc-bg: #e8feff;
|
||||
$doc-border: 1px dashed #84f9ff;
|
||||
$procedure-submit-btn-bg: #ebffeb;
|
||||
$section-title-bg: rgba(0, 0, 0, .04);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { createApp } from 'vue'
|
||||
import App from '@/App.vue'
|
||||
import router from '@/router'
|
||||
import './registerServiceWorker'
|
||||
|
||||
const app = createApp(App)
|
||||
app.config.globalProperties._config = window.config
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/* eslint-disable no-console */
|
||||
|
||||
import { register } from 'register-service-worker'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||
ready () {
|
||||
console.log(
|
||||
'App is being served from cache by a service worker.\n' +
|
||||
'For more details, visit https://goo.gl/AFskqB'
|
||||
)
|
||||
},
|
||||
registered () {
|
||||
console.log('Service worker has been registered.')
|
||||
},
|
||||
cached () {
|
||||
console.log('Content has been cached for offline use.')
|
||||
},
|
||||
updatefound () {
|
||||
console.log('New content is downloading.')
|
||||
},
|
||||
updated () {
|
||||
console.log('New content is available; please refresh.')
|
||||
},
|
||||
offline () {
|
||||
console.log('No internet connection found. App is running in offline mode.')
|
||||
},
|
||||
error (error) {
|
||||
console.error('Error during service worker registration:', error)
|
||||
}
|
||||
})
|
||||
}
|
|
@ -22,11 +22,11 @@
|
|||
background-color: $background-color;
|
||||
|
||||
&:hover {
|
||||
background-color: $hover-bg-2;
|
||||
background-color: $hover-bg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.autocomplete-active {
|
||||
background-color: $hover-bg-2 !important;
|
||||
background-color: $selected-bg !important;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@ $border-shadow-right: 2.5px 0 4px 0 $default-shadow-color;
|
|||
$border-shadow-bottom-right: 2.5px 2.5px 3px 0 $default-shadow-color;
|
||||
$header-shadow: 0px 1px 3px 1px #bbb !default;
|
||||
$group-shadow: 3px -2px 6px 1px #98b0a0;
|
||||
$primary-btn-shadow: 1px 1px 0.5px 0.75px #32b64640 !default;
|
||||
|
||||
//// Modals
|
||||
$modal-header-bg: #e0e0e0 !default;
|
||||
|
@ -82,7 +81,6 @@ $default-hover-fg: #35b870 !default;
|
|||
$default-hover-fg-2: #38cf80 !default;
|
||||
$hover-fg: $default-hover-fg !default;
|
||||
$hover-bg: linear-gradient(90deg, rgba(190,246,218,1) 0%, rgba(229,251,240,1) 100%) !default;
|
||||
$hover-bg-2: rgb(190,246,218) !default;
|
||||
$active-bg: #8fefb7 !default;
|
||||
|
||||
/// Disabled
|
||||
|
|
|
@ -1,36 +1,28 @@
|
|||
from collections import defaultdict
|
||||
import importlib
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import pickle
|
||||
import pkgutil
|
||||
from types import ModuleType
|
||||
from typing import Callable, Dict, Generator, Optional, Type, Union
|
||||
import threading
|
||||
from typing import Optional
|
||||
|
||||
import platypush.backend # lgtm [py/import-and-import-from]
|
||||
import platypush.plugins # lgtm [py/import-and-import-from]
|
||||
import platypush.message.event # lgtm [py/import-and-import-from]
|
||||
import platypush.message.response # lgtm [py/import-and-import-from]
|
||||
|
||||
from platypush.backend import Backend
|
||||
from platypush.config import Config
|
||||
from platypush.plugins import Plugin, action
|
||||
from platypush.message.event import Event
|
||||
from platypush.message.response import Response
|
||||
from platypush.utils import (
|
||||
get_backend_class_by_name,
|
||||
get_backend_name_by_class,
|
||||
get_plugin_class_by_name,
|
||||
get_plugin_name_by_class,
|
||||
)
|
||||
from platypush.utils.manifest import Manifest, scan_manifests
|
||||
|
||||
from ._context import ComponentContext
|
||||
from ._model import (
|
||||
BackendModel,
|
||||
EventModel,
|
||||
Model,
|
||||
PluginModel,
|
||||
ProcedureEncoder,
|
||||
ResponseModel,
|
||||
)
|
||||
from ._serialize import ProcedureEncoder
|
||||
|
||||
|
||||
class InspectPlugin(Plugin):
|
||||
|
@ -40,326 +32,183 @@ class InspectPlugin(Plugin):
|
|||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._components_cache_file = os.path.join(
|
||||
Config.get('workdir'), # type: ignore
|
||||
'components.cache', # type: ignore
|
||||
)
|
||||
self._components_context: Dict[type, ComponentContext] = defaultdict(
|
||||
ComponentContext
|
||||
)
|
||||
self._components_cache: Dict[type, dict] = defaultdict(dict)
|
||||
self._load_components_cache()
|
||||
self._plugins = {}
|
||||
self._backends = {}
|
||||
self._events = {}
|
||||
self._responses = {}
|
||||
self._plugins_lock = threading.RLock()
|
||||
self._backends_lock = threading.RLock()
|
||||
self._events_lock = threading.RLock()
|
||||
self._responses_lock = threading.RLock()
|
||||
self._html_doc = False
|
||||
|
||||
def _load_components_cache(self):
|
||||
"""
|
||||
Loads the components cache from disk.
|
||||
"""
|
||||
try:
|
||||
with open(self._components_cache_file, 'rb') as f:
|
||||
self._components_cache = pickle.load(f)
|
||||
except OSError:
|
||||
return
|
||||
|
||||
def _flush_components_cache(self):
|
||||
"""
|
||||
Flush the current components cache to disk.
|
||||
"""
|
||||
with open(self._components_cache_file, 'wb') as f:
|
||||
pickle.dump(self._components_cache, f)
|
||||
|
||||
def _get_cached_component(
|
||||
self, base_type: type, comp_type: type
|
||||
) -> Optional[Model]:
|
||||
"""
|
||||
Retrieve a cached component's ``Model``.
|
||||
|
||||
:param base_type: The base type of the component (e.g. ``Plugin`` or
|
||||
``Backend``).
|
||||
:param comp_type: The specific type of the component (e.g.
|
||||
``MusicMpdPlugin`` or ``HttpBackend``).
|
||||
:return: The cached component's ``Model`` if it exists, otherwise null.
|
||||
"""
|
||||
return self._components_cache.get(base_type, {}).get(comp_type)
|
||||
|
||||
def _cache_component(
|
||||
self,
|
||||
base_type: type,
|
||||
comp_type: type,
|
||||
model: Model,
|
||||
index_by_module: bool = False,
|
||||
):
|
||||
"""
|
||||
Cache the ``Model`` object for a component.
|
||||
|
||||
:param base_type: The base type of the component (e.g. ``Plugin`` or
|
||||
``Backend``).
|
||||
:param comp_type: The specific type of the component (e.g.
|
||||
``MusicMpdPlugin`` or ``HttpBackend``).
|
||||
:param model: The ``Model`` object to cache.
|
||||
:param index_by_module: If ``True``, the ``Model`` object will be
|
||||
indexed according to the ``base_type -> module -> comp_type``
|
||||
mapping, otherwise ``base_type -> comp_type``.
|
||||
"""
|
||||
if index_by_module:
|
||||
if not self._components_cache.get(base_type, {}).get(model.package):
|
||||
self._components_cache[base_type][model.package] = {}
|
||||
self._components_cache[base_type][model.package][comp_type] = model
|
||||
else:
|
||||
self._components_cache[base_type][comp_type] = model
|
||||
|
||||
def _scan_integrations(self, base_type: type):
|
||||
"""
|
||||
A generator that scans the manifest files given a ``base_type``
|
||||
(``Plugin`` or ``Backend``) and yields the parsed submodules.
|
||||
"""
|
||||
for mf_file in scan_manifests(base_type):
|
||||
manifest = Manifest.from_file(mf_file)
|
||||
try:
|
||||
yield importlib.import_module(manifest.package)
|
||||
except Exception as e:
|
||||
self.logger.debug(
|
||||
'Could not import module %s: %s',
|
||||
manifest.package,
|
||||
e,
|
||||
)
|
||||
continue
|
||||
|
||||
def _scan_modules(self, base_type: type) -> Generator[ModuleType, None, None]:
|
||||
"""
|
||||
A generator that scan the modules given a ``base_type`` (e.g. ``Event``).
|
||||
|
||||
Unlike :meth:`._scan_integrations`, this method recursively scans the
|
||||
modules using ``pkgutil`` instead of using the information provided in
|
||||
the integrations' manifest files.
|
||||
"""
|
||||
prefix = base_type.__module__ + '.'
|
||||
path = str(pathlib.Path(inspect.getfile(base_type)).parent)
|
||||
def _init_plugins(self):
|
||||
package = platypush.plugins
|
||||
prefix = package.__name__ + '.'
|
||||
|
||||
for _, modname, _ in pkgutil.walk_packages(
|
||||
path=[path], prefix=prefix, onerror=lambda _: None
|
||||
path=package.__path__, prefix=prefix, onerror=lambda _: None
|
||||
):
|
||||
try:
|
||||
yield importlib.import_module(modname)
|
||||
module = importlib.import_module(modname)
|
||||
except Exception as e:
|
||||
self.logger.warning('Could not import module %s: %s', modname, e)
|
||||
continue
|
||||
|
||||
for _, obj in inspect.getmembers(module):
|
||||
if inspect.isclass(obj) and issubclass(obj, Plugin):
|
||||
model = PluginModel(
|
||||
plugin=obj, prefix=prefix, html_doc=self._html_doc
|
||||
)
|
||||
if model.name:
|
||||
self._plugins[model.name] = model
|
||||
|
||||
def _init_backends(self):
|
||||
package = platypush.backend
|
||||
prefix = package.__name__ + '.'
|
||||
|
||||
for _, modname, _ in pkgutil.walk_packages(
|
||||
path=package.__path__, prefix=prefix, onerror=lambda _: None
|
||||
):
|
||||
try:
|
||||
module = importlib.import_module(modname)
|
||||
except Exception as e:
|
||||
self.logger.debug('Could not import module %s: %s', modname, e)
|
||||
continue
|
||||
|
||||
def _init_component(
|
||||
self,
|
||||
base_type: type,
|
||||
comp_type: type,
|
||||
model_type: Type[Model],
|
||||
index_by_module: bool = False,
|
||||
) -> Model:
|
||||
"""
|
||||
Initialize a component's ``Model`` object and cache it.
|
||||
|
||||
:param base_type: The base type of the component (e.g. ``Plugin`` or
|
||||
``Backend``).
|
||||
:param comp_type: The specific type of the component (e.g.
|
||||
``MusicMpdPlugin`` or ``HttpBackend``).
|
||||
:param model_type: The type of the ``Model`` object that should be
|
||||
created.
|
||||
:param index_by_module: If ``True``, the ``Model`` object will be
|
||||
indexed according to the ``base_type -> module -> comp_type``
|
||||
mapping, otherwise ``base_type -> comp_type``.
|
||||
:return: The initialized component's ``Model`` object.
|
||||
"""
|
||||
prefix = base_type.__module__ + '.'
|
||||
comp_file = inspect.getsourcefile(comp_type)
|
||||
model = None
|
||||
mtime = None
|
||||
|
||||
if comp_file:
|
||||
mtime = os.stat(comp_file).st_mtime
|
||||
cached_model = self._get_cached_component(base_type, comp_type)
|
||||
|
||||
# Only update the component model if its source file was
|
||||
# modified since the last time it was scanned
|
||||
if (
|
||||
cached_model
|
||||
and cached_model.last_modified
|
||||
and mtime <= cached_model.last_modified
|
||||
):
|
||||
model = cached_model
|
||||
|
||||
if not model:
|
||||
self.logger.info('Scanning component %s', comp_type.__name__)
|
||||
model = model_type(comp_type, prefix=prefix, last_modified=mtime)
|
||||
|
||||
self._cache_component(
|
||||
base_type, comp_type, model, index_by_module=index_by_module
|
||||
)
|
||||
return model
|
||||
|
||||
def _init_modules(
|
||||
self,
|
||||
base_type: type,
|
||||
model_type: Type[Model],
|
||||
):
|
||||
"""
|
||||
Initializes, parses and caches all the components of a given type.
|
||||
|
||||
Unlike :meth:`._scan_integrations`, this method inspects all the
|
||||
members of a ``module`` for those that match the given ``base_type``
|
||||
instead of relying on the information provided in the manifest.
|
||||
|
||||
It is a bit more inefficient, but it works fine for simple components
|
||||
(like entities and messages) that don't require extra recursive parsing
|
||||
logic for their docs (unlike plugins).
|
||||
"""
|
||||
for module in self._scan_modules(base_type):
|
||||
for _, obj_type in inspect.getmembers(module):
|
||||
if (
|
||||
inspect.isclass(obj_type)
|
||||
and issubclass(obj_type, base_type)
|
||||
# Exclude the base_type itself
|
||||
and obj_type != base_type
|
||||
):
|
||||
self._init_component(
|
||||
base_type=base_type,
|
||||
comp_type=obj_type,
|
||||
model_type=model_type,
|
||||
index_by_module=True,
|
||||
for _, obj in inspect.getmembers(module):
|
||||
if inspect.isclass(obj) and issubclass(obj, Backend):
|
||||
model = BackendModel(
|
||||
backend=obj, prefix=prefix, html_doc=self._html_doc
|
||||
)
|
||||
|
||||
def _init_integrations(
|
||||
self,
|
||||
base_type: Type[Union[Plugin, Backend]],
|
||||
model_type: Type[Union[PluginModel, BackendModel]],
|
||||
class_by_name: Callable[[str], Optional[type]],
|
||||
):
|
||||
"""
|
||||
Initializes, parses and caches all the integrations of a given type.
|
||||
|
||||
:param base_type: The base type of the component (e.g. ``Plugin`` or
|
||||
``Backend``).
|
||||
:param model_type: The type of the ``Model`` objects that should be
|
||||
created.
|
||||
:param class_by_name: A function that returns the class of a given
|
||||
integration given its qualified name.
|
||||
"""
|
||||
for module in self._scan_integrations(base_type):
|
||||
comp_name = '.'.join(module.__name__.split('.')[2:])
|
||||
comp_type = class_by_name(comp_name)
|
||||
if not comp_type:
|
||||
continue
|
||||
|
||||
self._init_component(
|
||||
base_type=base_type,
|
||||
comp_type=comp_type,
|
||||
model_type=model_type,
|
||||
)
|
||||
|
||||
self._flush_components_cache()
|
||||
|
||||
def _init_plugins(self):
|
||||
"""
|
||||
Initializes and caches all the available plugins.
|
||||
"""
|
||||
self._init_integrations(
|
||||
base_type=Plugin,
|
||||
model_type=PluginModel,
|
||||
class_by_name=get_plugin_class_by_name,
|
||||
)
|
||||
|
||||
def _init_backends(self):
|
||||
"""
|
||||
Initializes and caches all the available backends.
|
||||
"""
|
||||
self._init_integrations(
|
||||
base_type=Backend,
|
||||
model_type=BackendModel,
|
||||
class_by_name=get_backend_class_by_name,
|
||||
)
|
||||
if model.name:
|
||||
self._backends[model.name] = model
|
||||
|
||||
def _init_events(self):
|
||||
"""
|
||||
Initializes and caches all the available events.
|
||||
"""
|
||||
self._init_modules(
|
||||
base_type=Event,
|
||||
model_type=EventModel,
|
||||
)
|
||||
package = platypush.message.event
|
||||
prefix = package.__name__ + '.'
|
||||
|
||||
for _, modname, _ in pkgutil.walk_packages(
|
||||
path=package.__path__, prefix=prefix, onerror=lambda _: None
|
||||
):
|
||||
try:
|
||||
module = importlib.import_module(modname)
|
||||
except Exception as e:
|
||||
self.logger.debug('Could not import module %s: %s', modname, e)
|
||||
continue
|
||||
|
||||
for _, obj in inspect.getmembers(module):
|
||||
if type(obj) == Event: # pylint: disable=unidiomatic-typecheck
|
||||
continue
|
||||
|
||||
if inspect.isclass(obj) and issubclass(obj, Event) and obj != Event:
|
||||
event = EventModel(
|
||||
event=obj, html_doc=self._html_doc, prefix=prefix
|
||||
)
|
||||
if event.package not in self._events:
|
||||
self._events[event.package] = {event.name: event}
|
||||
else:
|
||||
self._events[event.package][event.name] = event
|
||||
|
||||
def _init_responses(self):
|
||||
"""
|
||||
Initializes and caches all the available responses.
|
||||
"""
|
||||
self._init_modules(
|
||||
base_type=Response,
|
||||
model_type=ResponseModel,
|
||||
)
|
||||
package = platypush.message.response
|
||||
prefix = package.__name__ + '.'
|
||||
|
||||
def _init_components(self, base_type: type, initializer: Callable[[], None]):
|
||||
"""
|
||||
Context manager boilerplate for the other ``_init_*`` methods.
|
||||
"""
|
||||
ctx = self._components_context[base_type]
|
||||
with ctx.init_lock:
|
||||
if not ctx.refreshed.is_set():
|
||||
initializer()
|
||||
ctx.refreshed.set()
|
||||
for _, modname, _ in pkgutil.walk_packages(
|
||||
path=package.__path__, prefix=prefix, onerror=lambda _: None
|
||||
):
|
||||
try:
|
||||
module = importlib.import_module(modname)
|
||||
except Exception as e:
|
||||
self.logger.debug('Could not import module %s: %s', modname, e)
|
||||
continue
|
||||
|
||||
for _, obj in inspect.getmembers(module):
|
||||
if type(obj) == Response: # pylint: disable=unidiomatic-typecheck
|
||||
continue
|
||||
|
||||
if (
|
||||
inspect.isclass(obj)
|
||||
and issubclass(obj, Response)
|
||||
and obj != Response
|
||||
):
|
||||
response = ResponseModel(
|
||||
response=obj, html_doc=self._html_doc, prefix=prefix
|
||||
)
|
||||
if response.package not in self._responses:
|
||||
self._responses[response.package] = {response.name: response}
|
||||
else:
|
||||
self._responses[response.package][response.name] = response
|
||||
|
||||
@action
|
||||
def get_all_plugins(self):
|
||||
def get_all_plugins(self, html_doc: Optional[bool] = None):
|
||||
"""
|
||||
Get information about all the available plugins.
|
||||
:param html_doc: If True then the docstring will be parsed into HTML (default: False)
|
||||
"""
|
||||
self._init_components(Plugin, self._init_plugins)
|
||||
return json.dumps(
|
||||
{
|
||||
get_plugin_name_by_class(cls): dict(plugin)
|
||||
for cls, plugin in self._components_cache.get(Plugin, {}).items()
|
||||
}
|
||||
)
|
||||
with self._plugins_lock:
|
||||
if not self._plugins or (
|
||||
html_doc is not None and html_doc != self._html_doc
|
||||
):
|
||||
self._html_doc = html_doc
|
||||
self._init_plugins()
|
||||
|
||||
return json.dumps(
|
||||
{name: dict(plugin) for name, plugin in self._plugins.items()}
|
||||
)
|
||||
|
||||
@action
|
||||
def get_all_backends(self):
|
||||
def get_all_backends(self, html_doc: Optional[bool] = None):
|
||||
"""
|
||||
Get information about all the available backends.
|
||||
:param html_doc: If True then the docstring will be parsed into HTML (default: False)
|
||||
"""
|
||||
self._init_components(Backend, self._init_backends)
|
||||
return json.dumps(
|
||||
{
|
||||
get_backend_name_by_class(cls): dict(backend)
|
||||
for cls, backend in self._components_cache.get(Backend, {}).items()
|
||||
}
|
||||
)
|
||||
with self._backends_lock:
|
||||
if not self._backends or (
|
||||
html_doc is not None and html_doc != self._html_doc
|
||||
):
|
||||
self._html_doc = html_doc
|
||||
self._init_backends()
|
||||
|
||||
return json.dumps(
|
||||
{name: dict(backend) for name, backend in self._backends.items()}
|
||||
)
|
||||
|
||||
@action
|
||||
def get_all_events(self):
|
||||
def get_all_events(self, html_doc: Optional[bool] = None):
|
||||
"""
|
||||
Get information about all the available events.
|
||||
:param html_doc: If True then the docstring will be parsed into HTML (default: False)
|
||||
"""
|
||||
self._init_components(Event, self._init_events)
|
||||
return json.dumps(
|
||||
{
|
||||
package: {
|
||||
obj_type.__name__: dict(event_model)
|
||||
for obj_type, event_model in events.items()
|
||||
with self._events_lock:
|
||||
if not self._events or (
|
||||
html_doc is not None and html_doc != self._html_doc
|
||||
):
|
||||
self._html_doc = html_doc
|
||||
self._init_events()
|
||||
|
||||
return json.dumps(
|
||||
{
|
||||
package: {name: dict(event) for name, event in events.items()}
|
||||
for package, events in self._events.items()
|
||||
}
|
||||
for package, events in self._components_cache.get(Event, {}).items()
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@action
|
||||
def get_all_responses(self):
|
||||
def get_all_responses(self, html_doc: Optional[bool] = None):
|
||||
"""
|
||||
Get information about all the available responses.
|
||||
:param html_doc: If True then the docstring will be parsed into HTML (default: False)
|
||||
"""
|
||||
self._init_components(Response, self._init_responses)
|
||||
return json.dumps(
|
||||
{
|
||||
package: {
|
||||
obj_type.__name__: dict(response_model)
|
||||
for obj_type, response_model in responses.items()
|
||||
with self._responses_lock:
|
||||
if not self._responses or (
|
||||
html_doc is not None and html_doc != self._html_doc
|
||||
):
|
||||
self._html_doc = html_doc
|
||||
self._init_responses()
|
||||
|
||||
return json.dumps(
|
||||
{
|
||||
package: {name: dict(event) for name, event in responses.items()}
|
||||
for package, responses in self._responses.items()
|
||||
}
|
||||
for package, responses in self._components_cache.get(
|
||||
Response, {}
|
||||
).items()
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@action
|
||||
def get_procedures(self) -> dict:
|
||||
|
@ -379,7 +228,8 @@ class InspectPlugin(Plugin):
|
|||
if entry:
|
||||
return Config.get(entry)
|
||||
|
||||
return Config.get()
|
||||
cfg = Config.get()
|
||||
return cfg
|
||||
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
from dataclasses import dataclass, field
|
||||
import threading
|
||||
|
||||
|
||||
@dataclass
|
||||
class ComponentContext:
|
||||
"""
|
||||
This class is used to store the context of a component type.
|
||||
"""
|
||||
|
||||
init_lock: threading.RLock = field(default_factory=threading.RLock)
|
||||
refreshed: threading.Event = field(default_factory=threading.Event)
|
|
@ -1,131 +1,123 @@
|
|||
from abc import ABC, abstractmethod
|
||||
import inspect
|
||||
import json
|
||||
import re
|
||||
from typing import Optional, Type
|
||||
from typing import Optional
|
||||
|
||||
from platypush.backend import Backend
|
||||
from platypush.message.event import Event
|
||||
from platypush.message.response import Response
|
||||
from platypush.plugins import Plugin
|
||||
from platypush.utils import get_decorators
|
||||
|
||||
|
||||
class Model:
|
||||
"""
|
||||
Base class for component models.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
obj_type: type,
|
||||
name: Optional[str] = None,
|
||||
doc: Optional[str] = None,
|
||||
prefix: str = '',
|
||||
last_modified: Optional[float] = None,
|
||||
) -> None:
|
||||
"""
|
||||
:param obj_type: Type of the component.
|
||||
:param name: Name of the component.
|
||||
:param doc: Documentation of the component.
|
||||
:param last_modified: Last modified timestamp of the component.
|
||||
"""
|
||||
self._obj_type = obj_type
|
||||
self.package = obj_type.__module__[len(prefix) :]
|
||||
self.name = name or self.package
|
||||
self.doc = doc or obj_type.__doc__
|
||||
self.last_modified = last_modified
|
||||
|
||||
class Model(ABC):
|
||||
def __str__(self):
|
||||
"""
|
||||
:return: JSON string representation of the model.
|
||||
"""
|
||||
return json.dumps(dict(self), indent=2, sort_keys=True)
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
:return: JSON string representation of the model.
|
||||
"""
|
||||
return json.dumps(dict(self))
|
||||
|
||||
@staticmethod
|
||||
def to_html(doc):
|
||||
try:
|
||||
import docutils.core # type: ignore
|
||||
except ImportError:
|
||||
# docutils not found
|
||||
return doc
|
||||
|
||||
return docutils.core.publish_parts(doc, writer_name='html')['html_body']
|
||||
|
||||
@abstractmethod
|
||||
def __iter__(self):
|
||||
"""
|
||||
Iterator for the model public attributes/values pairs.
|
||||
"""
|
||||
for attr in ['name', 'doc']:
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class ProcedureEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if callable(o):
|
||||
return {
|
||||
'type': 'native_function',
|
||||
}
|
||||
|
||||
return super().default(o)
|
||||
|
||||
|
||||
class BackendModel(Model):
|
||||
def __init__(self, backend, prefix='', html_doc: Optional[bool] = False):
|
||||
self.name = backend.__module__[len(prefix) :]
|
||||
self.html_doc = html_doc
|
||||
self.doc = (
|
||||
self.to_html(backend.__doc__)
|
||||
if html_doc and backend.__doc__
|
||||
else backend.__doc__
|
||||
)
|
||||
|
||||
def __iter__(self):
|
||||
for attr in ['name', 'doc', 'html_doc']:
|
||||
yield attr, getattr(self, attr)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class BackendModel(Model):
|
||||
"""
|
||||
Model for backend components.
|
||||
"""
|
||||
|
||||
def __init__(self, obj_type: Type[Backend], *args, **kwargs):
|
||||
super().__init__(obj_type, *args, **kwargs)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class PluginModel(Model):
|
||||
"""
|
||||
Model for plugin components.
|
||||
"""
|
||||
|
||||
def __init__(self, obj_type: Type[Plugin], prefix: str = '', **kwargs):
|
||||
super().__init__(
|
||||
obj_type,
|
||||
name=re.sub(r'\._plugin$', '', obj_type.__module__[len(prefix) :]),
|
||||
**kwargs,
|
||||
def __init__(self, plugin, prefix='', html_doc: Optional[bool] = False):
|
||||
self.name = plugin.__module__[len(prefix) :]
|
||||
self.html_doc = html_doc
|
||||
self.doc = (
|
||||
self.to_html(plugin.__doc__)
|
||||
if html_doc and plugin.__doc__
|
||||
else plugin.__doc__
|
||||
)
|
||||
|
||||
self.actions = {
|
||||
action_name: ActionModel(getattr(obj_type, action_name))
|
||||
for action_name in get_decorators(obj_type, climb_class_hierarchy=True).get(
|
||||
action_name: ActionModel(
|
||||
getattr(plugin, action_name), html_doc=html_doc or False
|
||||
)
|
||||
for action_name in get_decorators(plugin, climb_class_hierarchy=True).get(
|
||||
'action', []
|
||||
)
|
||||
}
|
||||
|
||||
def __iter__(self):
|
||||
"""
|
||||
Overrides the default implementation of ``__iter__`` to also include
|
||||
plugin actions.
|
||||
"""
|
||||
for attr in ['name', 'actions', 'doc']:
|
||||
for attr in ['name', 'actions', 'doc', 'html_doc']:
|
||||
if attr == 'actions':
|
||||
# noinspection PyShadowingNames
|
||||
yield attr, {
|
||||
name: dict(action) for name, action in self.actions.items()
|
||||
}
|
||||
},
|
||||
else:
|
||||
yield attr, getattr(self, attr)
|
||||
|
||||
|
||||
class EventModel(Model):
|
||||
"""
|
||||
Model for event components.
|
||||
"""
|
||||
def __init__(self, event, prefix='', html_doc: Optional[bool] = False):
|
||||
self.package = event.__module__[len(prefix) :]
|
||||
self.name = event.__name__
|
||||
self.html_doc = html_doc
|
||||
self.doc = (
|
||||
self.to_html(event.__doc__) if html_doc and event.__doc__ else event.__doc__
|
||||
)
|
||||
|
||||
def __init__(self, obj_type: Type[Event], **kwargs):
|
||||
super().__init__(obj_type, **kwargs)
|
||||
def __iter__(self):
|
||||
for attr in ['name', 'doc', 'html_doc']:
|
||||
yield attr, getattr(self, attr)
|
||||
|
||||
|
||||
class ResponseModel(Model):
|
||||
"""
|
||||
Model for response components.
|
||||
"""
|
||||
def __init__(self, response, prefix='', html_doc: Optional[bool] = False):
|
||||
self.package = response.__module__[len(prefix) :]
|
||||
self.name = response.__name__
|
||||
self.html_doc = html_doc
|
||||
self.doc = (
|
||||
self.to_html(response.__doc__)
|
||||
if html_doc and response.__doc__
|
||||
else response.__doc__
|
||||
)
|
||||
|
||||
def __init__(self, obj_type: Type[Response], **kwargs):
|
||||
super().__init__(obj_type, **kwargs)
|
||||
def __iter__(self):
|
||||
for attr in ['name', 'doc', 'html_doc']:
|
||||
yield attr, getattr(self, attr)
|
||||
|
||||
|
||||
class ActionModel(Model):
|
||||
"""
|
||||
Model for plugin action components.
|
||||
"""
|
||||
|
||||
def __init__(self, action, **kwargs):
|
||||
doc, argsdoc = self._parse_docstring(action.__doc__)
|
||||
super().__init__(action, name=action.__name__, doc=doc, **kwargs)
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def __init__(self, action, html_doc: bool = False):
|
||||
self.name = action.__name__
|
||||
self.doc, argsdoc = self._parse_docstring(action.__doc__, html_doc=html_doc)
|
||||
self.args = {}
|
||||
self.has_kwargs = False
|
||||
|
||||
|
@ -142,7 +134,7 @@ class ActionModel(Model):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def _parse_docstring(cls, docstring: str):
|
||||
def _parse_docstring(cls, docstring: str, html_doc: bool = False):
|
||||
new_docstring = ''
|
||||
params = {}
|
||||
cur_param = None
|
||||
|
@ -155,7 +147,11 @@ class ActionModel(Model):
|
|||
m = re.match(r'^\s*:param ([^:]+):\s*(.*)', line)
|
||||
if m:
|
||||
if cur_param:
|
||||
params[cur_param] = cur_param_docstring
|
||||
params[cur_param] = (
|
||||
cls.to_html(cur_param_docstring)
|
||||
if html_doc
|
||||
else cur_param_docstring
|
||||
)
|
||||
|
||||
cur_param = m.group(1)
|
||||
cur_param_docstring = m.group(2)
|
||||
|
@ -164,7 +160,11 @@ class ActionModel(Model):
|
|||
else:
|
||||
if cur_param:
|
||||
if not line.strip():
|
||||
params[cur_param] = cur_param_docstring
|
||||
params[cur_param] = (
|
||||
cls.to_html(cur_param_docstring)
|
||||
if html_doc
|
||||
else cur_param_docstring
|
||||
)
|
||||
cur_param = None
|
||||
cur_param_docstring = ''
|
||||
else:
|
||||
|
@ -173,9 +173,14 @@ class ActionModel(Model):
|
|||
new_docstring += line.rstrip() + '\n'
|
||||
|
||||
if cur_param:
|
||||
params[cur_param] = cur_param_docstring
|
||||
params[cur_param] = (
|
||||
cls.to_html(cur_param_docstring) if html_doc else cur_param_docstring
|
||||
)
|
||||
|
||||
return new_docstring.strip(), params
|
||||
return (
|
||||
new_docstring.strip() if not html_doc else cls.to_html(new_docstring),
|
||||
params,
|
||||
)
|
||||
|
||||
def __iter__(self):
|
||||
for attr in ['name', 'args', 'doc', 'has_kwargs']:
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
import inspect
|
||||
import json
|
||||
|
||||
|
||||
class ProcedureEncoder(json.JSONEncoder):
|
||||
"""
|
||||
Encoder for the Procedure model.
|
||||
"""
|
||||
|
||||
def default(self, o):
|
||||
if callable(o):
|
||||
return {
|
||||
'type': 'native_function',
|
||||
'module': o.__module__,
|
||||
'source': inspect.getsourcefile(o),
|
||||
'args': [
|
||||
name
|
||||
for name, arg in inspect.signature(o).parameters.items()
|
||||
if arg.kind != arg.VAR_KEYWORD
|
||||
],
|
||||
}
|
||||
|
||||
return super().default(o)
|
|
@ -344,24 +344,5 @@ class UtilsPlugin(Plugin):
|
|||
|
||||
return plugins
|
||||
|
||||
@action
|
||||
def rst_to_html(self, text: str):
|
||||
"""
|
||||
Utility action to convert RST to HTML.
|
||||
|
||||
It is mostly used by the frontend to render the docstring of the
|
||||
available plugins and actions.
|
||||
"""
|
||||
try:
|
||||
import docutils.core # type: ignore
|
||||
except ImportError:
|
||||
self.logger.warning(
|
||||
"docutils is not installed. "
|
||||
"Please install docutils to convert RST to HTML."
|
||||
)
|
||||
return text
|
||||
|
||||
return docutils.core.publish_parts(text, writer_name='html')['html_body']
|
||||
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
|
|
@ -73,17 +73,6 @@ def get_plugin_module_by_name(plugin_name):
|
|||
return None
|
||||
|
||||
|
||||
def get_backend_module_by_name(backend_name):
|
||||
"""Gets the module of a backend by name (e.g. "backend.http" or "backend.mqtt")"""
|
||||
|
||||
module_name = 'platypush.backend.' + backend_name
|
||||
try:
|
||||
return importlib.import_module('platypush.backend.' + backend_name)
|
||||
except ImportError as e:
|
||||
logger.error('Cannot import %s: %s', module_name, e)
|
||||
return None
|
||||
|
||||
|
||||
def get_plugin_class_by_name(plugin_name):
|
||||
"""Gets the class of a plugin by name (e.g. "music.mpd" or "media.vlc")"""
|
||||
|
||||
|
@ -121,34 +110,6 @@ def get_plugin_name_by_class(plugin) -> Optional[str]:
|
|||
return '.'.join(class_tokens)
|
||||
|
||||
|
||||
def get_backend_class_by_name(backend_name: str):
|
||||
"""Gets the class of a backend by name (e.g. "backend.http" or "backend.mqtt")"""
|
||||
|
||||
module = get_backend_module_by_name(backend_name)
|
||||
if not module:
|
||||
return
|
||||
|
||||
class_name = getattr(
|
||||
module,
|
||||
''.join(
|
||||
[
|
||||
token.capitalize()
|
||||
for i, token in enumerate(backend_name.split('.'))
|
||||
if not (i == 0 and token == 'backend')
|
||||
]
|
||||
)
|
||||
+ 'Backend',
|
||||
)
|
||||
try:
|
||||
return getattr(
|
||||
module,
|
||||
''.join([_.capitalize() for _ in backend_name.split('.')]) + 'Backend',
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error('Cannot import class %s: %s', class_name, e)
|
||||
return None
|
||||
|
||||
|
||||
def get_backend_name_by_class(backend) -> Optional[str]:
|
||||
"""Gets the common name of a backend (e.g. "http" or "mqtt") given its class."""
|
||||
|
||||
|
|