Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CCS
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Mecina
CCS
Commits
2c5d128f
Commit
2c5d128f
authored
2 years ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
minor code cleanup
parent
57e8281e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Ccs/DBus_Basic.py
+14
-19
14 additions, 19 deletions
Ccs/DBus_Basic.py
with
14 additions
and
19 deletions
Ccs/DBus_Basic.py
+
14
−
19
View file @
2c5d128f
#This file is used to set up a D-Bus
#
This file is used to set up a D-Bus
import
dbus
import
dbus
import
dbus.service
import
dbus.service
import
sys
import
subprocess
#import confignator
import
ccs_function_lib
as
cfl
import
ccs_function_lib
as
cfl
import
os
import
os
# Set up two Methodes to excess over a given dbus name
#Set up two Methodes to excess over a given dbus name
class
MessageListener
(
dbus
.
service
.
Object
):
class
MessageListener
(
dbus
.
service
.
Object
):
def
__init__
(
self
,
win
,
Bus_Name
,
*
args
):
def
__init__
(
self
,
win
,
Bus_Name
,
*
args
):
project
=
None
project
=
None
...
@@ -23,7 +19,7 @@ class MessageListener(dbus.service.Object):
...
@@ -23,7 +19,7 @@ class MessageListener(dbus.service.Object):
Bus_Name
+=
str
(
1
)
Bus_Name
+=
str
(
1
)
#Check if the Bus name already exists and increase the number if it does
#
Check if the Bus name already exists and increase the number if it does
counting
=
1
counting
=
1
check
=
True
check
=
True
while
check
==
True
:
while
check
==
True
:
...
@@ -36,7 +32,7 @@ class MessageListener(dbus.service.Object):
...
@@ -36,7 +32,7 @@ class MessageListener(dbus.service.Object):
else
:
else
:
check
=
False
check
=
False
#Set up the bus
#
Set up the bus
self
.
Bus_Name
=
Bus_Name
self
.
Bus_Name
=
Bus_Name
self
.
name
=
dbus
.
service
.
BusName
(
self
.
Bus_Name
,
bus
=
self
.
bus
)
self
.
name
=
dbus
.
service
.
BusName
(
self
.
Bus_Name
,
bus
=
self
.
bus
)
super
().
__init__
(
self
.
name
,
'
/MessageListener
'
)
super
().
__init__
(
self
.
name
,
'
/MessageListener
'
)
...
@@ -47,14 +43,14 @@ class MessageListener(dbus.service.Object):
...
@@ -47,14 +43,14 @@ class MessageListener(dbus.service.Object):
if
not
project
:
if
not
project
:
project
=
self
.
win
.
cfg
[
'
ccs-database
'
][
'
project
'
]
project
=
self
.
win
.
cfg
[
'
ccs-database
'
][
'
project
'
]
self
.
win
.
main_instance
=
project
# Variable in each application to tell the group name
self
.
win
.
main_instance
=
project
# Variable in each application to tell the group name
# This exception is necessary for the Poolmanager since most of the time a GUI does not exist
# This exception is necessary for the Poolmanager since most of the time a GUI does not exist
try
:
try
:
self
.
win
.
set_title
(
str
(
project
)
+
'
:
'
+
str
(
self
.
win
.
get_title
())
+
'
'
+
str
(
counting
-
1
))
self
.
win
.
set_title
(
str
(
project
)
+
'
:
'
+
str
(
self
.
win
.
get_title
())
+
'
'
+
str
(
counting
-
1
))
except
:
except
:
# Looks like a odd title name but is reshaped in pus_datapool.py
# Looks like a odd title name but is reshaped in pus_datapool.py
self
.
win
.
windowname
=
str
(
project
)
+
'
: @
'
+
str
(
counting
-
1
)
self
.
win
.
windowname
=
str
(
project
)
+
'
: @
'
+
str
(
counting
-
1
)
###
###
# Tell the terminal that a bus has been set up, this function has to exist in every file
# Tell the terminal that a bus has been set up, this function has to exist in every file
...
@@ -64,7 +60,7 @@ class MessageListener(dbus.service.Object):
...
@@ -64,7 +60,7 @@ class MessageListener(dbus.service.Object):
import
log_server
import
log_server
log_server_path
=
log_server
.
__file__
log_server_path
=
log_server
.
__file__
os
.
system
(
'
nohup python3
'
+
str
(
log_server_path
)
+
'
>/dev/null 2>&1 &
'
)
os
.
system
(
'
nohup python3
'
+
str
(
log_server_path
)
+
'
>/dev/null 2>&1 &
'
)
#subprocess.Popen(['python3', log_server_path])
#
subprocess.Popen(['python3', log_server_path])
# Return all available methods
# Return all available methods
@dbus.service.method
(
'
com.communication.interface
'
)
@dbus.service.method
(
'
com.communication.interface
'
)
...
@@ -100,7 +96,7 @@ class MessageListener(dbus.service.Object):
...
@@ -100,7 +96,7 @@ class MessageListener(dbus.service.Object):
print
(
argument
)
print
(
argument
)
return
return
#This makes one use all function given in the used file for the given instance (win variable in __init__ function)
#
This makes one use all function given in the used file for the given instance (win variable in __init__ function)
@dbus.service.method
(
'
com.communication.interface
'
,
byte_arrays
=
True
)
@dbus.service.method
(
'
com.communication.interface
'
,
byte_arrays
=
True
)
def
Functions
(
self
,
function_name
,
*
args
):
def
Functions
(
self
,
function_name
,
*
args
):
...
@@ -183,10 +179,10 @@ class MessageListener(dbus.service.Object):
...
@@ -183,10 +179,10 @@ class MessageListener(dbus.service.Object):
else
:
else
:
count
=
0
count
=
0
try
:
try
:
if
len
(
args
)
%
2
!=
0
:
if
len
(
args
)
%
2
!=
0
:
raise
KeyError
raise
KeyError
while
count
<
len
(
args
):
while
count
<
len
(
args
):
dict_to_call
[
args
[
count
]]
=
args
[
count
+
1
]
dict_to_call
[
args
[
count
]]
=
args
[
count
+
1
]
count
+=
2
count
+=
2
except
:
except
:
print
(
'
Please give a valid number of arguments
'
)
print
(
'
Please give a valid number of arguments
'
)
...
@@ -241,10 +237,9 @@ class MessageListener(dbus.service.Object):
...
@@ -241,10 +237,9 @@ class MessageListener(dbus.service.Object):
if
arg
.
get
(
'
kwargs
'
):
if
arg
.
get
(
'
kwargs
'
):
kwargs
=
arg
[
'
kwargs
'
]
kwargs
=
arg
[
'
kwargs
'
]
del
arg
[
'
kwargs
'
]
del
arg
[
'
kwargs
'
]
#kwargs = arg
#
kwargs = arg
args
.
remove
(
arg
)
args
.
remove
(
arg
)
'''
'''
breaklist = list(arguments)
breaklist = list(arguments)
for arg in arguments:
for arg in arguments:
...
@@ -278,7 +273,7 @@ class MessageListener(dbus.service.Object):
...
@@ -278,7 +273,7 @@ class MessageListener(dbus.service.Object):
arguments
=
tuple
(
args
)
arguments
=
tuple
(
args
)
return
arguments
,
kwargs
return
arguments
,
kwargs
def
dbus_to_python
(
self
,
data
,
user_console
=
False
):
def
dbus_to_python
(
self
,
data
,
user_console
=
False
):
"""
"""
Convets dbus Types to Python Types
Convets dbus Types to Python Types
@param data: Dbus Type variables or containers
@param data: Dbus Type variables or containers
...
@@ -384,4 +379,4 @@ class MessageListenerpy(object):
...
@@ -384,4 +379,4 @@ class MessageListenerpy(object):
else:
else:
return connectivity
return connectivity
'''
'''
\ 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