Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: py/utils/misc.py

Issue 346743008: Update common.py.utils to be used in Skia repo (Closed) Base URL: https://skia.googlesource.com/common.git@master
Patch Set: comment Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « py/utils/git_utils.py ('k') | py/utils/shell_utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ This module contains miscellaneous tools used by the buildbot scripts. """ 6 """ This module contains miscellaneous tools. """
7 7
8 import os 8 import os
9 9
10 from git_utils import GIT
11 import shell_utils
12
13 10
14 # Absolute path to the root of this Skia buildbot checkout. 11 # Absolute path to the root of this Skia buildbot checkout.
15 BUILDBOT_PATH = os.path.realpath(os.path.join( 12 BUILDBOT_PATH = os.path.realpath(os.path.join(
16 os.path.dirname(os.path.abspath(__file__)), 13 os.path.dirname(os.path.abspath(__file__)),
17 os.pardir, os.pardir, os.pardir)) 14 os.pardir, os.pardir, os.pardir))
18 15
19 16
20 def ArgsToDict(argv): 17 def ArgsToDict(argv):
21 """ Collect command-line arguments of the form '--key value' into a 18 """ Collect command-line arguments of the form '--key value' into a
22 dictionary. Fail if the arguments do not fit this format. """ 19 dictionary. Fail if the arguments do not fit this format. """
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 self._origin = os.getcwd() 83 self._origin = os.getcwd()
87 if self._verbose: 84 if self._verbose:
88 print 'chdir %s' % self._destination 85 print 'chdir %s' % self._destination
89 os.chdir(self._destination) 86 os.chdir(self._destination)
90 87
91 def __exit__(self, *args): 88 def __exit__(self, *args):
92 """Change back to the original directory.""" 89 """Change back to the original directory."""
93 if self._verbose: 90 if self._verbose:
94 print 'chdir %s' % self._origin 91 print 'chdir %s' % self._origin
95 os.chdir(self._origin) 92 os.chdir(self._origin)
96
97
98 class GitBranch(object):
99 """Class to manage git branches.
100
101 This class allows one to create a new branch in a repository to make changes,
102 then it commits the changes, switches to master branch, and deletes the
103 created temporary branch upon exit.
104 """
105 def __init__(self, branch_name, commit_msg, upload=True, commit_queue=False):
106 self._branch_name = branch_name
107 self._commit_msg = commit_msg
108 self._upload = upload
109 self._commit_queue = commit_queue
110 self._patch_set = 0
111
112 def __enter__(self):
113 shell_utils.run([GIT, 'reset', '--hard', 'HEAD'])
114 shell_utils.run([GIT, 'checkout', 'master'])
115 if self._branch_name in shell_utils.run([GIT, 'branch']):
116 shell_utils.run([GIT, 'branch', '-D', self._branch_name])
117 shell_utils.run([GIT, 'checkout', '-b', self._branch_name,
118 '-t', 'origin/master'])
119 return self
120
121 def commit_and_upload(self, use_commit_queue=False):
122 shell_utils.run([GIT, 'commit', '-a', '-m',
123 self._commit_msg])
124 upload_cmd = [GIT, 'cl', 'upload', '-f', '--bypass-hooks',
125 '--bypass-watchlists']
126 self._patch_set += 1
127 if self._patch_set > 1:
128 upload_cmd.extend(['-t', 'Patch set %d' % self._patch_set])
129 if use_commit_queue:
130 upload_cmd.append('--use-commit-queue')
131 shell_utils.run(upload_cmd)
132
133 def __exit__(self, exc_type, _value, _traceback):
134 if self._upload:
135 # Only upload if no error occurred.
136 try:
137 if exc_type is None:
138 self.commit_and_upload(use_commit_queue=self._commit_queue)
139 finally:
140 shell_utils.run([GIT, 'checkout', 'master'])
141 shell_utils.run([GIT, 'branch', '-D', self._branch_name])
142
OLDNEW
« no previous file with comments | « py/utils/git_utils.py ('k') | py/utils/shell_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698