Skip to content

Commit

Permalink
Merge pull request #960 from onkelandy/smartvisu
Browse files Browse the repository at this point in the history
(Visu_)Smartvisu Plugin: minor and 2 major fixes
  • Loading branch information
onkelandy authored Sep 20, 2024
2 parents 0efd5a1 + 919e547 commit b61eab4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 85 deletions.
38 changes: 15 additions & 23 deletions smartvisu/svgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

from lib.item import Items


class SmartVisuGenerator:

valid_sv_page_entries = ['room', 'overview', 'separator', 'seperator',
'category', 'cat_overview', 'cat_separator','cat_seperator',
'category', 'cat_overview', 'cat_separator', 'cat_seperator',
'room_lite', 'sv_overview']


def __init__(self, plugin_instance, visu_definition=None):
self.items = Items.get_instance()

Expand All @@ -43,9 +43,9 @@ def __init__(self, plugin_instance, visu_definition=None):
self.smartvisu_version = plugin_instance.smartvisu_version
self.overwrite_templates = plugin_instance.overwrite_templates
self.visu_style = plugin_instance.visu_style.lower()
if not self.visu_style in ['std','blk']:
if self.visu_style not in ['std', 'blk']:
self.visu_style = 'std'
self.logger.warning("SmartVisuGenerator: visu_style '{}' unknown, using visu_style '{1}'".format(plugin_instance.visu_style, self.visu_style))
self.logger.warning("SmartVisuGenerator: visu_style '{0}' unknown, using visu_style '{1}'".format(plugin_instance.visu_style, self.visu_style))
self.list_deprecated_warnings = plugin_instance.list_deprecated_warnings

self.logger.info("Generating pages for smartVISU v{}".format(self.smartvisu_version))
Expand Down Expand Up @@ -102,7 +102,6 @@ def initialize_visu_menu(self, nav_config, menu):
self.add_menuentry_to_list(menu, menu_entry)
self.logger.debug("initialize_visu_menu: '{}' menu_entry={}".format(menu, menu_entry))


def handle_heading_attributes(self, room):
if 'sv_heading_right' in room.conf:
heading_right = room.conf['sv_heading_right']
Expand All @@ -122,7 +121,6 @@ def handle_heading_attributes(self, room):
heading = ''
return heading


def get_widgetblocksize(self, item):
"""
Returns the blocksize for the block in which the item is to be displayed.
Expand All @@ -134,21 +132,19 @@ def get_widgetblocksize(self, item):
"""
if 'sv_blocksize' in item.conf:
blocksize = item.conf['sv_blocksize']
if not blocksize in ['1','2','3']:
if blocksize not in ['1', '2', '3']:
blocksize = '2'
else:
blocksize = '2'
return blocksize


def get_attribute(self, attr, item):
if attr in item.conf:
attrvalue = item.conf[attr]
else:
attrvalue = ''
return attrvalue


def create_page(self, room, menu_entry):
"""
Interpretation of the room-specific item-attributes.
Expand All @@ -159,7 +155,7 @@ def create_page(self, room, menu_entry):
:return: html code to be included in the visu file for the room
:rtype: str
"""
block_style = 'std' # 'std' or 'noh'
block_style = 'std' # 'std' or 'noh'
widgetblocktemplate = 'widgetblock_' + self.visu_style + '_' + block_style + '.html'
widgetblocktemplate2 = 'widgetblock2_' + self.visu_style + '_' + block_style + '.html'
widgets = ''
Expand Down Expand Up @@ -215,7 +211,6 @@ def create_page(self, room, menu_entry):
menu_entry['content'] += widgets
return r


def pages(self):
if not self.remove_oldpages():
return
Expand Down Expand Up @@ -284,13 +279,13 @@ def pages(self):
def create_menuentry(self, menu, entry_name, item_path, separator, img_name, nav_aside, nav_aside2, from_navconfig=False):
for menu_entry in self.navigation[menu]:
if menu_entry['name'] == entry_name:
if menu_entry.get('img', '') == '' and menu_entry.get('img_set', False) == False:
if menu_entry.get('img', '') == '' and menu_entry.get('img_set', False) is False:
menu_entry['img'] = img_name
if menu_entry['item_path'] == '':
menu_entry['item_path'] = item_path
if menu_entry.get('nav_aside', '') == ''and menu_entry.get('nav_aside_set', False) == False:
if menu_entry.get('nav_aside', '') == '' and menu_entry.get('nav_aside_set', False) is False:
menu_entry['nav_aside'] = nav_aside
if menu_entry.get('nav_aside2', '') == '' and menu_entry.get('nav_aside2_set', False) == False:
if menu_entry.get('nav_aside2', '') == '' and menu_entry.get('nav_aside2_set', False) is False:
menu_entry['nav_aside2'] = nav_aside2
return menu_entry

Expand All @@ -299,7 +294,7 @@ def create_menuentry(self, menu, entry_name, item_path, separator, img_name, nav
menu_entry['item_path'] = item_path
menu_entry['separator'] = separator
menu_entry['page'] = menu + '.' + entry_name
for ch in [' ',':','/','\\']:
for ch in [' ', ':', '/', '\\']:
if ch in menu_entry['page']:
menu_entry['page'] = menu_entry['page'].replace(ch, '_')
menu_entry['heading'] = ''
Expand Down Expand Up @@ -329,7 +324,6 @@ def create_menuentry(self, menu, entry_name, item_path, separator, img_name, nav

return menu_entry


def add_menuentry_to_list(self, menu, menu_entry):
for entry in self.navigation[menu]:
if entry['name'] == menu_entry['name']:
Expand Down Expand Up @@ -358,7 +352,7 @@ def write_navigation_and_pages(self, menu, navigation_file):
('{{ visu_aside2 }}', menu_entry['nav_aside2']),
('item.name', menu_entry['name']), ("'item", "'" + menu_entry['item_path'])
]
if menu_entry['separator'] == True:
if menu_entry['separator'] is True:
nav_list += self.parse_tpl('navi_sep.html', [('{{ name }}', menu_entry['name'])])
else:
#menu_entry['html'] = self.parse_tpl('navi.html', parse_list)
Expand All @@ -371,7 +365,7 @@ def write_navigation_and_pages(self, menu, navigation_file):
nav_list += self.parse_tpl('navi.html', parse_list)

# build page code
if menu_entry['separator'] == False:
if menu_entry['separator'] is False:
# build and write file for a single room
r = self.parse_tpl(menu+'_page.html', [('{{ visu_name }}', menu_entry['name']), ('{{ visu_widgets }}', menu_entry['content']),
('{{ visu_img }}', menu_entry['img']), ('{{ visu_heading }}', menu_entry['heading'])])
Expand Down Expand Up @@ -420,15 +414,13 @@ def parse_tpl(self, template, replace):
tpl = tpl.replace(s, rs)
return tpl


def write_parseresult(self, htmlfile, parseresult):
try:
with open(self.pages_dir + '/' + htmlfile, 'w') as f:
f.write(parseresult)
except Exception as e:
self.logger.warning("Could not write to {0}/{1}: {2}".format(self.pages_dir, htmlfile, e))


def copy_tpl(self, tplname, destname=''):
if destname == '':
destname = tplname
Expand Down Expand Up @@ -487,7 +479,7 @@ def copy_templates(self):

if self.smartvisu_version >= '2.9':
for fn in os.listdir(self.shng_tpldir):
if (self.overwrite_templates) or (not os.path.isfile(os.path.join(self.gen_tpldir, fn)) ):
if (self.overwrite_templates) or (not os.path.isfile(os.path.join(self.gen_tpldir, fn))):
self.logger.debug("copy_templates: Copying template '{}' from plugin to smartVISU v{} ({})".format(fn, self.smartvisu_version, self.gen_tpldir))
shutil.copy2(os.path.join(self.shng_tpldir, fn), self.gen_tpldir)
shutil.copy2(os.path.join(self.sv_tpldir, 'index.html'), self.gen_tpldir)
Expand All @@ -503,10 +495,10 @@ def copy_templates(self):
pass
# Open file for twig import statements (for root.html)
for fn in os.listdir(self.shng_tpldir):
if (self.overwrite_templates) or (not os.path.isfile(os.path.join(self.gen_tpldir, fn)) ):
if (self.overwrite_templates) or (not os.path.isfile(os.path.join(self.gen_tpldir, fn))):
self.logger.debug("copy_templates: Copying template '{}' from plugin to smartVISU v{}".format(fn, self.smartvisu_version))
try:
shutil.copy2( os.path.join(self.shng_tpldir, fn), self.gen_tpldir )
shutil.copy2(os.path.join(self.shng_tpldir, fn), self.gen_tpldir)
except Exception as e:
self.logger.error("Could not copy {0} from {1} to {2}".format(fn, self.shng_tpldir, self.gen_tpldir))
return
Loading

0 comments on commit b61eab4

Please sign in to comment.