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

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

Issue 349973004: Add verbose option to misc.ChDir (Closed) Base URL: https://skia.googlesource.com/common.git@master
Patch Set: fix Created 6 years, 6 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 | « no previous file | no next file » | 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 used by the buildbot scripts. """
7 7
8 import os 8 import os
9 9
10 from git_utils import GIT 10 from git_utils import GIT
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 path_parts = relative_path.split(os.sep) 60 path_parts = relative_path.split(os.sep)
61 abs_path = os.path.abspath('.') 61 abs_path = os.path.abspath('.')
62 for path_part in path_parts: 62 for path_part in path_parts:
63 abs_path = os.path.abspath(os.path.join(abs_path, path_part)) 63 abs_path = os.path.abspath(os.path.join(abs_path, path_part))
64 return abs_path 64 return abs_path
65 65
66 66
67 class ChDir(object): 67 class ChDir(object):
68 """Enter and exit the given directory appropriately.""" 68 """Enter and exit the given directory appropriately."""
69 69
70 def __init__(self, directory): 70 def __init__(self, directory, verbose=True):
71 """Instantiate the ChDir. 71 """Instantiate the ChDir.
72 72
73 Args: 73 Args:
74 directory: string; the directory to enter. 74 directory: string; the directory to enter.
75 verbose: bool; whether or not to log the directory changes.
rmistry 2014/06/23 14:08:15 nit: log -> print. log may mean you are using the
borenet 2014/06/23 14:16:40 Done.
75 """ 76 """
76 self._destination = directory 77 self._destination = directory
77 self._origin = None 78 self._origin = None
79 self._verbose = verbose
78 80
79 def __enter__(self): 81 def __enter__(self):
80 """Change to the destination directory. 82 """Change to the destination directory.
81 83
82 Does not check whether the directory exists. 84 Does not check whether the directory exists.
83 """ 85 """
84 self._origin = os.getcwd() 86 self._origin = os.getcwd()
85 print 'chdir %s' % self._destination 87 if self._verbose:
88 print 'chdir %s' % self._destination
86 os.chdir(self._destination) 89 os.chdir(self._destination)
87 90
88 def __exit__(self, *args): 91 def __exit__(self, *args):
89 """Change back to the original directory.""" 92 """Change back to the original directory."""
90 print 'chdir %s' % self._origin 93 if self._verbose:
94 print 'chdir %s' % self._origin
91 os.chdir(self._origin) 95 os.chdir(self._origin)
92 96
93 97
94 class GitBranch(object): 98 class GitBranch(object):
95 """Class to manage git branches. 99 """Class to manage git branches.
96 100
97 This class allows one to create a new branch in a repository to make changes, 101 This class allows one to create a new branch in a repository to make changes,
98 then it commits the changes, switches to master branch, and deletes the 102 then it commits the changes, switches to master branch, and deletes the
99 created temporary branch upon exit. 103 created temporary branch upon exit.
100 """ 104 """
(...skipping 28 matching lines...) Expand all
129 def __exit__(self, exc_type, _value, _traceback): 133 def __exit__(self, exc_type, _value, _traceback):
130 if self._upload: 134 if self._upload:
131 # Only upload if no error occurred. 135 # Only upload if no error occurred.
132 try: 136 try:
133 if exc_type is None: 137 if exc_type is None:
134 self.commit_and_upload(use_commit_queue=self._commit_queue) 138 self.commit_and_upload(use_commit_queue=self._commit_queue)
135 finally: 139 finally:
136 shell_utils.run([GIT, 'checkout', 'master']) 140 shell_utils.run([GIT, 'checkout', 'master'])
137 shell_utils.run([GIT, 'branch', '-D', self._branch_name]) 141 shell_utils.run([GIT, 'branch', '-D', self._branch_name])
138 142
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698