Merge changes from topic "windows-support"

* changes:
  Port os.rename calls to work on Windows
  Workaround shutil.rmtree limitation on Windows
  Add support for creating symbolic links on Windows
  Make "git command" and "forall" work on Windows
This commit is contained in:
David Pursehouse
2017-08-30 10:24:03 +00:00
committed by Gerrit Code Review
9 changed files with 346 additions and 59 deletions

View File

@ -15,17 +15,16 @@
from __future__ import print_function
import errno
import fcntl
import multiprocessing
import re
import os
import select
import signal
import sys
import subprocess
from color import Coloring
from command import Command, MirrorSafeCommand
import platform_utils
_CAN_COLOR = [
'branch',
@ -344,35 +343,25 @@ def DoWork(project, mirror, opt, cmd, shell, cnt, config):
if opt.project_header:
out = ForallColoring(config)
out.redirect(sys.stdout)
class sfd(object):
def __init__(self, fd, dest):
self.fd = fd
self.dest = dest
def fileno(self):
return self.fd.fileno()
empty = True
errbuf = ''
p.stdin.close()
s_in = [sfd(p.stdout, sys.stdout),
sfd(p.stderr, sys.stderr)]
s_in = platform_utils.FileDescriptorStreams.create()
s_in.add(p.stdout, sys.stdout, 'stdout')
s_in.add(p.stderr, sys.stderr, 'stderr')
for s in s_in:
flags = fcntl.fcntl(s.fd, fcntl.F_GETFL)
fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
while s_in:
in_ready, _out_ready, _err_ready = select.select(s_in, [], [])
while not s_in.is_done:
in_ready = s_in.select()
for s in in_ready:
buf = s.fd.read(4096)
buf = s.read()
if not buf:
s.fd.close()
s.close()
s_in.remove(s)
continue
if not opt.verbose:
if s.fd != p.stdout:
if s.std_name == 'stderr':
errbuf += buf
continue

View File

@ -14,10 +14,10 @@
# limitations under the License.
from __future__ import print_function
import shutil
import sys
from command import Command, GitcClientCommand
import platform_utils
from pyversion import is_python3
if not is_python3():
@ -50,4 +50,4 @@ and all locally downloaded sources.
if not response == 'yes':
print('Response was not "yes"\n Exiting...')
sys.exit(1)
shutil.rmtree(self.gitc_manifest.gitc_client_dir)
platform_utils.rmtree(self.gitc_manifest.gitc_client_dir)

View File

@ -17,7 +17,6 @@ from __future__ import print_function
import os
import platform
import re
import shutil
import sys
from pyversion import is_python3
@ -35,6 +34,7 @@ from error import ManifestParseError
from project import SyncBuffer
from git_config import GitConfig
from git_command import git_require, MIN_GIT_VERSION
import platform_utils
class Init(InteractiveCommand, MirrorSafeCommand):
common = True
@ -252,7 +252,7 @@ to update the working directory files.
# Better delete the manifest git dir if we created it; otherwise next
# time (when user fixes problems) we won't go through the "is_new" logic.
if is_new:
shutil.rmtree(m.gitdir)
platform_utils.rmtree(m.gitdir)
sys.exit(1)
if opt.manifest_branch:

View File

@ -19,7 +19,6 @@ import netrc
from optparse import SUPPRESS_HELP
import os
import re
import shutil
import socket
import subprocess
import sys
@ -73,6 +72,7 @@ from project import Project
from project import RemoteSpec
from command import Command, MirrorSafeCommand
from error import RepoChangedException, GitError, ManifestParseError
import platform_utils
from project import SyncBuffer
from progress import Progress
from wrapper import Wrapper
@ -475,7 +475,7 @@ later is required to fix a server side protocol bug.
# working git repository around. There shouldn't be any git projects here,
# so rmtree works.
try:
shutil.rmtree(os.path.join(path, '.git'))
platform_utils.rmtree(os.path.join(path, '.git'))
except OSError:
print('Failed to remove %s' % os.path.join(path, '.git'), file=sys.stderr)
print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)