[Python] JavaEE project update package packaging tool, pythonjavaee

Source: Internet
Author: User

[Python] JavaEE project update package packaging tool, pythonjavaee

The only Python script recommended by someone has been clicked. Well, should I issue some ready-made script tools?

 

First, let's talk about the production environment of this item.

People are in outsourcing companies, and there is no such thing as a small scale.

After the Java Web project is deployed, you must update the code and manually copy the changed file to the server to replace it. In particular, If you change a bunch of bugs to Java, when JSP files are dozens or even more... it is quite painful to manually find the compiled class from Tomcat.

But I also said that there are no specifications, and there are no ready-made tools... As a result, I want to write a script to automatically package it.

 

The Enterprise project is mainly Eclipse + SVN, and SVN uses sqlite3 as the local data storage to store the file change list. Then SVN can be used to conveniently and quickly obtain file update information.

Because the project file structures of different ides are different, this script can only be used for applications in the same environment (Eclipse + SVN ).

The usage is very simple. Enter the SVN project directory/package start version/Tomcat application directory/generate a different directory as prompted, the system will automatically read all file changes from the SVN version to the last version, and go to Tomcat to find the corresponding file (class/jsp, etc ), copy the file to the corresponding location of the generated differential directory. At last, you only need to back up the original application, paste and replace the entire folder, and restart the file.

I have never learned anything about Python. Just ignore the variable name and specification ....

Import sqlite3import tracebackimport osimport OS. pathfrom shutil import copy # this tool is used based on SVN file change records, automatically copy and change the class to the Tomcat directory to facilitate the creation of update packages # Only Eclipse projects are supported (the directory structure of the project files created by different ides is different) # def addLog (oldlog, logtext): print (logtext) return oldlog + "\ n" + logtextdef getDirByPath (dirpath): return dirpath [0: dirpath. rindex ("/")] def getFilenameByPath (dirpath): return dirpath [dirpath. rindex ("/") + 1: len (dirpath)] def myCopyFile (c_srcfile, C_desfile): if (OS. path. exists (c_srcfile) = False): return False if (OS. path. exists (getDirByPath (c_desfile) = False): OS. makedirs (getDirByPath (c_desfile) # If the class automatically traverses related internal classes, if yes, copy ClassName $ xxx together. class Format File tmpfile = getFilenameByPath (c_srcfile) if (tmpfile. endswith (". class "): tmpdir = getDirByPath (c_srcfile) tmpfile = tmpfile [0: len (tmpfile)-6] +" $ "for d in OS. listdir (tmpdir): if (d. start Swith (tmpfile): copy (tmpdir + "/" + d, getDirByPath (c_desfile) + "/" + d) copy (c_srcfile, c_desfile) return Trueprint ("welcome to the SVN difference automatic packaging script, the following requires that no \ symbol at the end of the input path") print ("this script is only applicable to Eclipse Java EE projects ") print ("all internal classes will be copied. If necessary, manually delete redundant internal classes") path = input ("Enter the SVN project directory:") try: cx = sqlite3.connect (path + "\\. svn \ wc. db ") cu = cx. cursor () ver = input ("Enter the package version:") cu.exe cute ("select local_relpath, changed_revision from NODES where kind = 'File' and changed_revision> = "+ ver +" order by changed_revision ") srcpath = input (" Enter the Tomcat project folder :") despath = input ("Enter the location of the differential file:") log = "" log = addLog (log, "[start to process the differential file, starting from version "+ ver +"]: ") while (True): data = cu. fetchone () if (data = None): break # determine the conversion path based on the extension if (data [0]. startswith ("WebContent/"): # srcfile = srcpath + data [0] [10: len (data [0])] desfile = despath + data [0] [10: len (Data [0])] if (myCopyFile (srcfile, desfile): log = addLog (log, "[Processed] [version:" + str (data [1]) + "]" + data [0]) else: print (srcfile) log = addLog (log, "[unprocessed] [version:" + str (data [1]) + "] the file [" + data [0] + "] does not exist! ") Elif (data [0]. startswith ("src/"): # SRC path conversion if (data [0]. endswith ("java"): tmp = data [0] [3: len (data [0])-4] + "class" else: tmp = data [0] [3: len (data [0])] tmp = "/WEB-INF/classes" + tmp srcfile = srcpath + tmp desfile = despath + tmp if (myCopyFile (srcfile, desfile): log = addLog (log, "[Processed] [version:" + str (data [1]) + "]" + data [0]) else: log = addLog (log, "[not processed] [version:" + str (data [1]) + "] File [" + data [0] + "] does not exist! ") Elif (data [0]. startswith ("config/"): # config path conversion srcfile = srcpath + "/WEB-INF/classes" + data [0] [6: len (data [0])] desfile = despath + "/WEB-INF/classes" + data [0] [6: len (data [0])] if (myCopyFile (srcfile, desfile )): log = addLog (log, "[Processed] [version:" + str (data [1]) + "]" + data [0]) else: log = addLog (log, "[unprocessed] [version:" + str (data [1]) + "] File [" + data [0] + "] does not exist! ") Else: # logs written by other resources are not processed at the moment. log = addLog (log," [not processed] [version: "+ str (data [1]) + The file ["+ data [0] +"] in "] cannot be identified. Please handle it manually! ") File_object = open (despath +"/chuli. log ", 'w') file_object.write (log) file_object.close () print (" after the program is executed, the log has been written to ["+ srcpath +" \ chuli. log], please refer to the manual processing [unprocessed] project ") handle T: print (" program execution exception ") traceback as needed. print_exc ()

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.