真 もわ爛漫

しゃーら、しゃーらしゃーら

異動した後に書いたコードの行数を調べてみた

mystatなるさぶこまんどを作った。まるでチェックしてないのでバグってたらおせーて。

ああ、ちなみにpassがアホの子のようにあるのはemacsがインデントの処理で利用してくれるから。もっといい方法きぼん。

# Apache らいせんすだじぇ!
from command import PagedCommand
from subprocess import Popen
from subprocess import PIPE
import re
import sys

RE_CHANGE = re.compile(' *\d+ files changed, (\d+) insertions\(\+\), (\d+) deletions')

class Mystat(PagedCommand):
  common = True
  helpSummary = "Show the working tree status"
  helpUsage = """
%prog
"""
  helpDescription = """hogehoge
"""

  def Execute(self, opt, args):
    all = self.GetProjects(args)
    clean = 0

    on = {}
    total_insertion = 0
    total_deletion = 0
    for project in all:
      popen = Popen(['git', ('--git-dir=%s/.git' % project.relpath),
                     'log', '--author=namaehakaetene', '--since=2010-08-06',
                     '--oneline'], stdout=PIPE)
      child_stdout = popen.stdout
      changes = []
      for line in child_stdout:
        changes.append(line.strip()[:7])
        pass
      popen.wait()

      subtotal_insertion = 0
      subtotal_deletion = 0
      for change in changes:
        popen = Popen(['git', ('--git-dir=%s/.git' % project.relpath),
                       'show', '--stat', change], stdout=PIPE)
        child_stdout = popen.stdout
        for line in child_stdout:
          m = RE_CHANGE.match(line)
          if m:
            subtotal_insertion += int(m.group(1))
            subtotal_deletion += int(m.group(2))
          else:
            if line.find('change') >= 0 and line.find('insertion') >= 0:
              print >>sys.stderr, 'suspicious line found: ' + line
              sys.exit(1)
              pass
            pass
          pass
        pass

      if subtotal_insertion > 0 or subtotal_deletion> 0:
        print ('%10s: insertion: %d, deletion: %d' %
               (project.name, subtotal_insertion, subtotal_deletion))
        total_insertion += subtotal_insertion
        total_deletion += subtotal_deletion
        pass
      pass
    print ('total: insertion: %d, deletion: %d' %
           (total_insertion, total_deletion))
    pass

結果を貼ろうかと思ったのだけど大層微妙なことになってたのでやめ。

あ、動かない?あ、どうやって使うか分からない? 諦めなさい