Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from maniotrix/gui
importing/exporting channels
- Loading branch information
Showing
16 changed files
with
229 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
*.pyc | ||
*~ | ||
*.log | ||
*.log* |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"monitor": { | ||
"splitter_addr": "localhost", | ||
"splitter_port": "4552", | ||
"thumbnail_url": "http:/xyz.com", | ||
"name": "monitor", | ||
"description": "monitor" | ||
}, | ||
"monitor1": { | ||
"splitter_addr": "localhost", | ||
"splitter_port": "4552", | ||
"thumbnail_url": "http:/xyz.com", | ||
"name": "monitor", | ||
"description": "monitor" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import json | ||
from common.decorators import exc_handler | ||
|
||
class JSON_Exporter(): | ||
|
||
@exc_handler | ||
def to_JSON(self,path,channels,encoder): | ||
json_file = open(path,"w") | ||
json.dump(channels , json_file, indent = 4 , cls = encoder) | ||
json_file.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import json | ||
from common.decorators import exc_handler | ||
|
||
class JSON_Importer(): | ||
|
||
@exc_handler | ||
def from_JSON(self,path): | ||
json_file = open(path,"r") | ||
data = json.load(json_file) | ||
json_file.close() | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#from collections import defaultdict | ||
class Category(): | ||
|
||
def __init__(self,name): | ||
self.name = name | ||
self.channels = {} | ||
|
||
def get_channels(self): | ||
return self.channels | ||
|
||
def set_name(self,name): | ||
self.name = name | ||
|
||
def get_name(self): | ||
return self.name | ||
|
||
def add(self,key,channel): | ||
self.channels[key] = channel | ||
|
||
def remove(self,key): | ||
del(self.channels[key]) | ||
|
||
def get_channel(self,key): | ||
return self.channels[key] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class Channel(): | ||
|
||
def __init__(self,data): | ||
self.name = data["name"] | ||
self.description = data["description"] | ||
self.thumbnail_url = data["thumbnail_url"] | ||
self.splitter_addr = data["splitter_addr"] | ||
self.splitter_port = data["splitter_port"] | ||
|
||
def set_name(self,name): | ||
self.name = name | ||
|
||
def get_name(self): | ||
return self.name | ||
|
||
def set_thumbnail_url(self,url): | ||
self.thumbnail_url = url | ||
|
||
def get_thumbnail_url(self): | ||
return self.thumbnail_url | ||
|
||
def set_description(self,description): | ||
self.description = description | ||
|
||
def get_description(self): | ||
return self.description | ||
|
||
def set_splitter_addr(self,addr): | ||
self.splitter_addr = addr | ||
|
||
def get_splitter_addr(self): | ||
return self.splitter_addr | ||
|
||
def set_splitter_port(self,port): | ||
self.splitter_port = port | ||
|
||
def get_splitter_port(self): | ||
return self.splitter_port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import json | ||
from channel import Channel | ||
|
||
class Channel_Encoder(json.JSONEncoder): | ||
|
||
def default(self,obj): | ||
if isinstance(obj, Channel): | ||
return obj.__dict__ | ||
else: | ||
return json.JSONEncoder.default(self, obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#script tested with python2.7 | ||
from model.category import Category | ||
from model.channel import Channel | ||
from common.json_importer import JSON_Importer | ||
from common.json_exporter import JSON_Exporter | ||
from model.channel_encoder import Channel_Encoder | ||
from core._print_ import _print_ | ||
import common.file_util as file_util | ||
|
||
import unittest | ||
import json | ||
|
||
def get_data(): | ||
|
||
data = {"monitor": | ||
{ "name" : "monitor" | ||
,"thumbnail_url" : "http:/xyz.com" | ||
,"description" : "monitor" | ||
,"splitter_addr" : "localhost" | ||
,"splitter_port" : "4552" } | ||
} | ||
return data | ||
|
||
path = file_util.find_file(__file__, | ||
"../data/channels/sample_data.json") | ||
|
||
#unittests are sorted according to their name and then run. | ||
#edit tearDown method to retain exported channels file and vice-versa. | ||
class Import_Export_Test(unittest.TestCase): | ||
|
||
exported_data = None | ||
imported_data = None | ||
|
||
def tearDown(self): | ||
if Import_Export_Test.imported_data is None: | ||
pass | ||
else: | ||
file_util.file_del(path) | ||
#pass | ||
|
||
def test_01_delete_channels_data(self): | ||
|
||
print("\n") | ||
_print_("deleting existing sample_data...") | ||
file_util.file_del(path) | ||
size = file_util.file_size(path) | ||
self.assertEqual(0,size) | ||
|
||
print("----------------------------------------------------------------------") | ||
|
||
def test_02_export_channels(self): | ||
|
||
Import_Export_Test.exported_data = get_data() | ||
|
||
monitor_channel = Channel(Import_Export_Test.exported_data["monitor"]) | ||
|
||
test_category = Category("test") | ||
test_category.add("monitor",monitor_channel) | ||
|
||
Import_Export_Test.exported_data["monitor1"] = get_data()["monitor"] | ||
test_category.add("monitor1",monitor_channel) | ||
|
||
exporter = JSON_Exporter() | ||
exporter.to_JSON(path,test_category.get_channels(),Channel_Encoder) | ||
print("\n") | ||
_print_("exporting channels to json file = " | ||
+ path | ||
+ "\n" | ||
+json.dumps(Import_Export_Test.exported_data | ||
,indent = 4 , cls = Channel_Encoder)) | ||
|
||
size = file_util.file_size(path) | ||
self.assertNotEqual(0,size) | ||
|
||
print("----------------------------------------------------------------------") | ||
|
||
def test_03_import_channels(self): | ||
importer = JSON_Importer() | ||
Import_Export_Test.imported_data = importer.from_JSON(path) | ||
print("\n") | ||
_print_("importing channels from json file = " | ||
+ path | ||
+ "\n" | ||
+json.dumps(Import_Export_Test.imported_data,indent = 4)) | ||
|
||
self.assertEqual(Import_Export_Test.exported_data | ||
,Import_Export_Test.imported_data) | ||
|
||
print("----------------------------------------------------------------------") | ||
|
||
|
||
if __name__ == "__main__": | ||
suite = unittest.TestLoader().loadTestsFromTestCase(Import_Export_Test) | ||
unittest.TextTestRunner(verbosity=2).run(suite) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters