def add(name,port,host = '',domain = '',stype = '_http._tcp',subtype = None,protocol = None,text = []): ''' Adds service file to storage dir @param name service name @param port integer port number. (udp: 0-65535, tcp: 1-65535) @param host hostname. multicast or unicast DNS findable host name. @param domain FQDN eg: myname.local or google.com @param stype see http://www.dns-sd.org/ServiceTypes.html (default: '_http._ftp') @param subtype service subtype @param protocol [any|ipv4|ipv6] (default: any; as per spec in "man avahi.service") @param text list/tuple of <text-record/> values USAGE: add('service name',9007) all other parameters are optional ''' ## notes for haxwithaxe # See http://www.dns-sd.org/ServiceTypes.html # name: <name>1 # stype: <service>+ # protocol: <service ?protocol="ipv4|ipv6|any"> # domain: <domain-name>? # host: <host-name>? (explicit FQDN eg: me.local) # subtype: <subtype>? # text: <txt-record>* # port: <port>? (uint) service_tmpl = file2str(config().service_template) service_path = os.path.join(services_store_dir, _mksname(name)+'.service') stext = '' for i in text: stext += '<text-record>'+i.strip()+'</text-record>' service_conf = service_tmpl % {'name':name,'port':port,'host':host,'domain':domain,'stype':stype,'subtype':subtype or '','protocol':protocol or 'any','text':stext} _utils.str2file(service_conf, service_path)
def update_services_cache(service,action = 'add'): logging.debug(service) logging.debug('updating cache') if os.path.exists(conf.services_cache): services = json.loads(_utils.file2str(conf.services_cache)) else: services = {} if action.lower() == 'add': services.update(service) logging.debug('Service added') elif action.lower() == 'del' and service in services: del services[service] logging.debug('Service removed') _utils.str2file(json.dumps(services),conf.services_cache)
def update_services_cache(service, action='add'): logging.debug(service) logging.debug('updating cache') if os.path.exists(conf.services_cache): services = json.loads(_utils.file2str(conf.services_cache)) else: services = {} if action.lower() == 'add': services.update(service) logging.debug('Service added') elif action.lower() == 'del' and service in services: del services[service] logging.debug('Service removed') _utils.str2file(json.dumps(services), conf.services_cache)