All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] replace tabs with spaces of Python code
@ 2005-05-18 18:58 aq
  2005-05-18 19:59 ` Jacob Gorm Hansen
  0 siblings, 1 reply; 12+ messages in thread
From: aq @ 2005-05-18 18:58 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 1846 bytes --]

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.

Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>


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(-)

-- 
regards,
aq

[-- Attachment #2: removetab.patch --]
[-- Type: application/octet-stream, Size: 32077 bytes --]

==== tools/python/logging/logging-0.4.9.2/test/mymodule.py 1.1 vs edited =====
--- 1.1/tools/python/logging/logging-0.4.9.2/test/mymodule.py	2004-07-22 22:42:38 +09:00
+++ edited/tools/python/logging/logging-0.4.9.2/test/mymodule.py	2005-05-19 01:48:50 +09:00
@@ -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 =====
--- 1.10/tools/python/xen/sv/CreateDomain.py	2004-11-02 10:26:39 +09:00
+++ edited/tools/python/xen/sv/CreateDomain.py	2005-05-19 03:12:37 +09:00
@@ -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 =====
--- 1.8/tools/python/xen/sv/Daemon.py	2005-05-18 07:28:24 +09:00
+++ edited/tools/python/xen/sv/Daemon.py	2005-05-19 02:00:44 +09:00
@@ -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 =====
--- 1.9/tools/python/xen/sv/DomInfo.py	2004-09-22 19:51:55 +09:00
+++ edited/tools/python/xen/sv/DomInfo.py	2005-05-19 02:13:26 +09:00
@@ -91,59 +91,54 @@ class DomSXPTab( PreTab ):
 class DomActionTab( ActionTab ):
 
     def __init__( self ):
-    	actions = { "shutdown" : ( "Shutdown the Domain", "shutdown.png" ),
-        	    "reboot" : ( "Reboot the Domain", "reboot.png" ),
+        actions = { "shutdown" : ( "Shutdown the Domain", "shutdown.png" ),
+                    "reboot" : ( "Reboot the Domain", "reboot.png" ),
                     "pause" : ( "Pause the Domain", "pause.png" ),
                     "unpause" : ( "Unpause the Domain", "unpause.png" ),
                     "destroy" : ( "Destroy the Domain", "destroy.png" ) }
         ActionTab.__init__( self, actions )    
         
     def op_shutdown( self, request ):
-   	dom = getVar( 'dom', request )
+        dom = getVar( 'dom', request )
         if not dom is None and dom != '0':
-    	   if DEBUG: print ">DomShutDown %s" % dom
-           try:
-    	   	server.xend_domain_shutdown( int( dom ), "halt" )
-           except:
-           	pass
+            if DEBUG: print ">DomShutDown %s" % dom
+            try:
+                server.xend_domain_shutdown( int( dom ), "halt" )
+            except:
+                pass
     
     def op_reboot( self, request ):
-       	dom = getVar( 'dom', request )
+        dom = getVar( 'dom', request )
         if not dom is None and dom != '0':
-    	    if DEBUG: print ">DomReboot %s" % dom
+            if DEBUG: print ">DomReboot %s" % dom
             try:
-            	server.xend_domain_shutdown( int( dom ), "reboot" )
+                server.xend_domain_shutdown( int( dom ), "reboot" )
             except:
-            	pass
+                pass
                 
     def op_pause( self, request ):
-       	dom = getVar( 'dom', request )
+        dom = getVar( 'dom', request )
         if not dom is None and dom != '0':
-    	    if DEBUG: print ">DomPause %s" % dom
+            if DEBUG: print ">DomPause %s" % dom
             try:
                 server.xend_domain_pause( int( dom ) )
             except:
-            	pass
+                pass
                
     def op_unpause( self, request ):
-       	dom = getVar( 'dom', request )
+        dom = getVar( 'dom', request )
         if not dom is None and dom != '0':
-    	   if DEBUG: print ">DomUnpause %s" % dom
-           try:
+            if DEBUG: print ">DomUnpause %s" % dom
+            try:
                server.xend_domain_unpause( int( dom ) )
-    	   except:
+            except:
                pass
                
     def op_destroy( self, request ):
-    	dom = getVar( 'dom', request )
+        dom = getVar( 'dom', request )
         if not dom is None and dom != '0':
-    	   if DEBUG: print ">DomDestroy %s" % dom
-           try:
-           	server.xend_domain_destroy( int( dom ), "halt" )
-           except:
-           	pass
-        
-    
-    
-        
-
+            if DEBUG: print ">DomDestroy %s" % dom
+            try:
+                server.xend_domain_destroy( int( dom ), "halt" )
+            except:
+                pass
===== tools/python/xen/sv/DomList.py 1.9 vs edited =====
--- 1.9/tools/python/xen/sv/DomList.py	2004-09-17 00:11:53 +09:00
+++ edited/tools/python/xen/sv/DomList.py	2005-05-19 02:18:04 +09:00
@@ -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 =====
--- 1.6/tools/python/xen/sv/GenTabbed.py	2004-07-27 01:18:00 +09:00
+++ edited/tools/python/xen/sv/GenTabbed.py	2005-05-19 02:19:32 +09:00
@@ -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 =====
--- 1.8/tools/python/xen/sv/HTMLBase.py	2004-08-16 22:04:37 +09:00
+++ edited/tools/python/xen/sv/HTMLBase.py	2005-05-19 02:20:38 +09:00
@@ -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 =====
--- 1.11/tools/python/xen/sv/Main.py	2004-11-02 10:26:39 +09:00
+++ edited/tools/python/xen/sv/Main.py	2005-05-19 02:25:00 +09:00
@@ -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 =====
--- 1.9/tools/python/xen/sv/NodeInfo.py	2004-11-02 00:49:54 +09:00
+++ edited/tools/python/xen/sv/NodeInfo.py	2005-05-19 02:29:21 +09:00
@@ -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 =====
--- 1.7/tools/python/xen/sv/Wizard.py	2004-07-29 21:54:44 +09:00
+++ edited/tools/python/xen/sv/Wizard.py	2005-05-19 02:44:05 +09:00
@@ -15,11 +15,11 @@ class Wizard( HTMLBase ):
         self.urlWriter = urlWriter
         
     def write_MENU( self, request ):
-    	request.write( "<p class='small'><a href='%s'>%s</a></p>" % (self.urlWriter( '' ), self.title) ) 
+        request.write( "<p class='small'><a href='%s'>%s</a></p>" % (self.urlWriter( '' ), self.title) ) 
     
     def write_BODY( self, request ):
         
-   	request.write( "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td>" )
+        request.write( "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td>" )
         request.write( "<p align='center'><u>%s</u></p></td></tr><tr><td>" % self.title )
         
         currSheet = getVar( 'sheet', request )
@@ -51,8 +51,8 @@ class Wizard( HTMLBase ):
         
         request.write( "</td></tr><tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>" )
         request.write( "<td width='80%'></td><td width='20%' align='center'><p align='center'>" )
-	if currSheet > 0:
-       	    request.write( "<img src='images/previous.png' onclick='doOp( \"prev\" )' onmouseover='update( \"wizText\", \"Previous\" )' onmouseout='update( \"wizText\", \"&nbsp;\" )'>&nbsp;" )
+        if currSheet > 0:
+            request.write( "<img src='images/previous.png' onclick='doOp( \"prev\" )' onmouseover='update( \"wizText\", \"Previous\" )' onmouseout='update( \"wizText\", \"&nbsp;\" )'>&nbsp;" )
         if currSheet < ( len( self.sheets ) - 2 ):        
             request.write( "<img src='images/next.png' onclick='doOp( \"next\" )' onmouseover='update( \"wizText\", \"Next\" )' onmouseout='update( \"wizText\", \"&nbsp;\" )'>" )
         elif currSheet == ( len( self.sheets ) - 2 ):
@@ -61,13 +61,13 @@ class Wizard( HTMLBase ):
         request.write( "</td></tr></table>" )
         
     def op_next( self, request ):
-    	pass
+        pass
         
     def op_prev( self, request ):
-    	pass
+        pass
         
     def op_finish( self, request ):
-    	pass  
+        pass  
         
 class Sheet( HTMLBase ):
 
@@ -80,9 +80,9 @@ class Sheet( HTMLBase ):
         self.passback = None
         
     def parseForm( self, request ):
-    	do_not_parse = [ 'mod', 'op', 'sheet', 'passback' ] 
+        do_not_parse = [ 'mod', 'op', 'sheet', 'passback' ] 
     
-    	passed_back = request.args
+        passed_back = request.args
         
         temp_passback = passed_back.get( "passback" )
         
@@ -105,18 +105,18 @@ class Sheet( HTMLBase ):
         
     def write_BODY( self, request, err ):
     
-    	if not self.passback: self.parseForm( request )
+        if not self.passback: self.parseForm( request )
         
-   	request.write( "<p>%s</p>" % self.title )
+        request.write( "<p>%s</p>" % self.title )
     
-    	previous_values = ssxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
+        previous_values = ssxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
         
         request.write( "<table width='100%' cellpadding='0' cellspacing='1' border='0'>" )
         
-    	for (feild, control) in self.feilds:
+        for (feild, control) in self.feilds:
             control.write_Control( request, previous_values.get( feild ) )
             if err and not control.validate( previous_values.get( feild ) ):
-            	control.write_Help( request )
+                control.write_Help( request )
             
         request.write( "</table>" )
             
@@ -125,18 +125,18 @@ class Sheet( HTMLBase ):
         request.write( "<input type='hidden' name='visited-sheet%s' value='True'></p>" % self.location )
                 
     def addControl( self, control ):
-    	self.feilds.append( [ control.getName(), control ] )
+        self.feilds.append( [ control.getName(), control ] )
         
     def validate( self, request ):
     
         if not self.passback: self.parseForm( request )
             
-    	check = True
+        check = True
         
         previous_values = ssxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
-    	if DEBUG: print previous_values
+        if DEBUG: print previous_values
       
-      	for (feild, control) in self.feilds:
+        for (feild, control) in self.feilds:
             if not control.validate( previous_values.get( feild ) ):
                 check = False
                 if DEBUG: print "> %s = %s" % (feild, previous_values.get( feild ))
@@ -158,16 +158,16 @@ class SheetControl( HTMLBase ):
         request.write( " %s</p></td></tr>" % self.reg_exp )
         
     def validate( self, persistedValue ):
-    	if persistedValue is None:
+        if persistedValue is None:
             persistedValue = ""
             
         return not re.compile( self.reg_exp ).match( persistedValue ) is None
 
     def getName( self ):
-    	return self.name
+        return self.name
         
     def setName( self, name ):
-    	self.name = name
+        self.name = name
         
 class InputControl( SheetControl ):
 
@@ -180,7 +180,7 @@ class InputControl( SheetControl ):
         self.help_text = help_text
         
     def write_Control( self, request, persistedValue ):
-    	if persistedValue is None:
+        if persistedValue is None:
             persistedValue = self.defaultValue
         
         request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'><input size='40'type='text' name='%s' value=\"%s\"></td></tr>" % (self.humanText, self.getName(), persistedValue) )
@@ -192,35 +192,35 @@ class InputControl( SheetControl ):
 class TextControl( SheetControl ):
 
     def __init__( self, text ):
-    	SheetControl.__init__( self )
+        SheetControl.__init__( self )
         self.text = text
         
     def write_Control( self, request, persistedValue ):
-    	request.write( "<tr><td colspan='2'><p>%s</p></td></tr>" % self.text )
+        request.write( "<tr><td colspan='2'><p>%s</p></td></tr>" % self.text )
 
 class SmallTextControl( SheetControl ):
 
     def __init__( self, text ):
-    	SheetControl.__init__( self )
+        SheetControl.__init__( self )
         self.text = text
         
     def write_Control( self, request, persistedValue ):
-    	request.write( "<tr><td colspan='2'><p class='small'>%s</p></tr></td>" % self.text )
+        request.write( "<tr><td colspan='2'><p class='small'>%s</p></tr></td>" % self.text )
         
 class ListControl( SheetControl ):
 
     def __init__( self, name, options, humanText ):
-    	SheetControl.__init__( self )
+        SheetControl.__init__( self )
         self.setName( name )
         self.options = options
         self.humanText = humanText
         
     def write_Control( self, request, persistedValue ):
         request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'>" % self.humanText )
-    	request.write( "<select name='%s'>" % self.getName() )
+        request.write( "<select name='%s'>" % self.getName() )
         for (value, text) in self.options:
             if value == persistedValue:
-            	request.write( "<option value='%s' selected>%s\n" % (value, text) )
+                request.write( "<option value='%s' selected>%s\n" % (value, text) )
             else:
                 request.write( "<option value='%s'>%s\n" % (value, text) )
         request.write( "</select></td></tr>" )
@@ -235,7 +235,7 @@ class ListControl( SheetControl ):
 class FileControl( InputControl ):
 
     def __init__( self, name, defaultValue, humanText,  reg_exp = ".*", help_text = "You must enter the appropriate details in this feild." ):
-	InputControl.__init__( self, name, defaultValue, humanText )
+        InputControl.__init__( self, name, defaultValue, humanText )
         
     def validate( self, persistedValue ):
         if persistedValue is None: return False
@@ -260,9 +260,9 @@ class TickControl( SheetControl ):
         request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'>" % self.humanText )
         
         if persistedValue == 'True':
-    	    request.write( "<input type='checkbox' name='%s' value='True' checked>" % self.getName() )
+            request.write( "<input type='checkbox' name='%s' value='True' checked>" % self.getName() )
         else:
-    	    request.write( "<input type='checkbox' name='%s' value='True'>" % self.getName() )
+            request.write( "<input type='checkbox' name='%s' value='True'>" % self.getName() )
             
         request.write( "</select></td></tr>" )
 
===== tools/python/xen/sv/util.py 1.10 vs edited =====
--- 1.10/tools/python/xen/sv/util.py	2004-08-16 22:04:37 +09:00
+++ edited/tools/python/xen/sv/util.py	2005-05-19 02:45:57 +09:00
@@ -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 =====
--- 1.3/tools/python/xen/web/SrvBase.py	2005-04-27 23:04:43 +09:00
+++ edited/tools/python/xen/web/SrvBase.py	2005-05-19 02:47:31 +09:00
@@ -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 =====
--- 1.3/tools/python/xen/web/SrvDir.py	2005-04-27 23:04:43 +09:00
+++ edited/tools/python/xen/web/SrvDir.py	2005-05-19 02:47:54 +09:00
@@ -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 =====
--- 1.9/tools/python/xen/xend/EventServer.py	2005-04-23 02:07:04 +09:00
+++ edited/tools/python/xen/xend/EventServer.py	2005-05-19 03:02:47 +09:00
@@ -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 =====
--- 1.6/tools/python/xen/xend/PrettyPrint.py	2005-05-17 18:03:48 +09:00
+++ edited/tools/python/xen/xend/PrettyPrint.py	2005-05-19 02:59:42 +09:00
@@ -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 =====
--- 1.48/tools/python/xen/xend/XendClient.py	2005-05-13 00:04:55 +09:00
+++ edited/tools/python/xen/xend/XendClient.py	2005-05-19 02:58:16 +09:00
@@ -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 =====
--- 1.75/tools/python/xen/xend/XendDomain.py	2005-05-19 00:33:39 +09:00
+++ edited/tools/python/xen/xend/XendDomain.py	2005-05-19 03:13:20 +09:00
@@ -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 =====
--- 1.7/tools/python/xen/xend/encode.py	2005-05-18 07:28:24 +09:00
+++ edited/tools/python/xen/xend/encode.py	2005-05-19 02:54:54 +09:00
@@ -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 =====
--- 1.16/tools/python/xen/xend/sxp.py	2005-05-18 07:28:24 +09:00
+++ edited/tools/python/xen/xend/sxp.py	2005-05-19 02:54:13 +09:00
@@ -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 =====
--- 1.38/tools/python/xen/xend/server/SrvDomain.py	2005-05-13 00:04:55 +09:00
+++ edited/tools/python/xen/xend/server/SrvDomain.py	2005-05-19 02:49:18 +09:00
@@ -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 =====
--- 1.52/tools/python/xen/xm/main.py	2005-05-13 00:04:56 +09:00
+++ edited/tools/python/xen/xm/main.py	2005-05-19 02:53:11 +09:00
@@ -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)
 

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-18 18:58 [PATCH] replace tabs with spaces of Python code aq
@ 2005-05-18 19:59 ` Jacob Gorm Hansen
  2005-05-19  0:48   ` aq
  0 siblings, 1 reply; 12+ messages in thread
From: Jacob Gorm Hansen @ 2005-05-18 19:59 UTC (permalink / raw)
  To: aq; +Cc: xen-devel

aq wrote:
> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH] replace tabs with spaces of Python code
@ 2005-05-18 20:06 Ian Pratt
  2005-05-18 20:21 ` Vincent Hanquez
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Ian Pratt @ 2005-05-18 20:06 UTC (permalink / raw)
  To: aq, xen-devel

 

> 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.
> 
> Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>

Are you sure python interprets a tab as a 4 spaces? I thought it
interpretted it as 8?

Hmm, there are a whole bunch of outstanding xend patches this this is
going to create merge hell for, so I'm not sure we want to apply this
straight away.

Could you just post the script you used, or did you just do the obvious
sed invocation?

Thanks,
Ian

> 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(-)
> 
> --
> regards,
> aq
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-18 20:06 Ian Pratt
@ 2005-05-18 20:21 ` Vincent Hanquez
  2005-05-18 20:43 ` Anthony Liguori
  2005-05-19  1:09 ` aq
  2 siblings, 0 replies; 12+ messages in thread
From: Vincent Hanquez @ 2005-05-18 20:21 UTC (permalink / raw)
  To: Ian Pratt; +Cc: xen-devel

On Wed, May 18, 2005 at 09:06:37PM +0100, Ian Pratt wrote:
> Hmm, there are a whole bunch of outstanding xend patches this this is
> going to create merge hell for, so I'm not sure we want to apply this
> straight away.

The patch looks OK anyway.

-- 
Vincent Hanquez

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-18 20:06 Ian Pratt
  2005-05-18 20:21 ` Vincent Hanquez
@ 2005-05-18 20:43 ` Anthony Liguori
  2005-05-19  1:09 ` aq
  2 siblings, 0 replies; 12+ messages in thread
From: Anthony Liguori @ 2005-05-18 20:43 UTC (permalink / raw)
  To: Ian Pratt; +Cc: xen-devel

[-- Attachment #1: Type: text/plain, Size: 2800 bytes --]

Ian Pratt wrote:

> 
>
>  
>
>>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.
>>
>>Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>
>>    
>>
>
>Are you sure python interprets a tab as a 4 spaces? I thought it
>interpretted it as 8?
>  
>
It's not that simple.  Check out 2.1.8 of the python language spec.

http://docs.python.org/ref/indentation.html

Tabs are expanded to the next 8 character column.  The following script 
expands tabs as described in the python standard.  I don't know how to 
do tab expansion in sed.

Regards,

Anthony Liguori

Signed-off-by: Anthony Liguori

>Hmm, there are a whole bunch of outstanding xend patches this this is
>going to create merge hell for, so I'm not sure we want to apply this
>straight away.
>
>Could you just post the script you used, or did you just do the obvious
>sed invocation?
>
>Thanks,
>Ian
>
>  
>
>>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(-)
>>
>>--
>>regards,
>>aq
>>
>>    
>>
>
>_______________________________________________
>Xen-devel mailing list
>Xen-devel@lists.xensource.com
>http://lists.xensource.com/xen-devel
>
>  
>


[-- Attachment #2: tab2space.py --]
[-- Type: application/x-python, Size: 507 bytes --]

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-18 19:59 ` Jacob Gorm Hansen
@ 2005-05-19  0:48   ` aq
  0 siblings, 0 replies; 12+ messages in thread
From: aq @ 2005-05-19  0:48 UTC (permalink / raw)
  To: Jacob Gorm Hansen; +Cc: xen-devel

On 5/19/05, Jacob Gorm Hansen <jacobg@diku.dk> wrote:
> aq wrote:
> > 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-18 20:06 Ian Pratt
  2005-05-18 20:21 ` Vincent Hanquez
  2005-05-18 20:43 ` Anthony Liguori
@ 2005-05-19  1:09 ` aq
  2 siblings, 0 replies; 12+ messages in thread
From: aq @ 2005-05-19  1:09 UTC (permalink / raw)
  To: Ian Pratt; +Cc: xen-devel

On 5/19/05, Ian Pratt <m+Ian.Pratt@cl.cam.ac.uk> wrote:
> 
> 
> > 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.
> >
> > Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>
> 
> Are you sure python interprets a tab as a 4 spaces? I thought it
> interpretted it as 8?

i investigated all the related code (not quite many), and they all use
4 spaces to indent. and in the above message, i didnt say that i
convert tab to 4 spaces, either. see below why.

> 
> Hmm, there are a whole bunch of outstanding xend patches this this is
> going to create merge hell for, so I'm not sure we want to apply this
> straight away.
> 
not many Python files mixed with tabs, and we can check to fix them
all. this should be cosidered bug, so no matter how hard it is, we
must fix it finally. we cannot avoid this.

mixing tabs and spaces is a *very*  serious problem, if you care. when
i reviewed code in my editor (vim in this case), almost all lines
which have tabs dont look right to me. some even mislead me, and only
when i turn on the hidden chars (":set list" in vim), i realized that
there were tabs inside. ouch!

> Could you just post the script you used, or did you just do the obvious
> sed invocation?
> 

actually, i did this job manually, with little help from one small
script. the reasons are:
- as you said, it is very dangeurous to do this kind of thing
automatically, so it is best to do it by hand
- the number of related files are not that many (21 files with nearly
150 related lines of code)
- some files use tab as 8 spaces, some use tab as 4 spaces, some even
mixed 4 and 8 spaces (checking by seeing the code structure). so it is
another reason not to do it automatically by a script.

Ian, it is a mistake if you dont get this patch. besides, the patch is
rather small, and you can check to see if it is OK.

below is a trivial script i used to indentify all tabs, so i dont miss
any thing. i post here, incase it is helpful for somebody.

regards,
aq

####
#! /usr/bin/env python

import sys, os

def main():
    for filename in sys.argv[1:]:
        if os.path.isdir(filename):
            continue
        data = open(filename, "rb").read()
        if '\0' in data:
            continue
        if data.find("\t") != -1:
            lines = data.split('\n')
            print filename
            n = 0
            for l in lines:
                n += 1
                if l.find('\t') != -1:
                    print '\t', n, '\t', l

if __name__ == '__main__':
    main()

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH] replace tabs with spaces of Python code
@ 2005-05-19  1:28 Ian Pratt
  2005-05-19  2:40 ` aq
  2005-05-19 17:53 ` David Hopwood
  0 siblings, 2 replies; 12+ messages in thread
From: Ian Pratt @ 2005-05-19  1:28 UTC (permalink / raw)
  To: aq; +Cc: xen-devel

> actually, i did this job manually, with little help from one 
> small script. the reasons are:
> - as you said, it is very dangeurous to do this kind of thing 
> automatically, so it is best to do it by hand

No, I think I'd rather it was done automatically, by a script that
interprets white space the same way that python does. 
The script from python.org that Anthony posted seems to fit the bill.

It would be very interesting to compare the output of the script against
your patch, to find out whether you fixed any bugs (or introduced any
:-)

> Ian, it is a mistake if you dont get this patch. besides, the 
> patch is rather small, and you can check to see if it is OK.

I agree that getting rid of the tabs is important, but it can happen
after some of the outstanding tools merges get completed. Of course, if
in doing the conversion you find bugs, that's a different matter...

Ian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-19  1:28 Ian Pratt
@ 2005-05-19  2:40 ` aq
  2005-05-19  9:17   ` Christian Limpach
  2005-05-19 17:53 ` David Hopwood
  1 sibling, 1 reply; 12+ messages in thread
From: aq @ 2005-05-19  2:40 UTC (permalink / raw)
  To: Ian Pratt; +Cc: xen-devel

On 5/19/05, Ian Pratt <m+Ian.Pratt@cl.cam.ac.uk> wrote:
> > actually, i did this job manually, with little help from one
> > small script. the reasons are:
> > - as you said, it is very dangeurous to do this kind of thing
> > automatically, so it is best to do it by hand
> 
> No, I think I'd rather it was done automatically, by a script that
> interprets white space the same way that python does.

of course it is fine if we have that kind of tool. but when we have no
such one, we can fix them all by hand, and from then on (in the
future) double check all the new python code before pushing them into
repo, so we can make sure no such a problem ever occur again.

as i said, since the patch is pretty small, we can afford to check it by hand.

> The script from python.org that Anthony posted seems to fit the bill.

no, that script doesnt work very well, because:
1. almost all the code indented by 4 spaces, but his script convert
tab to 8 spaces
2. some code consider tab as 4 and 8 spaces in the same file, so it is
hard to use this script.
3. that script doesnt see how python deal with the code. for example,
lines the python code is aligned with the previous line, but the
script doesnt take that into account. that is a problem.

a small example: file tools/python/xen/xm/main.py has few tabs inside,
and here is how Anthony's script converts the code, and it does it
wrongly. i have 3 files to compare here, so you can make a conclusion:
the main.org.py (copy from original main.py), main-t2s.py (converted
with Anthony's script, with tabsize=4) and main-aq.py (my script,
coverted manually)

now to see the problem, here is a hunk taken from the diffs. see the
commented i put next to the broken line:

$ diff -Nurp main.org.py main-t2s.py
--- main.org.py 2005-05-19 10:59:54.000000000 +0900
+++ main-t2s.py 2005-05-19 10:58:42.000000000 +0900
@@ -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)               <==== wrongly indented
         p = self.getprog(args[1], self.unknown)
         if help or len(args) < 2: 
             p.help(args[1:])

in the above code, the first tab is considered 4 spaces, but the
second is considered 8 spaces. then problem arises with the Anthony's
script.


$ diff -Nurp main.org.py main-aq.py 
--- main.org.py 2005-05-19 10:59:54.000000000 +0900
+++ main-aq.py  2005-05-19 11:01:20.000000000 +0900
@@ -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:])

everything is fine with main-aq.py

and here is a hunk got from diff between main-t2s.py and main-aq.py.
cleary they are not same.

$ diff -Nurp main-aq.py main-t2s.py 
--- main-aq.py  2005-05-19 11:01:20.000000000 +0900
+++ main-t2s.py 2005-05-19 10:58:42.000000000 +0900
@@ -143,7 +143,7 @@ class Xm:
         self.name = args[0]
         if len(args) < 2:
             args.append('help')
-        help = self.helparg(args)
+    help = self.helparg(args)
         p = self.getprog(args[1], self.unknown)
         if help or len(args) < 2: 
             p.help(args[1:])


> I agree that getting rid of the tabs is important, but it can happen
> after some of the outstanding tools merges get completed.

i think it is better to do it now, when there are not much code having
problem. in the future, code get bigger, so it is more difficult to
convert and check everything.

regards,
aq

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-19  2:40 ` aq
@ 2005-05-19  9:17   ` Christian Limpach
  2005-05-19 11:49     ` aq
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Limpach @ 2005-05-19  9:17 UTC (permalink / raw)
  To: aq; +Cc: Ian Pratt, xen-devel

On 5/19/05, aq <aquynh@gmail.com> wrote:
> > The script from python.org that Anthony posted seems to fit the bill.
> 
> no, that script doesnt work very well, because:
> 1. almost all the code indented by 4 spaces, but his script convert
> tab to 8 spaces
> 2. some code consider tab as 4 and 8 spaces in the same file, so it is
> hard to use this script.
> 3. that script doesnt see how python deal with the code. for example,
> lines the python code is aligned with the previous line, but the
> script doesnt take that into account. that is a problem.
> 
> a small example: file tools/python/xen/xm/main.py has few tabs inside,
> and here is how Anthony's script converts the code, and it does it
> wrongly. i have 3 files to compare here, so you can make a conclusion:
> the main.org.py (copy from original main.py), main-t2s.py (converted
> with Anthony's script, with tabsize=4) and main-aq.py (my script,
> coverted manually)
> 
> now to see the problem, here is a hunk taken from the diffs. see the
> commented i put next to the broken line:

That's because you broke the script by changing tabsize to 4.  As
Anthony wrote, the python manual describes the algorithm used to
expand tabs and how tabs get expanded has nothing to with how you have
indented your program.  Whether your indention levels are 4 character
wide or 8 doesn't matter, a tab always means go to the next 8
character column.  The original main.py looks visually incorrect at
the args.append line (it's indented by 8 characters instead of 4) but
that's not a bug.

> > I agree that getting rid of the tabs is important, but it can happen
> > after some of the outstanding tools merges get completed.
> 
> i think it is better to do it now, when there are not much code having
> problem. in the future, code get bigger, so it is more difficult to
> convert and check everything.

I'm not too keen on seeing this done in any of the 2.0 trees.

    christian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-19  9:17   ` Christian Limpach
@ 2005-05-19 11:49     ` aq
  0 siblings, 0 replies; 12+ messages in thread
From: aq @ 2005-05-19 11:49 UTC (permalink / raw)
  To: Christian.Limpach; +Cc: Ian Pratt, xen-devel

On 5/19/05, Christian Limpach <christian.limpach@gmail.com> wrote:
> On 5/19/05, aq <aquynh@gmail.com> wrote:
> > > The script from python.org that Anthony posted seems to fit the bill.
> >
> > no, that script doesnt work very well, because:
> > 1. almost all the code indented by 4 spaces, but his script convert
> > tab to 8 spaces
> > 2. some code consider tab as 4 and 8 spaces in the same file, so it is
> > hard to use this script.
> > 3. that script doesnt see how python deal with the code. for example,
> > lines the python code is aligned with the previous line, but the
> > script doesnt take that into account. that is a problem.
> >
> > a small example: file tools/python/xen/xm/main.py has few tabs inside,
> > and here is how Anthony's script converts the code, and it does it
> > wrongly. i have 3 files to compare here, so you can make a conclusion:
> > the main.org.py (copy from original main.py), main-t2s.py (converted
> > with Anthony's script, with tabsize=4) and main-aq.py (my script,
> > coverted manually)
> >
> > now to see the problem, here is a hunk taken from the diffs. see the
> > commented i put next to the broken line:
> 
> That's because you broke the script by changing tabsize to 4.  As
> Anthony wrote, the python manual describes the algorithm used to
> expand tabs and how tabs get expanded has nothing to with how you have
> indented your program.  Whether your indention levels are 4 character
> wide or 8 doesn't matter, a tab always means go to the next 8
> character column.  The original main.py looks visually incorrect at
> the args.append line (it's indented by 8 characters instead of 4) but
> that's not a bug.

Yes, I agree. Actually Anthony's script (with tabsize=8) can be used
to convert all related Python files, and the result code would work
like before.But since all the code originally indented with 4 spaces,
then we should still readjust some code a little bit.

If you want to play safely, I would rather use that script to remove
tabs completely, than leave them as they are now (not buggy but
*evil*).

regards,
aq

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] replace tabs with spaces of Python code
  2005-05-19  1:28 Ian Pratt
  2005-05-19  2:40 ` aq
@ 2005-05-19 17:53 ` David Hopwood
  1 sibling, 0 replies; 12+ messages in thread
From: David Hopwood @ 2005-05-19 17:53 UTC (permalink / raw)
  To: xen-devel

Ian Pratt wrote:
>>actually, i did this job manually, with little help from one 
>>small script. the reasons are:
>>- as you said, it is very dangeurous to do this kind of thing 
>>automatically, so it is best to do it by hand
> 
> No, I think I'd rather it was done automatically, by a script that
> interprets white space the same way that python does.

That assumes that the use of tabs is currently correct.

-- 
David Hopwood <david.nospam.hopwood@blueyonder.co.uk>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-05-19 17:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-18 18:58 [PATCH] replace tabs with spaces of Python code aq
2005-05-18 19:59 ` Jacob Gorm Hansen
2005-05-19  0:48   ` aq
  -- strict thread matches above, loose matches on Subject: below --
2005-05-18 20:06 Ian Pratt
2005-05-18 20:21 ` Vincent Hanquez
2005-05-18 20:43 ` Anthony Liguori
2005-05-19  1:09 ` aq
2005-05-19  1:28 Ian Pratt
2005-05-19  2:40 ` aq
2005-05-19  9:17   ` Christian Limpach
2005-05-19 11:49     ` aq
2005-05-19 17:53 ` David Hopwood

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.