from __future__ import print_function import os, glob ''' Plugin handler for the chain plugin. The plugin handler needs to support two methods: push and flush. push Pushes a Seedlink station binding. Can be used to either create configuration files immediately or to manage the information until flush is called. flush Flush the configuration and return a unique key for this station that is used by seedlink to group eg templates for plugins.ini. ''' class SeedlinkPluginHandler: # Create defaults def __init__(self): self.chain_group = {} self.activeDialupConnections = 0 self.stations = {} # Generates the group tag def generateGroupTag(self, seedlink, source_address): try: maxDialupConnections = int(seedlink.param('plugins.chain.dialupConnections', False)) except: maxDialupConnections = 0 dialup = seedlink._get('sources.chain.dialup.enable').lower() in ("yes", "true", "1") status_file = source_address group_tag = \ ' = maxDialupConnections: self.activeDialupConnections = 0 try: group_tag += '\n' + \ ' overlap_removal="%s"' % seedlink.param('sources.chain.overlapRemoval') except: pass try: if seedlink.param('sources.chain.batchmode').lower() in ("yes", "true", "1"): batchmode = "yes" else: batchmode = "no" except: # Default batchmode is "yes" batchmode = "yes" group_tag += '\n' + \ ' batchmode="%s"' % batchmode if dialup: status_file += ".dial" group_tag += '\n' + \ ' uptime="%s"\n' % seedlink._get('sources.chain.dialup.uptime') + \ ' schedule="%s"' % seedlink._get('sources.chain.dialup.schedule') try: group_tag += '\n' + \ ' ifup="%s"' % seedlink.param('sources.chain.dialup.ifup') except: pass try: group_tag += '\n' + \ ' ifdown="%s"' % seedlink.param('sources.chain.dialup.ifdown') except: pass group_tag += '>\n' return group_tag, status_file # Generates the station tag, child of def generateStationTag(self, seedlink): # Create station XML tag id = seedlink._get('seedlink.station.id') station_tpl = " \n") first = False fd.write("\n") fd.close() else: # If no groups are configured, delete chainX.xml try: os.remove(chainxml) except: print("Warning: %s could not be removed" % chainxml) files = glob.glob(os.path.join(seedlink.config_dir, "chain*")) for f in files: if f in chains: continue try: os.remove(f) except: print("Warning: %s could not be removed" % f)