Commit a99ed4bf authored by Karl Fleischmann's avatar Karl Fleischmann

Fix few bugs

* Register routines as class-methods
* Register few variables as data_interface-friends
* Indent few lines to work correctly (abfack-indentation introduced on
  outsourcing main-loop)
parent b7cede54
......@@ -41,7 +41,7 @@ class Main(object):
self.user_left_list = None
self.user_new_list = None
def caching_routine():
def caching_routine(self):
""""""
#######################################################################
......@@ -55,26 +55,26 @@ class Main(object):
open(hc_head.CACHE_PATH, 'a').close()
cached_data_dict = {
"device_count": 0,
"users": users
"users": self.data_interface.users
}
#compare saved and fetched value
if (self.args.show_user and
cached_data_dict['device_count'] != device_count):
cached_data_dict['device_count'] != self.data_interface.device_count):
self.header.count_changed = True
#diff saved and new recieved list
user_diff_fetched = list(
itertools.filterfalse(lambda x: x in cached_data_dict['users'],
users))
self.data_interface.users))
user_diff_saved = list(
itertools.filterfalse(lambda x: x in users,
itertools.filterfalse(lambda x: x in self.data_interface.users,
cached_data_dict['users']))
#####prepare to save value
save_cache_dict = {
"device_count": device_count,
"users": users
"device_count": self.data_interface.device_count,
"users": self.data_interface.users
}
if len(user_diff_fetched) > 0:
......@@ -94,31 +94,31 @@ class Main(object):
# end of fetch-routine
#######################################################################
def printing_routine():
def printing_routine(self):
""""""
#######################################################################
# printing routine
## print count
if self.args.printing:
if not self.args.show_user:
print("HackHro Users: {} ".format(len(users)))
if self.args.show_user:
print("HackHro Users: {} ".format(len(self.data_interface.users)))
if self.user_left_list is not None:
print("Users left: ", flush=True, end="")
for user in user_left_list:
print(user['name'] + " ", flush=True)
if self.user_left_list is not None:
print("Users left: ", flush=True, end="")
for user in user_left_list:
print(user['name'] + " ", flush=True)
if self.user_new_list is not None:
print("Users new: ", flush=True, end="")
for user in user_new_list:
print(user['name'] + " ", end="", flush=True)
if self.user_new_list is not None:
print("Users new: ", flush=True, end="")
for user in user_new_list:
print(user['name'] + " ", end="", flush=True)
else:
print("HackHro Devcies: ", device_count, flush=True)
print("HackHro Devcies: ", self.data_interface.device_count, flush=True)
# end of printing routine
#######################################################################
def notification_routine():
def notification_routine(self):
""""""
#######################################################################
......@@ -214,7 +214,7 @@ class Main(object):
exit(1)
# for each user logged in
for user in data_interface.users:
for user in self.data_interface.users:
# create a path of its avatar
user_image_path = os.path.join(hc_head.CACHE_PICTURE_FOLDER,
str(user['id']) + ".jpg")
......@@ -228,15 +228,15 @@ class Main(object):
user_image_path)
# fetch data from cache/write data into cache
caching_routine()
self.caching_routine()
# print user/device infos
printing_routine()
self.printing_routine()
# notify user/device infos
notification_routine()
self.notification_routine()
# break/continue loop depending on daemonize-value
if not self.args.daemonize:
sys.exit(0)
sleep(self.args.interval)
\ No newline at end of file
sleep(self.args.interval)
Markdown is supported
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