Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: prepare tools/install.py for Python 3 #24800

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tools/install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import ast
import errno
import os
Expand All @@ -25,27 +26,27 @@ def load_config():
def try_unlink(path):
try:
os.unlink(path)
except OSError, e:
except OSError as e:
if e.errno != errno.ENOENT: raise

def try_symlink(source_path, link_path):
print 'symlinking %s -> %s' % (source_path, link_path)
print('symlinking %s -> %s' % (source_path, link_path))
try_unlink(link_path)
try_mkdir_r(os.path.dirname(link_path))
os.symlink(source_path, link_path)

def try_mkdir_r(path):
try:
os.makedirs(path)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST: raise

def try_rmdir_r(path):
path = abspath(path)
while path.startswith(install_path):
try:
os.rmdir(path)
except OSError, e:
except OSError as e:
if e.errno == errno.ENOTEMPTY: return
if e.errno == errno.ENOENT: return
raise
Expand All @@ -60,14 +61,14 @@ def mkpaths(path, dst):

def try_copy(path, dst):
source_path, target_path = mkpaths(path, dst)
print 'installing %s' % target_path
print('installing %s' % target_path)
try_mkdir_r(os.path.dirname(target_path))
try_unlink(target_path) # prevent ETXTBSY errors
return shutil.copy2(source_path, target_path)

def try_remove(path, dst):
source_path, target_path = mkpaths(path, dst)
print 'removing %s' % target_path
print('removing %s' % target_path)
try_unlink(target_path)
try_rmdir_r(os.path.dirname(target_path))

Expand Down