Commits

Anonymous committed 54b5518

Updated to reindent file prior to upgrading source.

Comments (0)

Files changed (1)

Plug-ins/wx25upgrade.plug-in.py

 import sys
 import string
 
-from ExternalLib import wx25upgrade
+from ExternalLib import wx25upgrade, reindent
+import Utils
 
 def createWx25CodeUpgradeDlg(parent):
     return Wx25CodeUpgradeDlg(parent)
                     temp = 'Converting: %s' % name
                     keepGoing = dlg.Update(count, temp)
                     
-                    fInput = file(os.path.join(self.sourceFolder.GetValue(), name), 'r')
+                    fInputName = os.path.join(self.sourceFolder.GetValue(), name)
+                    fInputLines = file(fInputName, 'r').readlines()
+                    fInputData = self.reindentSource(fInputLines, fInputName)
                     fOutput = file(os.path.join(self.targetFolder.GetValue(), name), 'w')
                     try:
                         frag = []
-                        for non, rep in self.u.scanner(fInput.read()):
+                        for non, rep in self.u.scanner(fInputData):
                             frag.append(non)
                             frag.append(rep)
                         newtext = string.join(frag, '')
                         fOutput.write(newtext)
                     finally:
-                        fInput.close()
                         fOutput.close()
                         temp = 'Done converting: %s' % name
                         keepGoing = dlg.Update(count, temp)
         outName = newName+'Upg'+ext
         root2, newFileName = os.path.split(outName)
                 
-        fInput = file(self.sourceFile.GetValue(), 'r')
+        fInputName = self.sourceFile.GetValue()
+        fInputLines = file(fInputName, 'r').readlines()
+        fInputData = self.reindentSource(fInputLines, fInputName)
+
         fOutput = file(outName, 'w')
 
         temp = 'Converting: %s,\n\nto: %s' % (fileName, newFileName)
         
         try:
             frag = []
-            for non, rep in self.u.scanner(fInput.read()):
+            for non, rep in self.u.scanner(fInputData):
                 frag.append(non)
                 frag.append(rep)
             newtext = string.join(frag, '')
             fOutput.write(newtext)
         finally:
-            fInput.close()
             fOutput.close()
             
             count = count +1
         import webbrowser
         webbrowser.open('http://wiki.wxpython.org/index.cgi/Boa040Upgrade')
 
+    def reindentSource(self, srcLines, filename):
+        data = ''.join(srcLines)
+        eol = Utils.getEOLMode(data)
+        file = SourcePseudoFile(srcLines)
+        ri = reindent.Reindenter(file, eol=eol)
+        try:
+            if ri.run():
+                file.output = []
+                ri.write(file)
 
+                return ''.join(file.output)
+        except Exception, error:
+            print 'Error on reindenting %s : %s'%(filename, str(error))
+
+        return data
+
+class SourcePseudoFile(Utils.PseudoFileOutStore):
+    def readlines(self):
+        return self.output
+    
 #-------------------------------------------------------------------------------
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.