<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: ooad code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 20 Aug 2008 16:45:46 GMT</pubDate>
    <description>DZone Snippets: ooad code</description>
    <item>
      <title>Applying Python to modify Java code</title>
      <link>http://snippets.dzone.com/posts/show/5240</link>
      <description>Python script intended to open each Java's project file, add the license term on the start of the file as a Java comment and writing it to the disk.&lt;br /&gt;&lt;br /&gt;1) You'll need a Python interpreter. Check this out in http://python.org.&lt;br /&gt;2) You'll need to enter the root file directory of the Java project, like &lt;pre&gt;python AddLicense.py ${path}&lt;/pre&gt; where ${path} defines user project root directory.&lt;br /&gt;3) See http://fcmanager.wiki.sourceforge.net&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; 1:# Python script to add the LGPL notices to each java file of the FileContentManager project.&lt;br /&gt; 2:import os, glob, sys&lt;br /&gt; 3:License = """\&lt;br /&gt; 4:/**&lt;br /&gt; 5:*FileContentManager is a Java based file manager desktop application, &lt;br /&gt; 6:*it can show, edit and manipulate the content of the files archived inside a zip.&lt;br /&gt; 7:*&lt;br /&gt; 8:*Copyright (C) 2008 &lt;br /&gt; 9:*&lt;br /&gt;10:*Created by Camila Sanchez [http://mimix.wordpress.com/], Rafael Naufal [http://rnaufal.livejournal.com] &lt;br /&gt;11:and Rodrigo [rdomartins@gmail.com]&lt;br /&gt;12:*&lt;br /&gt;13:*FileContentManager is free software; you can redistribute it and/or&lt;br /&gt;14:*modify it under the terms of the GNU Lesser General Public&lt;br /&gt;15:*License as published by the Free Software Foundation; either&lt;br /&gt;16:*version 2.1 of the License, or (at your option) any later version.&lt;br /&gt;17:*&lt;br /&gt;18:*This library is distributed in the hope that it will be useful,&lt;br /&gt;19:*but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;20:*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;21:*Lesser General Public License for more details.&lt;br /&gt;22:*&lt;br /&gt;23:*You should have received a copy of the GNU Lesser General Public&lt;br /&gt;24:*License along with FileContentManager; if not, write to the Free Software&lt;br /&gt;25:*Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """&lt;br /&gt;26:&lt;br /&gt;27:size = len(sys.argv)&lt;br /&gt;28:if size == 1 or size &gt; 2:&lt;br /&gt;29:    print "Usage: AddLicense.py $1"&lt;br /&gt;30:    sys.exit(1)&lt;br /&gt;31:inputPath = sys.argv[1]&lt;br /&gt;32:if not os.path.exists(inputPath):&lt;br /&gt;33:    print inputPath, "does not exist on disk"&lt;br /&gt;34:    sys.exit(1)&lt;br /&gt;35:if not os.path.isdir(inputPath):&lt;br /&gt;36:    print inputPath, "isn't a dir"&lt;br /&gt;37:    sys.exit(1)   &lt;br /&gt;38:for path, dirs, files in os.walk(inputPath):&lt;br /&gt;39:    fileWithLicense = ''&lt;br /&gt;40:    for filepath in [ os.path.join(path, f)&lt;br /&gt;41:            for f in files if f.endswith(".java")]:&lt;br /&gt;42:        content = file(filepath).read()&lt;br /&gt;43:        f = file(filepath, "w")&lt;br /&gt;44:        print &gt;&gt;f, License + "\n" + content&lt;br /&gt;45:        f.close()&lt;br /&gt;46:        &lt;br /&gt;47:    &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 17 Mar 2008 11:54:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5240</guid>
      <author>rnaufal (Rafael Naufal)</author>
    </item>
  </channel>
</rss>
