From 6fd4f84bc5286c02fc4e9403e3ca88aa1e443bd5 Mon Sep 17 00:00:00 2001 From: Josef Date: Tue, 24 Dec 2019 16:07:48 +0800 Subject: [PATCH] added issue #17, #19 and #20 --- Notiframe.egg-info/PKG-INFO | 10 ++ Notiframe.egg-info/SOURCES.txt | 9 ++ Notiframe.egg-info/dependency_links.txt | 1 + Notiframe.egg-info/top_level.txt | 1 + readme.md => README.md | 0 notiframe/Notiframe.py | 155 ++++++++++++------------ notiframe/__init__.py | 2 +- notiframe/config.toml | 8 +- setup.py | 10 +- tests/test_manager.py | 15 +++ 10 files changed, 131 insertions(+), 80 deletions(-) create mode 100644 Notiframe.egg-info/PKG-INFO create mode 100644 Notiframe.egg-info/SOURCES.txt create mode 100644 Notiframe.egg-info/dependency_links.txt create mode 100644 Notiframe.egg-info/top_level.txt rename readme.md => README.md (100%) create mode 100644 tests/test_manager.py diff --git a/Notiframe.egg-info/PKG-INFO b/Notiframe.egg-info/PKG-INFO new file mode 100644 index 0000000..7c1b119 --- /dev/null +++ b/Notiframe.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: Notiframe +Version: 0.1.dev0 +Summary: UNKNOWN +Home-page: https://git.distreon.net/josef/NotiFrame +Author: UNKNOWN +Author-email: UNKNOWN +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN diff --git a/Notiframe.egg-info/SOURCES.txt b/Notiframe.egg-info/SOURCES.txt new file mode 100644 index 0000000..8dcfd84 --- /dev/null +++ b/Notiframe.egg-info/SOURCES.txt @@ -0,0 +1,9 @@ +README.md +setup.py +Notiframe.egg-info/PKG-INFO +Notiframe.egg-info/SOURCES.txt +Notiframe.egg-info/dependency_links.txt +Notiframe.egg-info/top_level.txt +notiframe/Notiframe.py +notiframe/__init__.py +notiframe/test.py \ No newline at end of file diff --git a/Notiframe.egg-info/dependency_links.txt b/Notiframe.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Notiframe.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/Notiframe.egg-info/top_level.txt b/Notiframe.egg-info/top_level.txt new file mode 100644 index 0000000..1258298 --- /dev/null +++ b/Notiframe.egg-info/top_level.txt @@ -0,0 +1 @@ +notiframe diff --git a/readme.md b/README.md similarity index 100% rename from readme.md rename to README.md diff --git a/notiframe/Notiframe.py b/notiframe/Notiframe.py index ba0e1c8..e49bad1 100644 --- a/notiframe/Notiframe.py +++ b/notiframe/Notiframe.py @@ -1,15 +1,24 @@ +#!/usr/bin/env python3 +from collections import namedtuple import uuid -import argparse +import os +import toml +from preserve import preservable, preserve, restore + +mydir = os.path.dirname(os.path.abspath(__file__)) -test_mode = False # Classes # class Manager(): # Manager class to manage a notiframe session. def __init__(self): - self.devices = [] self.manager_id = gen_id() + self.devices = [] + self.config = {} + + self.import_config_file() + self.construct_from_config() def add_device(self, name, resolution): #add parameters for Device class constructor self.devices.append(Device(name, resolution)) @@ -19,15 +28,67 @@ class Manager(): if dev.device_id == dev_id: self.devices.remove(dev) break + + def import_config_file(self): + #get toml config file, convert to named tuple + #return named tuple containing all layouts + try: + config = toml.load(os.path.join(mydir, 'config.toml')) + #config = convert(uni_config) + restored_data = restore(config) + self.config = restored_data + self.devices = self.config['devices'] + except: + return None + + def export_config_file(self): + #take tuple containing all layouts and dump as toml + path = os.path.join(mydir, 'config.toml') + preserved_data = preserve(self.devices) + with open(path, "w+") as config_file: + config_file.write(toml.dumps({'devices': preserved_data})) + + #def update_config(self, new_config_tuple): + # new_device_list = [] + # for dev in devices: + # conf_dev = Conf_device(dev.name, dev.resolution, dev.device_id) + # new_device_list.append(conf_dev) + # +# + # self.export_config_file(new_config_tuple) + # #self.update_layout() update devices layouts that need to be updated + + def update_layout(self, new_layout, device): + device.layout = new_layout + def clear_layout(self, device): + device.layout = {} + + def construct_from_config(self): + try: + for confdev in self.config.devices: + dev = Device(confdev.name, confdev.resolution, confdev.device_id) + #for cwidg in dev.widgets: ###add code to construct widgets as well + self.devices.append(dev) + except: + return None + +@preservable class Device(): # Device class to contain a device's properties, layout and widgets - def __init__(self, name, resolution): + def __init__(self, name, resolution, dev_id=None): + #attributes self.name = name self.resolution = resolution - self.device_id = gen_id() + if(dev_id is None): + self.device_id = gen_id() + else: + self.device_id = dev_id + + #widgets container self.widgets = [] - self.layout = Layout() + + #generated self.device_image = None class Layout(): @@ -35,78 +96,18 @@ class Layout(): def __init__(self): self.layout = {} - def import_file(self): - return None - - def save_to_file(self): - return None - - def update_layout(self, new_layout): - self.layout = new_layout - - def clear_layout(self): - self.layout = {} - -class Test(): - # Test class to test other classes and their functions. - def __init__(self): - #instantiate manager class - self.manager = Manager() - - def test_manager(self): - manager_uuid = self.manager_uuid() - add_device = self.add_device() - device_uuid = self.device_uuid() - remove_device = self.remove_device() - - print("manager id is valid: " + str(manager_uuid)) - print("device id is valid: " + str(device_uuid)) - print("added device: " + str(add_device)) - print("removed device: " + str(remove_device)) - - # Note: Do function wrapper here for tests functions, to say "test_function_name" success/failure - def manager_uuid(self): - uuid_test = self.manager.manager_id - return self.is_valid_uuid(uuid_test) - - def device_uuid(self): - dev = self.manager.devices[0] - uuid_test = dev.device_id - return self.is_valid_uuid(uuid_test) - - # Test if manager class's gen_id function produces a valid uuid - def is_valid_uuid(self, val): - try: - uuid.UUID(str(val)) - return True - except ValueError: - return False - - def add_device(self): - len1 = len(self.manager.devices) - self.manager.add_device("test", (1080, 1920)) - len2 = len(self.manager.devices) - if len2 == len1 + 1: - return True - else: - return False - - def remove_device(self): - id = self.manager.devices[0].device_id - len1 = len(self.manager.devices) - self.manager.remove_device(id) - len2 = len(self.manager.devices) - if len2 == len1 - 1: - return True - else: - return False - # Global Functions # def gen_id(): - return uuid.uuid4() - - -test = Test() -test.test_manager() + return str(uuid.uuid4()) + +def convert(input): + if isinstance(input, dict): + return dict((convert(key), convert(value)) for key, value in input.iteritems()) + elif isinstance(input, list): + return [convert(element) for element in input] + elif isinstance(input, unicode): + return input.encode('utf-8') + else: + return input diff --git a/notiframe/__init__.py b/notiframe/__init__.py index 8d1c8b6..a39fb0a 100644 --- a/notiframe/__init__.py +++ b/notiframe/__init__.py @@ -1 +1 @@ - +from notiframe import Notiframe diff --git a/notiframe/config.toml b/notiframe/config.toml index 8d1c8b6..08fe310 100644 --- a/notiframe/config.toml +++ b/notiframe/config.toml @@ -1 +1,7 @@ - +[[devices]] +name = "test" +resolution = [ 1, 2,] +device_id = "e79e6f13-60a8-4dd9-b7ba-665a0939f9f5" +widgets = [] +"<_jam>" = "Device" + diff --git a/setup.py b/setup.py index 8d1c8b6..2a260e3 100644 --- a/setup.py +++ b/setup.py @@ -1 +1,9 @@ - +from distutils.core import setup + +setup( + name='Notiframe', + version='0.1dev', + packages=['notiframe',], + long_description=open('README.md').read(), + url='https://git.distreon.net/josef/NotiFrame', +) \ No newline at end of file diff --git a/tests/test_manager.py b/tests/test_manager.py new file mode 100644 index 0000000..466ea7a --- /dev/null +++ b/tests/test_manager.py @@ -0,0 +1,15 @@ +from notiframe import Notiframe +import os + +mydir = os.path.dirname(os.path.abspath(__file__)) + +def test_config_dumpload(): + path = os.path.join(mydir, '../notiframe/config.toml') + os.remove(path) + + mgr = Notiframe.Manager() + mgr.add_device('test', [1,2]) + mgr.export_config_file() + + mgr = Notiframe.Manager() + assert mgr.devices[0].name == 'test' \ No newline at end of file