diff options
| author | Anthony King <anthonydking@slimroms.net> | 2015-04-04 21:18:59 +0100 |
|---|---|---|
| committer | Anthony King <anthonydking@slimroms.net> | 2015-04-04 21:21:49 +0100 |
| commit | b51f07cd0643388ffe2cefb28899429d9e1131fc (patch) | |
| tree | f0bdd78523b44eb01597369b1f3ad8ac9f914b8e /subcmds | |
| parent | 04f2f0e1860d10a4cc2a7b8ef7cc1665f51094b9 (diff) | |
| download | git-repo-b51f07cd0643388ffe2cefb28899429d9e1131fc.tar.gz | |
status: lose dependence on StringIO
buflist was being used, which isn't available in Python 3.
`Execute` was using StringIO to capture the output of `PrintWorkTreeStatus`,
only to redirect it straight to stdout.
Instead, just let `PrintWorkTreeStatus` do it's own thing directly to stdout.
for handling `_FindOrphans`, we swap StringIO for a list. Nothing was done
that needed a a file like object.
Change-Id: Ibdaae137904de66a5ffb590d84203ef0fe782d8b
Diffstat (limited to 'subcmds')
| -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) |
