Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
anselm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vaclab
anselm
Commits
50b35d58
Commit
50b35d58
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
next attempt pubsub.listen in QtThread...
parent
3b89503d
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
anselm.py
+38
-14
38 additions, 14 deletions
anselm.py
anselm/db.py
+1
-1
1 addition, 1 deletion
anselm/db.py
anselm/system.py
+6
-2
6 additions, 2 deletions
anselm/system.py
anselm/worker.py
+23
-10
23 additions, 10 deletions
anselm/worker.py
with
68 additions
and
27 deletions
anselm.py
+
38
−
14
View file @
50b35d58
import
sys
import
json
import
argparse
from
threading
import
Thread
from
anselm.system
import
System
# pylint: disable=E0611
from
anselm.db
import
DB
# pylint: disable=E0611
from
anselm.worker
import
Worker
# pylint: disable=E0611
from
PyQt5.QtWidgets
import
QWidget
,
QDesktopWidget
,
QApplication
,
QPushButton
,
QComboBox
,
QGridLayout
,
QLabel
from
PyQt5.QtCore
import
QThread
,
pyqtSignal
import
sys
class
Observe
(
QThread
,
System
):
signal
=
pyqtSignal
(
'
PyQt_PyObject
'
)
def
__init__
(
self
):
QThread
.
__init__
(
self
)
def
run
(
self
):
# git clone done, now inform the main thread with the output
self
.
p
.
subscribe
(
"
io
"
)
print
(
'
Listening redis...
'
)
for
item
in
self
.
p
.
listen
():
self
.
log
.
debug
(
"
received item: {}
"
.
format
(
item
))
self
.
signal
.
emit
(
"
kkkkkkk
"
)
class
Anselm
(
System
):
def
__init__
(
self
):
super
().
__init__
()
self
.
db
=
DB
()
self
.
worker
=
Worker
()
self
.
observer_thread
=
Observe
()
self
.
observer_thread
.
signal
.
connect
(
self
.
end_task
)
self
.
observer_thread
.
start
()
self
.
current_grid_line
=
1
self
.
initUI
()
def
initUI
(
self
):
self
.
win
=
QWidget
()
self
.
win
.
resize
(
250
,
150
)
self
.
win
.
setWindowTitle
(
'
Anselm
'
)
self
.
grid
=
QGridLayout
()
add_device_bttn
=
QPushButton
(
"
add device
"
,
self
.
win
)
...
...
@@ -35,8 +57,18 @@ class Anselm(System):
self
.
add_widget_to_grid
(
std_select_combo
,
1
,
1
)
self
.
add_widget_to_grid
(
add_device_bttn
,
1
,
2
)
std_select_combo
.
currentIndexChanged
.
connect
(
lambda
:
self
.
std_selected
(
std_select_combo
))
self
.
draw_grid
()
self
.
draw_grid
()
def
run_task
(
self
,
line
):
self
.
log
.
info
(
"
try to start device at line {}
"
.
format
(
line
))
self
.
worker
.
work_on_line
=
line
self
.
worker
.
run
()
def
end_task
(
self
,
line
):
self
.
log
.
info
(
"
end task at line {}
"
.
format
(
line
))
def
add_device_line
(
self
):
self
.
current_grid_line
+=
1
line
=
self
.
current_grid_line
...
...
@@ -56,7 +88,7 @@ class Anselm(System):
def
make_run_bttn
(
self
,
line
):
run_device_bttn
=
QPushButton
(
"
run
"
,
self
.
win
)
run_device_bttn
.
clicked
.
connect
(
lambda
:
self
.
run_
device
(
line
))
run_device_bttn
.
clicked
.
connect
(
lambda
:
self
.
run_
task
(
line
))
return
run_device_bttn
...
...
@@ -149,14 +181,7 @@ class Anselm(System):
for
item
in
item_list
:
combo
.
addItem
(
item
)
return
combo
def
run_device
(
self
,
line
):
self
.
log
.
info
(
"
try to start device at line {}
"
.
format
(
line
))
task
=
self
.
dget
(
'
task
'
,
line
)
if
task
:
self
.
log
.
debug
(
"
task is: {}
"
.
format
(
task
))
Thread
(
target
=
self
.
worker
.
run
,
args
=
(
task
,
line
,)).
start
()
def
std_selected
(
self
,
combo
):
standard
=
combo
.
currentText
()
...
...
@@ -167,6 +192,5 @@ if __name__ == '__main__':
app
=
QApplication
(
sys
.
argv
)
ex
=
Anselm
()
sys
.
exit
(
Thread
(
target
=
ex
.
run
).
start
())
sys
.
exit
(
app
.
exec_
())
This diff is collapsed.
Click to expand it.
anselm/db.py
+
1
−
1
View file @
50b35d58
...
...
@@ -20,7 +20,7 @@ class DB(System):
self
.
db_dict
=
db_dict
self
.
db_srv
=
couchdb
.
Server
(
url
)
self
.
db
=
self
.
db_srv
[
self
.
db_dict
[
'
database
'
]]
self
.
log
.
info
(
"
long-term memory system
ok
"
)
self
.
log
.
info
(
"
database
ok
"
)
def
store_doc
(
self
,
doc
):
id
=
doc
.
get
(
'
_id
'
)
...
...
This diff is collapsed.
Click to expand it.
anselm/system.py
+
6
−
2
View file @
50b35d58
...
...
@@ -13,7 +13,7 @@ class System:
max_arg_len
=
40
log_fmt
=
'
%(asctime)s,%(msecs)03d %(hostname)s %(filename)s:%(lineno)s %(levelname)s %(message)s
'
log_level
=
"
DEBUG
"
state
=
{}
def
__init__
(
self
):
"""
Gets the configuration out of the file: ``config.json``.
...
...
@@ -40,9 +40,12 @@ class System:
host
=
db_dict
.
get
(
'
host
'
)
db
=
db_dict
.
get
(
'
db
'
)
self
.
r
=
redis
.
StrictRedis
(
host
=
host
,
port
=
port
,
db
=
db
)
self
.
r
=
redis
.
StrictRedis
(
host
=
host
,
port
=
port
,
db
=
db
)
self
.
log
.
info
(
"
key value store ok
"
)
self
.
p
=
self
.
r
.
pubsub
()
self
.
log
.
info
(
"
pubsub ok
"
)
def
aset
(
self
,
key_prefix
,
line
,
value
):
k
=
'
{}@{}
'
.
format
(
key_prefix
,
line
)
...
...
@@ -63,5 +66,6 @@ class System:
v
=
self
.
aget
(
key_prefix
,
line
)
return
json
.
loads
(
v
)
def
now
(
self
):
return
datetime
.
datetime
.
now
().
isoformat
().
replace
(
'
T
'
,
'
'
)
This diff is collapsed.
Click to expand it.
anselm/worker.py
+
23
−
10
View file @
50b35d58
...
...
@@ -4,8 +4,7 @@ from anselm.system import System
class
Worker
(
System
):
work_on_line
=
None
def
__init__
(
self
):
super
().
__init__
()
relay_dict
=
self
.
config
[
'
relay
'
]
...
...
@@ -14,20 +13,34 @@ class Worker(System):
self
.
headers
=
{
'
content-type
'
:
'
application/json
'
}
def
run
(
self
,
task
,
line
):
acc
=
task
[
'
Action
'
]
def
run
(
self
):
"""
The memeber workomline is set ba anselm
before the thread is start.
"""
if
self
.
work_on_line
:
line
=
self
.
work_on_line
task
=
self
.
dget
(
'
task
'
,
line
)
acc
=
task
[
'
Action
'
]
if
acc
==
"
TCP
"
:
self
.
relay_worker
(
task
,
line
)
if
acc
==
"
VXI11
"
:
self
.
relay_worker
(
task
,
line
)
self
.
work_on_line
=
None
else
:
self
.
log
.
error
(
"
member work_on_line not set
"
)
if
acc
==
"
TCP
"
:
self
.
relay_worker
(
task
,
line
)
if
acc
==
"
VXI11
"
:
self
.
relay_worker
(
task
,
line
)
def
relay_worker
(
self
,
task
,
line
):
req
=
requests
.
post
(
self
.
relay_url
,
data
=
json
.
dumps
(
task
),
headers
=
self
.
headers
)
res
=
req
.
json
()
print
(
res
)
if
'
Result
'
in
res
:
self
.
aset
(
'
result
'
,
line
,
res
[
'
Result
'
])
if
'
ToExchange
'
in
res
:
self
.
aset
(
'
exchange
'
,
line
,
res
[
'
ToExchange
'
])
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment