やっつけスクリプト
必要に迫られて書きました。対象1500ファイル超は、さすがに手作業では無理・・・・・・。
指定したディレクトリをルートとして、このディレクトリ以下のすべての java ファイルに対して class のコメントを編集します。
具体的には、これを
/** * Action の基底クラスです。<br> * すべての Action は、このクラスを継承します。 * * @author foo */ public abstract class BaseActionSupport extends ActionSupport {
こうします。
/** * Action の基底クラスです。<br> * すべての Action は、このクラスを継承します。 * * @author foo * @version $Revision$ * Copyright: (C) xxxxxxxxxx All Right Reserved. */ public abstract class BaseActionSupport extends ActionSupport {
pythonで書きました。
# -*- coding: sjis -*- import shutil import os import time ### functions def search_author_tag(filename): cnt = 0 mark = 0 for line in file(filename, 'r'): cnt += 1 if line.startswith(' * @author'): mark = cnt return mark def copy_file(filename, srcdir, destdir): if not srcdir.endswith('\\'): srcdir += '\\' if not destdir.endswith('\\'): destdir += '\\' shutil.copy2(srcdir + filename, destdir + filename) return destdir + filename def set_version(): return ' * @version $Revision$' def set_copyright(): return ' * Copyright: (C) xxxxxxxxxx All Right Reserved.' def append_comment(filepath, mark): reader = file(filepath, 'r') buf = '' cnt = 0 for line in reader: cnt += 1 buf += line if cnt == mark: buf += set_version() + '\n' buf += set_copyright() + '\n' reader.close() writer = file(filepath, 'w') writer.write(buf) writer.close() ### variables rootdir = 'D:\\all-in-one-eclipse\\workspace\\someproject\\src\\' backupdir_base = 'D:\\backup$date$\\' backupdir = backupdir_base.replace('$date$', time.strftime('%y%m%d_%H%M%S')) ### main for root, dirs, files in os.walk(rootdir): newdir = root.replace(rootdir, backupdir, 1) if not '\\CVS' in newdir: os.makedirs(newdir) print 'Create: ' + newdir for fileentry in files: if fileentry.endswith('.java'): # copy destpath = copy_file(fileentry, root, newdir) print 'Copy: ' + root + '\\' + fileentry + ' -> ' + destpath # set doc-comment marker = search_author_tag(destpath) print 'Info: ' + destpath + ': line ' + str(marker) + ': ' + ' @author タグを検出しました。' append_comment(destpath, marker)