added issue #17, #19 and #20

Josef Dabrowski 6 years ago
parent 59730b4cec
commit 6fd4f84bc5

@ -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

@ -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

@ -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))
@ -20,14 +29,66 @@ class Manager():
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
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

@ -1 +1 @@
from notiframe import Notiframe

@ -1 +1,7 @@
[[devices]]
name = "test"
resolution = [ 1, 2,]
device_id = "e79e6f13-60a8-4dd9-b7ba-665a0939f9f5"
widgets = []
"<_jam>" = "Device"

@ -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',
)

@ -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'
Loading…
Cancel
Save