Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
willforde committed Feb 4, 2018
1 parent b2d38c6 commit 207246d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 6 additions & 6 deletions script.module.codequick/lib/codequick/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def _close(self):
raise KeyError("unknown stream detail key: '{}'".format(key))

# Now we are ready to send the stream info to kodi
if audio: # pragma: no branch
if audio: # pragma: no branch
self._listitem.addStreamInfo("audio", audio)
if video:
self._listitem.addStreamInfo("video", video)
Expand Down Expand Up @@ -508,7 +508,7 @@ class Listitem(object):

def __init__(self, content_type="video"):
self.content_type = content_type
self.callback = ""
self.path = ""

#: The underlining kodi listitem object, for advanced use.
self.listitem = listitem = xbmcgui.ListItem()
Expand Down Expand Up @@ -597,12 +597,12 @@ def set_callback(self, callback, *args, **kwargs):
args_map = callback.route.args_to_kwargs(args)
kwargs.update(args_map)

self.callback = callback
self.path = callback
self.params.update(kwargs)

# noinspection PyProtectedMember
def _close(self):
callback = self.callback
callback = self.path
if hasattr(callback, "route"):
self.listitem.setProperty("isplayable", str(callback.route.is_playable).lower())
self.listitem.setProperty("folder", str(callback.route.is_folder).lower())
Expand All @@ -620,11 +620,11 @@ def _close(self):
self.art.raw_dict["icon"] = "DefaultFolder.png"
else:
# Set Kodi icon image if not already set
if "icon" not in self.art.raw_dict: # pragma: no branch
if "icon" not in self.art.raw_dict: # pragma: no branch
self.art.raw_dict["icon"] = "DefaultVideo.png"

# Add mediatype if not already set
if "mediatype" not in self.info.raw_dict and self.content_type in ("video", "music"): # pragma: no branch
if "mediatype" not in self.info.raw_dict and self.content_type in ("video", "music"): # pragma: no branch
self.info.raw_dict["mediatype"] = self.content_type

# Add Video Specific Context menu items
Expand Down
12 changes: 9 additions & 3 deletions script.module.codequick/lib/codequick/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def flush(self):
Data will only be written to disk if contents has changed.
"""
# Serialize the storage data
content = pickle.dumps(self._serializer_obj(self), protocol=2) # Protocol 2 is used for python2/3 compatibility
content = pickle.dumps(self._serialize(), protocol=2) # Protocol 2 is used for python2/3 compatibility
current_hash = sha1(content).hexdigest()

# Compare saved hash with current hash, to detect if content has changed
Expand Down Expand Up @@ -102,6 +102,9 @@ def __enter__(self):
def __exit__(self, *_):
self.close()

def _serialize(self):
pass


class PersistentDict(_PersistentBase, dict):
"""
Expand Down Expand Up @@ -129,10 +132,12 @@ class PersistentDict(_PersistentBase, dict):
def __init__(self, name):
super(PersistentDict, self).__init__(name)
current_data = self._load()
self._serializer_obj = dict
if current_data:
self.update(current_data)

def _serialize(self):
return dict(self)


class PersistentList(_PersistentBase, list):
"""
Expand Down Expand Up @@ -161,7 +166,8 @@ class PersistentList(_PersistentBase, list):
def __init__(self, name):
super(PersistentList, self).__init__(name)
current_data = self._load()
self._serializer_obj = list
if current_data:
self.extend(current_data)

def _serialize(self):
return list(self)
4 changes: 2 additions & 2 deletions tests/test_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ def test_unformatted_label(self):

def test_callback(self):
self.listitem.set_callback(self.route_callback)
self.assertEqual(self.listitem.callback, self.route_callback)
self.assertEqual(self.listitem.path, self.route_callback)

def test_callback_args(self):
self.listitem.set_callback(self.route_callback_args, "yes", full=True)
self.assertEqual(self.listitem.callback, self.route_callback_args)
self.assertEqual(self.listitem.path, self.route_callback_args)
self.assertIn("full", self.listitem.params)
self.assertIn("test", self.listitem.params)

Expand Down

0 comments on commit 207246d

Please sign in to comment.