Research on Python static Compiler

Source: Internet
Author: User

The Python static compiler compiled by wxPython and pychecker is used to find the py script errors and open source code in the compiler. It is shared with pythoner. I hope this article will help you, let's join in the Python world.

The Code is as follows:

 
 
  1.     def OnBuildOne(self, event):  
  2.         if self.paths.count != 0:  
  3.             self.Report.AppendText(self.CompileInfoHead("File"))  
  4.             path = self.paths[self.List.GetSelection()]  
  5.             print "Building " + path + " ..."  
  6.             try:  
  7.                 py_compile.compile(path, None, None)  
  8.             except py_compile.PyCompileError, ex:  
  9.                 print ex  
  10.             self.Report.AppendText("=-- Build Finished.\n\n")  
  11.  
  12.  
  13.     def OnBuildAll(self, event):  
  14.         if self.paths.count != 0:  
  15.             self.Report.AppendText(self.CompileInfoHead("File(s)"))  
  16.             for path in self.paths:  
  17.                 print "Building " + path + " ..."  
  18.                 try:  
  19.                     py_compile.compile(path, None, None)  
  20.                 except py_compile.PyCompileError, ex:  
  21.                     print ex  
  22.             self.Report.AppendText("=-- Build Finished.\n\n")  
  23.  
  24.  
  25.     def OnBuildDirectory(self, event):  
  26.         dlg = wxDirDialog(self, "Select a directory for build", self.cfg[2])  
  27.         if dlg.ShowModal() == wxID_OK:  
  28.             path = dlg.GetPath()  
  29.             self.Report.AppendText(self.CompileInfoHead("Directory:", path))  
  30.             compile_dir(path, 10, None, 1, None)  
  31.             self.Report.AppendText("=-- Build Finished.\n\n")  
  32.             self.cfg[2] = dlg.GetPath()  
  33.                   
  34.         dlg.Destroy()  
  35.       
  36.  
  37.     def OnAbout(self, event):   
  38.         dlg = wxMessageDialog(self, "Present by Dracula 2005\n"   
  39.                                     "Build 2005.05.05\n", "About",   
  40.                                     wxOK | wxICON_INFORMATION)  
  41.         dlg.ShowModal()  
  42.         dlg.Destroy()  
  43.  
  44.  
  45.     def OnResize(self, event):  
  46.         sizeClient = self.GetClientSize()  
  47.         self.List.SetSize(sizeClient)  
  48.         sizeList = self.List.GetClientSize()  
  49.         self.Report.SetSize(wxSize(sizeClient.width, sizeClient.height-sizeList.height))  
  50.  
  51.  
  52.     def OnClose(self, event):  
  53.         try:  
  54.             f = open("config.cfg", "w")  
  55.             f.write(self.cfg[0])  
  56.             if self.cfg[0][-1] != '\n':  
  57.                 f.write("\n")  
  58.             f.write(self.cfg[1])  
  59.             if self.cfg[1][-1] != '\n':  
  60.                 f.write("\n")  
  61.             f.write(self.cfg[2])  
  62.             f.close()  
  63.         except IOError:  
  64.             pass  
  65.  
  66.         sys.path = self.save_sys_path[:]  
  67.           
  68.         self.timer.Stop()  
  69.         del self.timer   
  70.         del self.icon   
  71.         self.Destroy()  
  72.  
  73.  
  74.     def OnQuit(self, event):  
  75.         self.Close(true)  
  76.  
  77.  
  78.     def PyCheck(self, argv):  
  79.         argv2 = ['pychecker']  
  80.         argv2.append(argv)  
  81.         pychecker.checker2.main(argv2)  
  82.         #reload(pychecker.checker2)  
  83.  
  84.  
  85.     def AddPath(self, path):  
  86.         curdir = path 
  87.         system_dir = curdir + '\\data\\script'  
  88.         system_core_dir = curdir + '\\data\\script\\core'  
  89.         subsystem_dir = curdir + '\\data\\subsystem'  
  90.         subsystem_trashbin_dir = curdir + '\\data\\subsystem\\trashbin'  
  91.  
  92.         sys.path = self.save_sys_path[:]  
  93.         sys.path.append(curdir)  
  94.         sys.path.append(system_dir)  
  95.         sys.path.append(system_core_dir)  
  96.         sys.path.append(subsystem_dir)  
  97.         sys.path.append(subsystem_trashbin_dir)  
  98.  
  99.  
  100.     def CompileInfoHead(self, str1, str2=""):  
  101.         return "=-- %s %s Compile %s %s ...\n" % (self.Date(), self.Time(), str1, str2)  
  102.       
  103.  
  104.     def Error(self, error):  
  105.         self.Report.AppendText(error)  
  106.  
  107.  
  108.     def Output(self, info):  
  109.         self.Report.AppendText(info)  
  110.  
  111.  
  112.     def Date(self):  
  113.         t = time.localtime(time.time())   
  114.         strDate = time.strftime("%Y.%m.%d", t)  
  115.         return strDate  
  116.  
  117.  
  118.     def Time(self):  
  119.         t = time.localtime(time.time())   
  120.         strTime = time.strftime("%I:%M:%S", t)  
  121.         return strTime  
  122.  
  123.  
  124.     def Notify(self):  
  125.         self.statusbar.SetStatusText(self.Date() + "   " + self.Time(), 1)  
  126.  
  127.  
  128. class MyApp(wxApp):  
  129. def OnInit(self):  
  130. self.frame = MyFrame(NULL, -1, "cd2Py Compiler")  
  131. self.frame.Show(true)  
  132. return true   
  133. cd2Py = MyApp(0)  
  134. import sys  
  135. class errCatcher:  
  136. def __init__(self):  
  137. pass  
  138. def write(self, stuff):  
  139. cd2Py.frame.Error(stuff)  
  140. class outCatcher:  
  141. def __init__(self):  
  142. passdef write(self, stuff):  
  143. cd2Py.frame.Output(stuff)  
  144. sys.stderr = errCatcher()  
  145. sys.stdout = outCatcher()  
  146. cd2Py.MainLoop() 
  1. How to embed Python into C ++ applications?
  2. In-depth discussion of Ruby and Python syntax comparison
  3. Introduction to Python
  4. Python Learning Experience: version, IDE selection and coding Solutions
  5. Analysis of Python GIL and thread security

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.