Skip to contentSkip to conversation

replace tabs with spaces of Python code

PATCH In review aq 2 participants 3 messages May 18, 2005 – May 19, 2005

lore
Share & tools
lore

aq

author
#0 lore raw

PATCH 1/1 replace tabs with spaces of Python code

hello,

there are many Python codes in tools/ that mix tab and space for indentation, which might introduce some silly and hidden bugs. this is a serious problem and must be avoid at all cost.

here is a patch (against cset 1.1452) to replace all tabs with spaces. all the changes are pretty trivial, and i double checked everything. please take a look to see if all the modifies are OK.

any idea? if nobody complains, i would prepare a patch like this for -testing tree.

$ diffstat removetab.patch 
 logging/logging-0.4.9.2/test/mymodule.py |    6 +-
 xen/sv/CreateDomain.py                   |   34 ++++++++--------
 xen/sv/Daemon.py                         |    2 
 xen/sv/DomInfo.py                        |   55 ++++++++++++--------------
 xen/sv/DomList.py                        |   16 +++----
 xen/sv/GenTabbed.py                      |    6 +-
 xen/sv/HTMLBase.py                       |    4 -
 xen/sv/Main.py                           |   12 ++---
 xen/sv/NodeInfo.py                       |   16 +++----
 xen/sv/Wizard.py                         |   64 +++++++++++++++----------------
 xen/sv/util.py                           |    6 +-
 xen/web/SrvBase.py                       |    6 +-
 xen/web/SrvDir.py                        |    2 
 xen/xend/EventServer.py                  |   24 +++++------
 xen/xend/PrettyPrint.py                  |    6 +-
 xen/xend/XendClient.py                   |    6 +-
 xen/xend/XendDomain.py                   |    4 -
 xen/xend/encode.py                       |    2 
 xen/xend/server/SrvDomain.py             |    6 +-
 xen/xend/sxp.py                          |    2 
 xen/xm/main.py                           |   12 ++---
 21 files changed, 143 insertions(+), 148 deletions(-)
Signature · 2 lines
regards,
aq

==== tools/python/logging/logging-0.4.9.2/test/mymodule.py 1.1 vs edited =====

tools/python/logging/logging-0.4.9.2/test/mymodule.py +3 -3
@@ -2,7 +2,7 @@ import logging
 log = logging.getLogger("MyModule")
 
 def doIt():
-	log.debug("Doin' stuff...")
-	#do stuff...
-	raise TypeError, "Bogus type error for testing"
+    log.debug("Doin' stuff...")
+    #do stuff...
+    raise TypeError, "Bogus type error for testing"
 

===== tools/python/xen/sv/CreateDomain.py 1.10 vs edited =====

tools/python/xen/sv/CreateDomain.py +17 -17
@@ -8,15 +8,15 @@ from xen.xend.XendClient import server
 
 class CreateDomain( Wizard ):
     def __init__( self, urlWriter ):
-    	
-    	sheets = [ CreatePage0,
-          	   CreatePage1,
-          	   CreatePage2,
+
+        sheets = [ CreatePage0,
+                   CreatePage1,
+                   CreatePage2,
                    CreatePage3,
                    CreatePage4,
                    CreateFinish ]
     
-    	Wizard.__init__( self, urlWriter, "Create Domain", sheets )
+        Wizard.__init__( self, urlWriter, "Create Domain", sheets )
        
 class CreatePage0( Sheet ):
 
@@ -39,7 +39,7 @@ class CreatePage1( Sheet ):
 class CreatePage2( Sheet ):
 
     def __init__( self, urlWriter ):
-    	Sheet.__init__( self, urlWriter, "Setup Virtual Block Device", 2 )
+        Sheet.__init__( self, urlWriter, "Setup Virtual Block Device", 2 )
         self.addControl( InputControl( 'num_vbds', '1', 'Number of VBDs:', '[\\d]+', "You must enter a number in this field" ) )
 
 class CreatePage3( Sheet ):
@@ -50,7 +50,7 @@ class CreatePage3( Sheet ):
     def write_BODY( self, request, err ):
         if not self.passback: self.parseForm( request )
     
-    	previous_values = sxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
+        previous_values = sxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
         
         num_vbds = previous_values.get( 'num_vbds' )
         
@@ -101,7 +101,7 @@ class CreateFinish( Sheet ):
         request.write( "<input type='hidden' name='sheet' value='%s'></p>" % self.location )
     
     def translate_sxp( self, fin_sxp ):
-   	fin_hash = ssxp2hash( fin_sxp )
+        fin_hash = ssxp2hash( fin_sxp )
     
         def get( key ):
             ret = fin_hash.get( key )
@@ -110,18 +110,18 @@ class CreateFinish( Sheet ):
             else:
                 return ""
         
-    	vals = OptVals()
+        vals = OptVals()
         
-        vals.name = 	get( 'name' )
-        vals.memory = 	get( 'memory' )
-        vals.maxmem =   get( 'maxmem' )
-        vals.cpu =  	get( 'cpu' )
+        vals.name = get( 'name' )
+        vals.memory = get( 'memory' )
+        vals.maxmem = get( 'maxmem' )
+        vals.cpu = get( 'cpu' )
         vals.cpu_weight = get( 'cpu_weight' )
         
-        vals.builder =  get( 'builder' )       
-        vals.kernel =   get( 'kernel' )
-	vals.root = 	get( 'root' )
-        vals.extra = 	get( 'extra' )
+        vals.builder = get( 'builder' )       
+        vals.kernel = get( 'kernel' )
+        vals.root = get( 'root' )
+        vals.extra = get( 'extra' )
         
         #setup vbds
         

===== tools/python/xen/sv/Daemon.py 1.8 vs edited =====

tools/python/xen/sv/Daemon.py +1 -1
@@ -89,7 +89,7 @@ class Daemon:
         return self.cleanup(kill=True)
 
     def run(self):
-	root = static.File( SV_ROOT )
+        root = static.File( SV_ROOT )
         root.indexNames = [ 'Main.rpy' ]
         root.processors = { '.rpy': script.ResourceScript }
         reactor.listenTCP( SV_PORT, server.Site( root ) )

===== tools/python/xen/sv/DomInfo.py 1.9 vs edited =====

tools/python/xen/sv/DomInfo.py +25 -30

84 lines not on this page · raw message

===== tools/python/xen/sv/DomList.py 1.9 vs edited =====

tools/python/xen/sv/DomList.py +8 -8
@@ -13,17 +13,17 @@ class DomList( HTMLBase ):
         self.urlWriter = urlWriter
         
     def write_MENU( self, request ):
-    	return self.write_BODY( request, head=True, long=False ) 
+        return self.write_BODY( request, head=True, long=False ) 
 
     def write_BODY( self, request, head=True, long=True ):
         
-    	domains = None
+        domains = None
     
-    	try:
-        	domains = server.xend_domains()
-        	domains.sort()
-  	except:
-        	pass
+        try:
+            domains = server.xend_domains()
+            domains.sort()
+        except:
+            pass
                 
         request.write( "\n<table style='border:0px solid white' cellspacing='0' cellpadding='0' border='0' width='100%'>\n" )
         
@@ -45,7 +45,7 @@ class DomList( HTMLBase ):
                 self.write_DOMAIN( request, getDomInfoHash( domain ), long )
                 request.write( "</tr>\n" )
         else:
-        	request.write( "<tr colspan='10'><p class='small'>Error getting domain list<br/>Perhaps XenD not running?</p></tr>")
+            request.write( "<tr colspan='10'><p class='small'>Error getting domain list<br/>Perhaps XenD not running?</p></tr>")
                 
         request.write( "</table>\n" )
             

===== tools/python/xen/sv/GenTabbed.py 1.6 vs edited =====

tools/python/xen/sv/GenTabbed.py +3 -3
@@ -114,16 +114,16 @@ class ActionTab( HTMLBase ):
 class CompositeTab( HTMLBase ):
 
     def __init__( self, tabs ):
-    	HTMLBase.__init__( self )
+        HTMLBase.__init__( self )
         self.tabs = tabs
         
     def write_BODY( self, request ):
-    	for tab in self.tabs:
+        for tab in self.tabs:
             request.write( "<br/>" )
             tab().write_BODY( request )
             
     def perform( self, request ):
-    	for tab in self.tabs:
+        for tab in self.tabs:
             tab().perform( request )
     
     

===== tools/python/xen/sv/HTMLBase.py 1.8 vs edited =====

tools/python/xen/sv/HTMLBase.py +2 -2
@@ -37,7 +37,7 @@ class HTMLBase( Resource ):
         """Get the method for an operation.
         For operation 'foo' looks for 'op_foo'.
 
-        op	operation name
+        op  operation name
         returns method or None
         """
         op_method_name = 'op_' + op
@@ -53,7 +53,7 @@ class HTMLBase( Resource ):
         and an HTML string otherwise (or list).
         Methods may also return a Deferred (for incomplete processing).
 
-        req	request
+        req request
         """
         op = req.args.get('op')
         if not op is None and len(op) == 1:

===== tools/python/xen/sv/Main.py 1.11 vs edited =====

tools/python/xen/sv/Main.py +6 -6
@@ -31,9 +31,9 @@ class Main( HTMLBase ):
         
     def render_POST( self, request ):
     
-    	#decide what module post'd the action
+        #decide what module post'd the action
                 
-    	args = getVar( 'args', request )
+        args = getVar( 'args', request )
 
         mod = getVar( 'mod', request )
                 
@@ -48,7 +48,7 @@ class Main( HTMLBase ):
         return self.render_GET( request )
 
     def mainUrlWriter( self, module ):
-    	def fun( f ):
+        def fun( f ):
             return "Main.rpy?mod=%s%s" % ( module, f )
         return fun    
         
@@ -98,16 +98,16 @@ class Main( HTMLBase ):
         
                 
     def op_destroy( self, request ):
-    	dom = getVar( 'dom', request )
+        dom = getVar( 'dom', request )
         if not dom is None and dom != "0":
             server.xend_domain_destroy( int( dom ), "halt" ) 
                  
     def op_pause( self, request ):
-    	dom = getVar( 'dom', request )
+        dom = getVar( 'dom', request )
         if not dom is None and dom != "0":
             server.xend_domain_pause( int( dom ) )      
     
     def op_unpause( self, request ):
-    	dom = getVar( 'dom', request )
+        dom = getVar( 'dom', request )
         if not dom is None and dom != "0":
             server.xend_domain_unpause( int( dom ) )      

===== tools/python/xen/sv/NodeInfo.py 1.9 vs edited =====

tools/python/xen/sv/NodeInfo.py +8 -8
@@ -14,16 +14,16 @@ class NodeInfo( GenTabbed ):
 
 class NodeGeneralTab( CompositeTab ):
     def __init__( self ):
-    	CompositeTab.__init__( self, [ NodeInfoTab, NodeActionTab ] )        
+        CompositeTab.__init__( self, [ NodeInfoTab, NodeActionTab ] )        
         
 class NodeInfoTab( GeneralTab ):
                         
     def __init__( self ):
          
-    	nodeInfo = {}
+        nodeInfo = {}
         try:
             nodeInfo = sxp2hash( server.xend_node() )
-   	except:
+        except:
             nodeInfo[ 'system' ] = 'Error getting node info'
              
         dictTitles = {}
@@ -43,7 +43,7 @@ class NodeInfoTab( GeneralTab ):
 class NodeDmesgTab( PreTab ):
 
     def __init__( self ):
-    	try:
+        try:
             dmesg = server.xend_node_get_dmesg()
         except:
             dmesg = "Error getting node information: XenD not running?"
@@ -53,12 +53,12 @@ class NodeActionTab( ActionTab ):
 
     def __init__( self ):
         ActionTab.__init__( self, { "shutdown" : ( "Shutdown the Node", "shutdown.png" ),
-        	"reboot" : ( "Reboot the Node", "reboot.png" ) } )    
+            "reboot" : ( "Reboot the Node", "reboot.png" ) } )    
         
     def op_shutdown( self, request ):
-    	print ">NodeShutDown"
-    	server.xend_node_shutdown()
+        print ">NodeShutDown"
+        server.xend_node_shutdown()
     
     def op_reboot( self, request ):
-    	print ">NodeReboot"
+        print ">NodeReboot"
         server.xend_node_reboot()

===== tools/python/xen/sv/Wizard.py 1.7 vs edited =====

tools/python/xen/sv/Wizard.py +32 -32

183 lines not on this page · raw message

===== tools/python/xen/sv/util.py 1.10 vs edited =====

tools/python/xen/sv/util.py +3 -3
@@ -10,14 +10,14 @@ def getDomInfoHash( domain ):
         domInfoHash = sxp2hash( server.xend_domain( domain ) )
         domInfoHash['dom'] = domain
     except:
-    	domInfoHash['name'] = "Error getting domain details"
+        domInfoHash['name'] = "Error getting domain details"
     return domInfoHash
 
 def sxp2hash( s ):
     sxphash = {}
         
     for child in sxp.children( s ):
-    	if isinstance( child, types.ListType ) and len( child ) > 1:
+        if isinstance( child, types.ListType ) and len( child ) > 1:
             if isinstance( child[1], types.ListType ) and len( child ) > 1:
                 sxphash[ child[0] ] = sxp2hash( child[1] )
             else:
@@ -38,7 +38,7 @@ def hash2sxp( h ):
     hashsxp = []
     
     for (key, item) in h.items():
-    	hashsxp.append( [key, item] )
+        hashsxp.append( [key, item] )
         
     return hashsxp    
     

===== tools/python/xen/web/SrvBase.py 1.3 vs edited =====

tools/python/xen/web/SrvBase.py +3 -3
@@ -15,7 +15,7 @@ import httpserver
 
 def uri_pathlist(p):
     """Split a path into a list.
-    p		path
+    p       path
     return list of path elements
     """
     l = []
@@ -36,7 +36,7 @@ class SrvBase(resource.Resource):
         """Get the method for an operation.
         For operation 'foo' looks for 'op_foo'.
 
-        op	operation name
+        op  operation name
         returns method or None
         """
         op_method_name = 'op_' + op
@@ -52,7 +52,7 @@ class SrvBase(resource.Resource):
         and an HTML string otherwise (or list).
         Methods may also return a ThreadRequest (for incomplete processing).
 
-        req	request
+        req request
         """
         op = req.args.get('op')
         if op is None or len(op) != 1:

===== tools/python/xen/web/SrvDir.py 1.3 vs edited =====

tools/python/xen/web/SrvDir.py +1 -1
@@ -22,7 +22,7 @@ class SrvConstructor:
         """Create a constructor. It is assumed that the class
         should be imported as 'from xen.xend.server.klass import klass'.
 
-        klass	name of its class
+        klass   name of its class
         """
         self.klass = klass
         self.obj = None

===== tools/python/xen/xend/EventServer.py 1.9 vs edited =====

tools/python/xen/xend/EventServer.py +12 -12
@@ -71,7 +71,7 @@ class EventServer:
         for the '?'. A subscription like 'a.b.c.*' ending in '*' matches
         any event type with the same prefix, 'a.b.c' in this case.
 
-        event	event name
+        event   event name
         handler event handler fn(event, val)
         """
         try:
@@ -87,7 +87,7 @@ class EventServer:
     def unsubscribe_all(self, event=None):
         """Unsubscribe all handlers for a given event, or all handlers.
 
-        event	event (optional)
+        event   event (optional)
         """
         try:
             self.lock.acquire()
@@ -101,7 +101,7 @@ class EventServer:
     def unsubscribe(self, event, handler):
         """Unsubscribe a given event and handler.
 
-        event	event
+        event   event
         handler handler
         """
         try:
@@ -118,8 +118,8 @@ class EventServer:
         """Inject an event. Handlers for it are called if running, otherwise
         it is queued.
 
-        event	event type
-        val	event value
+        event   event type
+        val event value
         """
         try:
             self.lock.acquire()
@@ -146,9 +146,9 @@ class EventServer:
         """Call the handlers for an event.
         It is safe for handlers to subscribe or unsubscribe.
 
-        key	key for handler list
-        event	event type
-        val	event value
+        key key for handler list
+        event   event type
+        val event value
         """
         try:
             self.lock.acquire()
@@ -171,8 +171,8 @@ class EventServer:
     def call_query_handlers(self, event, val):
         """Call regex handlers for events matching 'event' that end in '?'.
 
-        event	event type
-        val	event value
+        event   event type
+        val event value
         """
         dot_idx = event.rfind(self.DOT)
         if dot_idx == -1:
@@ -184,8 +184,8 @@ class EventServer:
     def call_star_handlers(self, event, val):
         """Call regex handlers for events matching 'event' that end in '*'.
 
-        event	event type
-        val	event value
+        event   event type
+        val event value
         """
         etype = string.split(event, self.DOT)
         for i in range(len(etype), 0, -1):

===== tools/python/xen/xend/PrettyPrint.py 1.6 vs edited =====

tools/python/xen/xend/PrettyPrint.py +3 -3
@@ -273,9 +273,9 @@ class SXPPrettyPrinter(PrettyPrinter):
 def prettyprint(sxpr, out=sys.stdout, width=80):
     """Prettyprint an SXP form.
 
-    sxpr	s-expression
-    out		destination
-    width	maximum output width
+    sxpr    s-expression
+    out     destination
+    width   maximum output width
     """
     if isinstance(sxpr, types.ListType):
         pp = SXPPrettyPrinter(width=width)

===== tools/python/xen/xend/XendClient.py 1.48 vs edited =====

tools/python/xen/xend/XendClient.py +3 -3
@@ -256,9 +256,9 @@ class Xend:
                              {'op'        : 'cpu_sedf_set',
                               'period'    : period,
                               'slice'     : slice,
-			      'latency'   : latency,
-			      'extratime' : extratime,
-			      'weight'    : weight })
+                              'latency'   : latency,
+                              'extratime' : extratime,
+                              'weight'    : weight })
 
     def xend_domain_maxmem_set(self, id, memory):
         return self.xendPost(self.domainurl(id),

===== tools/python/xen/xend/XendDomain.py 1.75 vs edited =====

tools/python/xen/xend/XendDomain.py +2 -2
@@ -164,7 +164,7 @@ class XendDomain:
     def sync_domain(self, dom):
         """Sync info for a domain to disk.
 
-        dom	domain id (string)
+        dom domain id (string)
         """
         self.db.save(dom, self.domain_db[dom])
 
@@ -658,7 +658,7 @@ class XendDomain:
     def domain_cpu_sedf_set(self, id, period, slice, latency, extratime, weight):
         """Set Simple EDF scheduler parameters for a domain.
         """
-	dominfo = self.domain_lookup(id)
+        dominfo = self.domain_lookup(id)
         try:
             return xc.sedf_domain_set(dominfo.dom, period, slice, latency, extratime, weight)
         except Exception, ex:

===== tools/python/xen/xend/encode.py 1.7 vs edited =====

tools/python/xen/xend/encode.py +1 -1
@@ -82,7 +82,7 @@ def encode_data(d):
     """Encode some data for HTTP transport.
     The encoding used is stored in 'Content-Type' in the headers.
 
-    d	data - sequence of tuples or dictionary
+    d   data - sequence of tuples or dictionary
     returns a 2-tuple of the headers and the encoded data
     """
     val = ({}, None)

===== tools/python/xen/xend/sxp.py 1.16 vs edited =====

tools/python/xen/xend/sxp.py +1 -1
@@ -707,7 +707,7 @@ def all_from_string(str):
 def parse(io):
     """Completely parse all input from 'io'.
 
-    io	input file object
+    io  input file object
     returns list of values, None if incomplete
     raises ParseError on parse error
     """

===== tools/python/xen/xend/server/SrvDomain.py 1.38 vs edited =====

tools/python/xen/xend/server/SrvDomain.py +3 -3
@@ -110,9 +110,9 @@ class SrvDomain(SrvDir):
                     [['dom', 'str'],
                      ['period', 'int'],
                      ['slice', 'int'],
-		     ['latency', 'int'],
-		     ['extratime', 'int'],
-		     ['weight', 'int']])
+                     ['latency', 'int'],
+                     ['extratime', 'int'],
+                     ['weight', 'int']])
         val = fn(req.args, {'dom': self.dom.id})
         return val
 

===== tools/python/xen/xm/main.py 1.52 vs edited =====

tools/python/xen/xm/main.py +6 -6
@@ -142,8 +142,8 @@ class Xm:
         """
         self.name = args[0]
         if len(args) < 2:
-        	args.append('help')
-	help = self.helparg(args)
+            args.append('help')
+        help = self.helparg(args)
         p = self.getprog(args[1], self.unknown)
         if help or len(args) < 2: 
             p.help(args[1:])
@@ -646,10 +646,10 @@ class ProgSedf(Prog):
         print "\nSet simple EDF parameters."
 
     def main(self, args):
-	if len(args) != 7: self.err("%s: Invalid argument(s)" % args[0])
-	dom = args[1]
-	v = map(int, args[2:7])
-	server.xend_domain_cpu_sedf_set(dom, *v)
+        if len(args) != 7: self.err("%s: Invalid argument(s)" % args[0])
+        dom = args[1]
+        v = map(int, args[2:7])
+        server.xend_domain_cpu_sedf_set(dom, *v)
 
 xm.prog(ProgSedf)
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 5 lines · aq

hello,

there are many Python codes in tools/ that mix tab and space for indentation, which might introduce some silly and hidden bugs. this is a serious problem and must be avoid at all cost.

I would suggest doing the opposite, like Linux does, but I guess this is mostly a matter of taste (i.e. your's is bad and mine is good ;-))

Jacob

author
#2 lore raw
Quoted 9 lines · Jacob Gorm Hansen
Quoted 5 lines · aq

hello,

there are many Python codes in tools/ that mix tab and space for indentation, which might introduce some silly and hidden bugs. this is a serious problem and must be avoid at all cost.

I would suggest doing the opposite, like Linux does, but I guess this is mostly a matter of taste (i.e. your's is bad and mine is good ;-))

because most of code in Xen use spaces to indent, so it takes less time/effort to convert/check if we change tab to spaces. so it is wiser not to do the opposite :-)

regards,
aq