diff options
author | Conley Owens <cco3@android.com> | 2015-04-08 17:58:33 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-04-08 17:58:35 +0000 |
commit | 44859d02672be7509b8fe9b2d444aa239a849af5 (patch) | |
tree | d13e364f800b935f1332d0bdf3cf5559e35c048c | |
parent | 33fe4e99f95125a0083e97c4c143d1fb5134cf36 (diff) | |
parent | b51f07cd0643388ffe2cefb28899429d9e1131fc (diff) | |
download | git-repo-44859d02672be7509b8fe9b2d444aa239a849af5.tar.gz |
Merge "status: lose dependence on StringIO"
-rw-r--r-- | subcmds/status.py | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/subcmds/status.py b/subcmds/status.py index b42675e0..38c229b1 100644 --- a/subcmds/status.py +++ b/subcmds/status.py | |||
@@ -22,15 +22,8 @@ except ImportError: | |||
22 | 22 | ||
23 | import glob | 23 | import glob |
24 | 24 | ||
25 | from pyversion import is_python3 | ||
26 | if is_python3(): | ||
27 | import io | ||
28 | else: | ||
29 | import StringIO as io | ||
30 | |||
31 | import itertools | 25 | import itertools |
32 | import os | 26 | import os |
33 | import sys | ||
34 | 27 | ||
35 | from color import Coloring | 28 | from color import Coloring |
36 | 29 | ||
@@ -97,7 +90,7 @@ the following meanings: | |||
97 | dest='orphans', action='store_true', | 90 | dest='orphans', action='store_true', |
98 | help="include objects in working directory outside of repo projects") | 91 | help="include objects in working directory outside of repo projects") |
99 | 92 | ||
100 | def _StatusHelper(self, project, clean_counter, sem, output): | 93 | def _StatusHelper(self, project, clean_counter, sem): |
101 | """Obtains the status for a specific project. | 94 | """Obtains the status for a specific project. |
102 | 95 | ||
103 | Obtains the status for a project, redirecting the output to | 96 | Obtains the status for a project, redirecting the output to |
@@ -111,7 +104,7 @@ the following meanings: | |||
111 | output: Where to output the status. | 104 | output: Where to output the status. |
112 | """ | 105 | """ |
113 | try: | 106 | try: |
114 | state = project.PrintWorkTreeStatus(output) | 107 | state = project.PrintWorkTreeStatus() |
115 | if state == 'CLEAN': | 108 | if state == 'CLEAN': |
116 | next(clean_counter) | 109 | next(clean_counter) |
117 | finally: | 110 | finally: |
@@ -122,16 +115,16 @@ the following meanings: | |||
122 | status_header = ' --\t' | 115 | status_header = ' --\t' |
123 | for item in dirs: | 116 | for item in dirs: |
124 | if not os.path.isdir(item): | 117 | if not os.path.isdir(item): |
125 | outstring.write(''.join([status_header, item])) | 118 | outstring.append(''.join([status_header, item])) |
126 | continue | 119 | continue |
127 | if item in proj_dirs: | 120 | if item in proj_dirs: |
128 | continue | 121 | continue |
129 | if item in proj_dirs_parents: | 122 | if item in proj_dirs_parents: |
130 | self._FindOrphans(glob.glob('%s/.*' % item) + \ | 123 | self._FindOrphans(glob.glob('%s/.*' % item) + |
131 | glob.glob('%s/*' % item), \ | 124 | glob.glob('%s/*' % item), |
132 | proj_dirs, proj_dirs_parents, outstring) | 125 | proj_dirs, proj_dirs_parents, outstring) |
133 | continue | 126 | continue |
134 | outstring.write(''.join([status_header, item, '/'])) | 127 | outstring.append(''.join([status_header, item, '/'])) |
135 | 128 | ||
136 | def Execute(self, opt, args): | 129 | def Execute(self, opt, args): |
137 | all_projects = self.GetProjects(args) | 130 | all_projects = self.GetProjects(args) |
@@ -144,26 +137,17 @@ the following meanings: | |||
144 | next(counter) | 137 | next(counter) |
145 | else: | 138 | else: |
146 | sem = _threading.Semaphore(opt.jobs) | 139 | sem = _threading.Semaphore(opt.jobs) |
147 | threads_and_output = [] | 140 | threads = [] |
148 | for project in all_projects: | 141 | for project in all_projects: |
149 | sem.acquire() | 142 | sem.acquire() |
150 | 143 | ||
151 | class BufList(io.StringIO): | ||
152 | def dump(self, ostream): | ||
153 | for entry in self.buflist: | ||
154 | ostream.write(entry) | ||
155 | |||
156 | output = BufList() | ||
157 | |||
158 | t = _threading.Thread(target=self._StatusHelper, | 144 | t = _threading.Thread(target=self._StatusHelper, |
159 | args=(project, counter, sem, output)) | 145 | args=(project, counter, sem)) |
160 | threads_and_output.append((t, output)) | 146 | threads.append(t) |
161 | t.daemon = True | 147 | t.daemon = True |
162 | t.start() | 148 | t.start() |
163 | for (t, output) in threads_and_output: | 149 | for t in threads: |
164 | t.join() | 150 | t.join() |
165 | output.dump(sys.stdout) | ||
166 | output.close() | ||
167 | if len(all_projects) == next(counter): | 151 | if len(all_projects) == next(counter): |
168 | print('nothing to commit (working directory clean)') | 152 | print('nothing to commit (working directory clean)') |
169 | 153 | ||
@@ -188,23 +172,21 @@ the following meanings: | |||
188 | try: | 172 | try: |
189 | os.chdir(self.manifest.topdir) | 173 | os.chdir(self.manifest.topdir) |
190 | 174 | ||
191 | outstring = io.StringIO() | 175 | outstring = [] |
192 | self._FindOrphans(glob.glob('.*') + \ | 176 | self._FindOrphans(glob.glob('.*') + |
193 | glob.glob('*'), \ | 177 | glob.glob('*'), |
194 | proj_dirs, proj_dirs_parents, outstring) | 178 | proj_dirs, proj_dirs_parents, outstring) |
195 | 179 | ||
196 | if outstring.buflist: | 180 | if outstring: |
197 | output = StatusColoring(self.manifest.globalConfig) | 181 | output = StatusColoring(self.manifest.globalConfig) |
198 | output.project('Objects not within a project (orphans)') | 182 | output.project('Objects not within a project (orphans)') |
199 | output.nl() | 183 | output.nl() |
200 | for entry in outstring.buflist: | 184 | for entry in outstring: |
201 | output.untracked(entry) | 185 | output.untracked(entry) |
202 | output.nl() | 186 | output.nl() |
203 | else: | 187 | else: |
204 | print('No orphan files or directories') | 188 | print('No orphan files or directories') |
205 | 189 | ||
206 | outstring.close() | ||
207 | |||
208 | finally: | 190 | finally: |
209 | # Restore CWD. | 191 | # Restore CWD. |
210 | os.chdir(orig_path) | 192 | os.chdir(orig_path) |