Skip to content
Snippets Groups Projects
Commit 2c5d128f authored by Marko Mecina's avatar Marko Mecina
Browse files

minor code cleanup

parent 57e8281e
Branches
No related tags found
No related merge requests found
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment