Chromium Code Reviews| Index: utils/tree-prune.py |
| =================================================================== |
| --- utils/tree-prune.py (revision 0) |
| +++ utils/tree-prune.py (revision 0) |
| @@ -0,0 +1,82 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +""" A tool for listing branches with closed and abandoned issues.""" |
| + |
| +import os |
| +import sys |
| + |
| +try: |
|
M-A Ruel
2012/03/13 14:16:02
Using this instead;
BASE_DIR = os.path.dirname(os
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + import git_cl |
| +except ImportError: |
| + sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| + import git_cl |
| + |
| +import urllib2 |
|
M-A Ruel
2012/03/13 14:16:02
Keep it grouped with system lib imports
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + |
| +def GetBranches(): |
|
M-A Ruel
2012/03/13 14:16:02
use PEP-8 style function naming, namely;
def get_
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + """Get list of all local git branches.""" |
| + result = [] |
| + for branch_name in git_cl.RunGit(["branch"]).split(): |
|
M-A Ruel
2012/03/13 14:16:02
splitlines()
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + if branch_name != '*': |
|
M-A Ruel
2012/03/13 14:16:02
Use branch_name[3:] instead
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + result.append(Branch(branch_name)) |
| + return result |
|
M-A Ruel
2012/03/13 14:16:02
So in the end, the function looks like this:
retu
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + |
| + |
| +class Branch(git_cl.Changelist): |
| + def __init__(self, name): |
| + git_cl.Changelist.__init__(self, branchref = name) |
|
M-A Ruel
2012/03/13 14:16:02
argument default values don't have space, e.g.
br
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + self._issue_status = None |
| + |
| + def GetStatus(self): |
| + if not self._issue_status: |
| + if self.GetIssue() is not None: |
|
M-A Ruel
2012/03/13 14:16:02
if self.GetIssue():
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + try: |
| + issue_properties = self.RpcServer().get_issue_properties( |
| + self.GetIssue(), None) |
| + if issue_properties['closed']: |
| + self._issue_status = 'closed' |
| + else: |
| + self._issue_status = 'pending' |
| + except urllib2.HTTPError, e: |
| + if e.code == 404: |
| + self._issue_status = 'abandoned' |
| + else: |
| + self._issue_status = 'no-issue' |
| + return self._issue_status |
| + |
|
M-A Ruel
2012/03/13 14:16:02
2 lines between file level symbols
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| +def main(argv): |
| + branches = GetBranches() |
| + filtered = { 'closed' : [], |
| + 'pending' : [], |
| + 'abandoned' : [], |
| + 'no-issue' : []} |
| + |
| + for branch in branches: |
| + filtered[branch.GetStatus()].append(branch) |
| + |
| + print "# Branches with closed issues" |
| + for branch in filtered['closed']: |
| + print "git branch -D %s # Issue %s is closed." % (branch.GetBranch(), |
| + branch.GetIssue()) |
| + |
| + print "\n# Pending Branches" |
| + for branch in filtered['pending']: |
| + print "# Branch %s - Issue %s" % (branch.GetBranch(), branch.GetIssue()) |
| + |
| + |
|
M-A Ruel
2012/03/13 14:16:02
remove extra line
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| + print "\n# Branches with abandoned issues" |
| + for branch in filtered['abandoned']: |
| + print "# Branch %s - was issue %s" % ( |
| + branch.GetBranch(), branch.GetIssue()) |
| + |
| + print "\n# Branches without associated issues" |
| + for branch in filtered['no-issue']: |
| + print "# Branch %s" % (branch.GetBranch()) |
| + |
| + return 0 |
| + |
|
M-A Ruel
2012/03/13 14:16:02
add line
groby-ooo-7-16
2012/03/14 20:39:51
Done.
|
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv[1:])) |
| Property changes on: utils/tree-prune.py |
| ___________________________________________________________________ |
| Added: svn:executable |
| + * |
| Added: svn:eol-style |
| + LF |