|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
| 3 | +from __future__ import print_function |
3 | 4 | import ast |
4 | 5 | import errno |
5 | 6 | import os |
@@ -25,27 +26,27 @@ def load_config(): |
25 | 26 | def try_unlink(path): |
26 | 27 | try: |
27 | 28 | os.unlink(path) |
28 | | - except OSError, e: |
| 29 | + except OSError as e: |
29 | 30 | if e.errno != errno.ENOENT: raise |
30 | 31 |
|
31 | 32 | def try_symlink(source_path, link_path): |
32 | | - print 'symlinking %s -> %s' % (source_path, link_path) |
| 33 | + print('symlinking %s -> %s' % (source_path, link_path)) |
33 | 34 | try_unlink(link_path) |
34 | 35 | try_mkdir_r(os.path.dirname(link_path)) |
35 | 36 | os.symlink(source_path, link_path) |
36 | 37 |
|
37 | 38 | def try_mkdir_r(path): |
38 | 39 | try: |
39 | 40 | os.makedirs(path) |
40 | | - except OSError, e: |
| 41 | + except OSError as e: |
41 | 42 | if e.errno != errno.EEXIST: raise |
42 | 43 |
|
43 | 44 | def try_rmdir_r(path): |
44 | 45 | path = abspath(path) |
45 | 46 | while path.startswith(install_path): |
46 | 47 | try: |
47 | 48 | os.rmdir(path) |
48 | | - except OSError, e: |
| 49 | + except OSError as e: |
49 | 50 | if e.errno == errno.ENOTEMPTY: return |
50 | 51 | if e.errno == errno.ENOENT: return |
51 | 52 | raise |
@@ -60,14 +61,14 @@ def mkpaths(path, dst): |
60 | 61 |
|
61 | 62 | def try_copy(path, dst): |
62 | 63 | source_path, target_path = mkpaths(path, dst) |
63 | | - print 'installing %s' % target_path |
| 64 | + print('installing %s' % target_path) |
64 | 65 | try_mkdir_r(os.path.dirname(target_path)) |
65 | 66 | try_unlink(target_path) # prevent ETXTBSY errors |
66 | 67 | return shutil.copy2(source_path, target_path) |
67 | 68 |
|
68 | 69 | def try_remove(path, dst): |
69 | 70 | source_path, target_path = mkpaths(path, dst) |
70 | | - print 'removing %s' % target_path |
| 71 | + print('removing %s' % target_path) |
71 | 72 | try_unlink(target_path) |
72 | 73 | try_rmdir_r(os.path.dirname(target_path)) |
73 | 74 |
|
|