Permalink
Browse files

fixed tabs in python files from <insert whitespace> to 4 spaces per tab

  • Loading branch information...
1 parent c99a505 commit e04d43ad5f192640650581bd44a6a266af67df96 @haxwithaxe haxwithaxe committed Jul 22, 2012
View
@@ -2,28 +2,28 @@
# vim: set expandtab tabstop=4 shiftwidth=4 :
def debug(message,level = '1'):
- import os
- _debug = ('BYZ_DEBUG' in os.environ)
- if _debug and os.environ['BYZ_DEBUG'] >= level:
- print(repr(message))
+ import os
+ _debug = ('BYZ_DEBUG' in os.environ)
+ if _debug and os.environ['BYZ_DEBUG'] >= level:
+ print(repr(message))
def file2str(file_name, mode = 'r'):
- fileobj = open(file_name,mode)
- filestr = fileobj.read()
- fileobj.close()
- return filestr
+ fileobj = open(file_name,mode)
+ filestr = fileobj.read()
+ fileobj.close()
+ return filestr
def str2file(string,file_name,mode = 'w'):
- fileobj = open(file_name,mode)
- fileobj.write(string)
- fileobj.close()
+ fileobj = open(file_name,mode)
+ fileobj.write(string)
+ fileobj.close()
class Config(object):
- ''' Make me read from a file '''
- def __init__(self):
- self.services_cache = '/tmp/byz_services.json'
- self.service_template = '/etc/byzantium/services/avahi/template.service'
- self.services_store_dir = '/etc/avahi/inactive'
- self.services_live_dir = '/etc/avahi/services'
+ ''' Make me read from a file '''
+ def __init__(self):
+ self.services_cache = '/tmp/byz_services.json'
+ self.service_template = '/etc/byzantium/services/avahi/template.service'
+ self.services_store_dir = '/etc/avahi/inactive'
+ self.services_live_dir = '/etc/avahi/services'
View
@@ -9,75 +9,75 @@
def _mksname(name):
- return name.lower().replace(' ','_')
+ return name.lower().replace(' ','_')
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)
+ ''' 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)
- # activate here?
+ 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)
+ # activate here?
def activate(name):
- service_file = os.path.join(services_store_dir,_mksname(name)+'.service')
- service_link = os.path.join(services_live_dir,_mksname(name)+'.service')
- if service_file != service_link:
- if os.path.exists(service_file):
- if os.path.exists(os.path.split(service_link)[0]):
- try:
- os.symlink(service_file,service_link)
- except Exception as sym_e:
- return {'code':False,'message':repr(sym_e)}
- else:
- return {'code':False,'message':'Directory not found: "%s"' % os.path.split(service_link)[0]}
- else:
- return {'code':False,'message':'Directory not found: "%s"' % service_file}
- reload_avahi_daemon()
- return {'code':True,'message':'Activated'}
+ service_file = os.path.join(services_store_dir,_mksname(name)+'.service')
+ service_link = os.path.join(services_live_dir,_mksname(name)+'.service')
+ if service_file != service_link:
+ if os.path.exists(service_file):
+ if os.path.exists(os.path.split(service_link)[0]):
+ try:
+ os.symlink(service_file,service_link)
+ except Exception as sym_e:
+ return {'code':False,'message':repr(sym_e)}
+ else:
+ return {'code':False,'message':'Directory not found: "%s"' % os.path.split(service_link)[0]}
+ else:
+ return {'code':False,'message':'Directory not found: "%s"' % service_file}
+ reload_avahi_daemon()
+ return {'code':True,'message':'Activated'}
def deactivate(name):
- service_file = os.path.join(services_store_dir,_mksname(name)+'.service')
- service_link = os.path.join(services_live_dir,_mksname(name)+'.service')
- if service_file != service_link:
- if os.path.exists(service_link):
- try:
- os.remove(service_link)
- except Exception as rm_sym_e:
- return {'code':False,'message':repr(rm_sym_e)}
- else:
- return {'code':False,'message':'Directory not found: "%s"' % service_link}
- reload_avahi_daemon()
- return {'code':True,'message':'Deactivated'}
- else:
- return {'code':False,'message':'Service file is the same as service link (file:"%s", link:"%s")' % (service_file,service_link)}
+ service_file = os.path.join(services_store_dir,_mksname(name)+'.service')
+ service_link = os.path.join(services_live_dir,_mksname(name)+'.service')
+ if service_file != service_link:
+ if os.path.exists(service_link):
+ try:
+ os.remove(service_link)
+ except Exception as rm_sym_e:
+ return {'code':False,'message':repr(rm_sym_e)}
+ else:
+ return {'code':False,'message':'Directory not found: "%s"' % service_link}
+ reload_avahi_daemon()
+ return {'code':True,'message':'Deactivated'}
+ else:
+ return {'code':False,'message':'Service file is the same as service link (file:"%s", link:"%s")' % (service_file,service_link)}
def reload_avahi_daemon():
- import subprocess
- cmd = ['/usr/sbin/avahi-daemon','--reload']
- subprocess.call(cmd)
+ import subprocess
+ cmd = ['/usr/sbin/avahi-daemon','--reload']
+ subprocess.call(cmd)
@@ -14,8 +14,8 @@
# For security reasons I see no reason to change this; if you want to admin a
# Byzantium node remotely you'll have to use SSH port forwarding.
-# v0.2 - Split the network traffic graphs from the system status report.
-# v0.1 - Initial release.
+# v0.2 - Split the network traffic graphs from the system status report.
+# v0.1 - Initial release.
# Import modules.
import cherrypy
View
@@ -5,45 +5,45 @@
import socket
class DNSQuery:
- def __init__(self, data):
- self.data=data
- self.domain=''
+ def __init__(self, data):
+ self.data=data
+ self.domain=''
- tipo = (ord(data[2]) >> 3) & 15 # Opcode bits
- if tipo == 0: # Standard query
- ini=12
- lon=ord(data[ini])
- while lon != 0:
- self.domain+=data[ini+1:ini+lon+1]+'.'
- ini+=lon+1
- lon=ord(data[ini])
+ tipo = (ord(data[2]) >> 3) & 15 # Opcode bits
+ if tipo == 0: # Standard query
+ ini=12
+ lon=ord(data[ini])
+ while lon != 0:
+ self.domain+=data[ini+1:ini+lon+1]+'.'
+ ini+=lon+1
+ lon=ord(data[ini])
- def response(self, ip):
- packet=''
- if self.domain:
- packet+=self.data[:2] + "\x81\x80"
- packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00' # Questions and Answers Counts
- packet+=self.data[12:] # Original Domain Name Question
- packet+='\xc0\x0c' # Pointer to domain name
- packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04' # Response type, ttl and resource data length -> 4 bytes
- packet+=str.join('',map(lambda x: chr(int(x)), ip.split('.'))) # 4bytes of IP
- return packet
+ def response(self, ip):
+ packet=''
+ if self.domain:
+ packet+=self.data[:2] + "\x81\x80"
+ packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00' # Questions and Answers Counts
+ packet+=self.data[12:] # Original Domain Name Question
+ packet+='\xc0\x0c' # Pointer to domain name
+ packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04' # Response type, ttl and resource data length -> 4 bytes
+ packet+=str.join('',map(lambda x: chr(int(x)), ip.split('.'))) # 4bytes of IP
+ return packet
if __name__ == '__main__':
- ip='192.168.1.1'
- print 'DistDNS:: dom.query. 60 IN A %s' % ip
+ ip='192.168.1.1'
+ print 'DistDNS:: dom.query. 60 IN A %s' % ip
- udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- udps.bind(('',53))
+ udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ udps.bind(('',53))
- try:
- while 1:
- data, addr = udps.recvfrom(1024)
- p=DNSQuery(data)
- udps.sendto(p.response(ip), addr)
- print 'Response: %s -> %s' % (p.domain, ip)
- except KeyboardInterrupt:
- print 'Finished'
- udps.close()
+ try:
+ while 1:
+ data, addr = udps.recvfrom(1024)
+ p=DNSQuery(data)
+ udps.sendto(p.response(ip), addr)
+ print 'Response: %s -> %s' % (p.domain, ip)
+ except KeyboardInterrupt:
+ print 'Finished'
+ udps.close()
## end of http://code.activestate.com/recipes/491264/ }}}
Oops, something went wrong.

0 comments on commit e04d43a

Please sign in to comment.