Mercurial > hg-stable
annotate mercurial/windows.py @ 16076:e7701459fb42
windows: use 'str.replace()' instead of combination of split() and join()
'str.replace()' is twice (or more) as fast as combination of split()
and join().
combination of split() and join() in current 'util.pconvert()'
implementation comes only from historical reason when win32mbcs
extension was introduced.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sun, 05 Feb 2012 22:58:31 +0900 |
parents | 7b7f03502b5a |
children | e34106fa0dc3 98823bd0d697 |
rev | line source |
---|---|
8226
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
1 # windows.py - Windows utility function implementations for Mercurial |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
2 # |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
4 # |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
7914
48661519913f
windows: add various missing import
Steve Borho <steve@borho.org>
parents:
7913
diff
changeset
|
8 from i18n import _ |
14064
e4bfb9c337f3
remove unused imports and variables
Alexander Solovyov <alexander@solovyov.net>
parents:
14004
diff
changeset
|
9 import osutil |
e4bfb9c337f3
remove unused imports and variables
Alexander Solovyov <alexander@solovyov.net>
parents:
14004
diff
changeset
|
10 import errno, msvcrt, os, re, sys |
8421
b6d0fa8c7685
posixfile: remove posixfile_nt and fix import bug in windows.py
Sune Foldager <cryo@cyanite.org>
parents:
8364
diff
changeset
|
11 |
15016
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
12 import win32 |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
13 executablepath = win32.executablepath |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
14 getuser = win32.getuser |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
15 hidewindow = win32.hidewindow |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
16 lookupreg = win32.lookupreg |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
17 makedir = win32.makedir |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
18 nlinks = win32.nlinks |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
19 oslink = win32.oslink |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
20 samedevice = win32.samedevice |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
21 samefile = win32.samefile |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
22 setsignalhandler = win32.setsignalhandler |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
23 spawndetached = win32.spawndetached |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
24 termwidth = win32.termwidth |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
25 testpid = win32.testpid |
871c77e78f5d
windows: fix pyflakes warning on unused imports
Matt Mackall <mpm@selenic.com>
parents:
15011
diff
changeset
|
26 unlink = win32.unlink |
14985
dbf91976f900
windows: eliminate win32 wildcard import
Adrian Buehlmann <adrian@cadifra.com>
parents:
14969
diff
changeset
|
27 |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
28 nulldev = 'NUL:' |
15440
9ab2b3b730ee
windows: use umask 022 in debugstate output
Mads Kiilerich <mads@kiilerich.com>
parents:
15016
diff
changeset
|
29 umask = 0022 |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
30 |
8421
b6d0fa8c7685
posixfile: remove posixfile_nt and fix import bug in windows.py
Sune Foldager <cryo@cyanite.org>
parents:
8364
diff
changeset
|
31 # wrap osutil.posixfile to provide friendlier exceptions |
b6d0fa8c7685
posixfile: remove posixfile_nt and fix import bug in windows.py
Sune Foldager <cryo@cyanite.org>
parents:
8364
diff
changeset
|
32 def posixfile(name, mode='r', buffering=-1): |
b6d0fa8c7685
posixfile: remove posixfile_nt and fix import bug in windows.py
Sune Foldager <cryo@cyanite.org>
parents:
8364
diff
changeset
|
33 try: |
b6d0fa8c7685
posixfile: remove posixfile_nt and fix import bug in windows.py
Sune Foldager <cryo@cyanite.org>
parents:
8364
diff
changeset
|
34 return osutil.posixfile(name, mode, buffering) |
b6d0fa8c7685
posixfile: remove posixfile_nt and fix import bug in windows.py
Sune Foldager <cryo@cyanite.org>
parents:
8364
diff
changeset
|
35 except WindowsError, err: |
9448
bc6b0fef9495
windows: provide filename in IOError exceptions
Steve Borho <steve@borho.org>
parents:
9174
diff
changeset
|
36 raise IOError(err.errno, '%s: %s' % (name, err.strerror)) |
8421
b6d0fa8c7685
posixfile: remove posixfile_nt and fix import bug in windows.py
Sune Foldager <cryo@cyanite.org>
parents:
8364
diff
changeset
|
37 posixfile.__doc__ = osutil.posixfile.__doc__ |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
38 |
8778
c5f36402daad
use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8761
diff
changeset
|
39 class winstdout(object): |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
40 '''stdout on windows misbehaves if sent through a pipe''' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
41 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
42 def __init__(self, fp): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
43 self.fp = fp |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
44 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
45 def __getattr__(self, key): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
46 return getattr(self.fp, key) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
47 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
48 def close(self): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
49 try: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
50 self.fp.close() |
14004
97ed99d1f419
eliminate various naked except clauses
Idan Kamara <idankk86@gmail.com>
parents:
13986
diff
changeset
|
51 except IOError: |
97ed99d1f419
eliminate various naked except clauses
Idan Kamara <idankk86@gmail.com>
parents:
13986
diff
changeset
|
52 pass |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
53 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
54 def write(self, s): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
55 try: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
56 # This is workaround for "Not enough space" error on |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
57 # writing large size of data to console. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
58 limit = 16000 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
59 l = len(s) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
60 start = 0 |
10394
4612cded5176
fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
61 self.softspace = 0 |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
62 while start < l: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
63 end = start + limit |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
64 self.fp.write(s[start:end]) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
65 start = end |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
66 except IOError, inst: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
67 if inst.errno != 0: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
68 raise |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
69 self.close() |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
70 raise IOError(errno.EPIPE, 'Broken pipe') |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
71 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
72 def flush(self): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
73 try: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
74 return self.fp.flush() |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
75 except IOError, inst: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
76 if inst.errno != errno.EINVAL: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
77 raise |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
78 self.close() |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
79 raise IOError(errno.EPIPE, 'Broken pipe') |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
80 |
14892
d2d592718e90
win32: assign winstdout to sys.__stdout__ as well (issue2888)
Idan Kamara <idankk86@gmail.com>
parents:
14271
diff
changeset
|
81 sys.__stdout__ = sys.stdout = winstdout(sys.stdout) |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
82 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
83 def _is_win_9x(): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
84 '''return true if run on windows 95, 98 or me.''' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
85 try: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
86 return sys.getwindowsversion()[3] == 1 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
87 except AttributeError: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
88 return 'command' in os.environ.get('comspec', '') |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
89 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
90 def openhardlinks(): |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13280
diff
changeset
|
91 return not _is_win_9x() |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
92 |
14231
8abe4db2d162
rename util.parse_patch_output to parsepatchoutput
Adrian Buehlmann <adrian@cadifra.com>
parents:
14064
diff
changeset
|
93 def parsepatchoutput(output_line): |
8761
0289f384e1e5
Generally replace "file name" with "filename" in help and comments.
timeless <timeless@gmail.com>
parents:
8657
diff
changeset
|
94 """parses the output produced by patch and returns the filename""" |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
95 pf = output_line[14:] |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
96 if pf[0] == '`': |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
97 pf = pf[1:-1] # Remove the quotes |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
98 return pf |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
99 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
100 def sshargs(sshcmd, host, user, port): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
101 '''Build argument list for ssh or Plink''' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
102 pflag = 'plink' in sshcmd.lower() and '-P' or '-p' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
103 args = user and ("%s@%s" % (user, host)) or host |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
104 return port and ("%s %s %s" % (args, pflag, port)) or args |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
105 |
14232
df2399663392
rename util.set_flags to setflags
Adrian Buehlmann <adrian@cadifra.com>
parents:
14231
diff
changeset
|
106 def setflags(f, l, x): |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
107 pass |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
108 |
15011
5e44e4b3a0a3
util: move copymode into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
14985
diff
changeset
|
109 def copymode(src, dst, mode=None): |
5e44e4b3a0a3
util: move copymode into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
14985
diff
changeset
|
110 pass |
5e44e4b3a0a3
util: move copymode into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
14985
diff
changeset
|
111 |
13879
5b0a3f6cbead
util: move checkexec() to posix.py and return False on Windows
Adrian Buehlmann <adrian@cadifra.com>
parents:
13777
diff
changeset
|
112 def checkexec(path): |
5b0a3f6cbead
util: move checkexec() to posix.py and return False on Windows
Adrian Buehlmann <adrian@cadifra.com>
parents:
13777
diff
changeset
|
113 return False |
5b0a3f6cbead
util: move checkexec() to posix.py and return False on Windows
Adrian Buehlmann <adrian@cadifra.com>
parents:
13777
diff
changeset
|
114 |
13890
31eb145b50b6
util: move checklink() to posix.py and return False on Windows
Adrian Buehlmann <adrian@cadifra.com>
parents:
13879
diff
changeset
|
115 def checklink(path): |
31eb145b50b6
util: move checklink() to posix.py and return False on Windows
Adrian Buehlmann <adrian@cadifra.com>
parents:
13879
diff
changeset
|
116 return False |
31eb145b50b6
util: move checklink() to posix.py and return False on Windows
Adrian Buehlmann <adrian@cadifra.com>
parents:
13879
diff
changeset
|
117 |
14233
659f34b833b9
rename util.set_binary to setbinary
Adrian Buehlmann <adrian@cadifra.com>
parents:
14232
diff
changeset
|
118 def setbinary(fd): |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
119 # When run without console, pipes may expose invalid |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
120 # fileno(), usually set to -1. |
14969
a3f97038c1c2
windows: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14927
diff
changeset
|
121 fno = getattr(fd, 'fileno', None) |
a3f97038c1c2
windows: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14927
diff
changeset
|
122 if fno is not None and fno() >= 0: |
a3f97038c1c2
windows: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14927
diff
changeset
|
123 msvcrt.setmode(fno(), os.O_BINARY) |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
124 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
125 def pconvert(path): |
16076
e7701459fb42
windows: use 'str.replace()' instead of combination of split() and join()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15674
diff
changeset
|
126 return path.replace(os.sep, '/') |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
127 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
128 def localpath(path): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
129 return path.replace('/', '\\') |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
130 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
131 def normpath(path): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
132 return pconvert(os.path.normpath(path)) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
133 |
15672
2ebe3d0ce91d
i18n: use encoding.lower/upper for encoding aware case folding
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15671
diff
changeset
|
134 encodinglower = None |
2ebe3d0ce91d
i18n: use encoding.lower/upper for encoding aware case folding
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15671
diff
changeset
|
135 encodingupper = None |
2ebe3d0ce91d
i18n: use encoding.lower/upper for encoding aware case folding
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15671
diff
changeset
|
136 |
15671
3c5e818ac679
windows: use upper() instead of lower() or os.path.normcase()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15637
diff
changeset
|
137 def normcase(path): |
15672
2ebe3d0ce91d
i18n: use encoding.lower/upper for encoding aware case folding
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15671
diff
changeset
|
138 return encodingupper(path) |
15488
6eff984d8e76
dirstate: fix case-folding identity for traditional Unix
Matt Mackall <mpm@selenic.com>
parents:
15016
diff
changeset
|
139 |
9238
40196d036a71
util: add realpath() for getting the 'true' path.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9174
diff
changeset
|
140 def realpath(path): |
40196d036a71
util: add realpath() for getting the 'true' path.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9174
diff
changeset
|
141 ''' |
40196d036a71
util: add realpath() for getting the 'true' path.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9174
diff
changeset
|
142 Returns the true, canonical file system path equivalent to the given |
40196d036a71
util: add realpath() for getting the 'true' path.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9174
diff
changeset
|
143 path. |
40196d036a71
util: add realpath() for getting the 'true' path.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9174
diff
changeset
|
144 ''' |
40196d036a71
util: add realpath() for getting the 'true' path.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9174
diff
changeset
|
145 # TODO: There may be a more clever way to do this that also handles other, |
40196d036a71
util: add realpath() for getting the 'true' path.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9174
diff
changeset
|
146 # less common file systems. |
15637
7f01ad702405
icasefs: use util.normcase() instead of str.lower() or os.path.normpath()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15488
diff
changeset
|
147 return os.path.normpath(normcase(os.path.realpath(path))) |
9238
40196d036a71
util: add realpath() for getting the 'true' path.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9174
diff
changeset
|
148 |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
149 def samestat(s1, s2): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
150 return False |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
151 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
152 # A sequence of backslashes is special iff it precedes a double quote: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
153 # - if there's an even number of backslashes, the double quote is not |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
154 # quoted (i.e. it ends the quoted region) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
155 # - if there's an odd number of backslashes, the double quote is quoted |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
156 # - in both cases, every pair of backslashes is unquoted into a single |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
157 # backslash |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
158 # (See http://msdn2.microsoft.com/en-us/library/a1y7w461.aspx ) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
159 # So, to quote a string, we must surround it in double quotes, double |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
160 # the number of backslashes that preceed double quotes and add another |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
161 # backslash before every double quote (being careful with the double |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
162 # quote we've appended to the end) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
163 _quotere = None |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
164 def shellquote(s): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
165 global _quotere |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
166 if _quotere is None: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
167 _quotere = re.compile(r'(\\*)("|\\$)') |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
168 return '"%s"' % _quotere.sub(r'\1\1\\\2', s) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
169 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
170 def quotecommand(cmd): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
171 """Build a command string suitable for os.popen* calls.""" |
13188
6c9345f9edca
util: concentrate quoting knowledge to windows.py quotecommand()
Steve Borho <steve@borho.org>
parents:
12689
diff
changeset
|
172 if sys.version_info < (2, 7, 1): |
6c9345f9edca
util: concentrate quoting knowledge to windows.py quotecommand()
Steve Borho <steve@borho.org>
parents:
12689
diff
changeset
|
173 # Python versions since 2.7.1 do this extra quoting themselves |
6c9345f9edca
util: concentrate quoting knowledge to windows.py quotecommand()
Steve Borho <steve@borho.org>
parents:
12689
diff
changeset
|
174 return '"' + cmd + '"' |
6c9345f9edca
util: concentrate quoting knowledge to windows.py quotecommand()
Steve Borho <steve@borho.org>
parents:
12689
diff
changeset
|
175 return cmd |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
176 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
177 def popen(command, mode='r'): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
178 # Work around "popen spawned process may not write to stdout |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
179 # under windows" |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
180 # http://bugs.python.org/issue1366 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
181 command += " 2> %s" % nulldev |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
182 return os.popen(quotecommand(command), mode) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
183 |
14234
600e64004eb5
rename explain_exit to explainexit
Adrian Buehlmann <adrian@cadifra.com>
parents:
14233
diff
changeset
|
184 def explainexit(code): |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
185 return _("exited with status %d") % code, code |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
186 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
187 # if you change this stub into a real check, please try to implement the |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
188 # username and groupname functions above, too. |
8657
3fa92c618624
posix: do not use fstat in isowner
Martin Geisler <mg@lazybytes.net>
parents:
8614
diff
changeset
|
189 def isowner(st): |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
190 return True |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
191 |
14271
4030630fb59c
rename util.find_exe to findexe
Adrian Buehlmann <adrian@cadifra.com>
parents:
14234
diff
changeset
|
192 def findexe(command): |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
193 '''Find executable for command searching like cmd.exe does. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
194 If command is a basename then PATH is searched for command. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
195 PATH isn't searched if command is an absolute or relative path. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
196 An extension from PATHEXT is found and added if not present. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
197 If command isn't found None is returned.''' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
198 pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD') |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
199 pathexts = [ext for ext in pathext.lower().split(os.pathsep)] |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
200 if os.path.splitext(command)[1].lower() in pathexts: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
201 pathexts = [''] |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
202 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
203 def findexisting(pathcommand): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
204 'Will append extension (if needed) and return existing file' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
205 for ext in pathexts: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
206 executable = pathcommand + ext |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
207 if os.path.exists(executable): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
208 return executable |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
209 return None |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
210 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
211 if os.sep in command: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
212 return findexisting(command) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
213 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
214 for path in os.environ.get('PATH', '').split(os.pathsep): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
215 executable = findexisting(os.path.join(path, command)) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
216 if executable is not None: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
217 return executable |
10156
c31ac3f7fd8f
windows: expand environment vars in find_exe
Steve Borho <steve@borho.org>
parents:
9594
diff
changeset
|
218 return findexisting(os.path.expanduser(os.path.expandvars(command))) |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
219 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
220 def statfiles(files): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
221 '''Stat each file in files and yield stat or None if file does not exist. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
222 Cluster and cache stat per directory to minimize number of OS stat calls.''' |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
223 dircache = {} # dirname -> filename -> status | None if file does not exist |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
224 for nf in files: |
15637
7f01ad702405
icasefs: use util.normcase() instead of str.lower() or os.path.normpath()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15488
diff
changeset
|
225 nf = normcase(nf) |
9099
3d456bf32f18
Use os.path.split() for MBCS with win32mbcs extension.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
8951
diff
changeset
|
226 dir, base = os.path.split(nf) |
3d456bf32f18
Use os.path.split() for MBCS with win32mbcs extension.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
8951
diff
changeset
|
227 if not dir: |
3d456bf32f18
Use os.path.split() for MBCS with win32mbcs extension.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
8951
diff
changeset
|
228 dir = '.' |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
229 cache = dircache.get(dir, None) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
230 if cache is None: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
231 try: |
15637
7f01ad702405
icasefs: use util.normcase() instead of str.lower() or os.path.normpath()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15488
diff
changeset
|
232 dmap = dict([(normcase(n), s) |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
233 for n, k, s in osutil.listdir(dir, True)]) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
234 except OSError, err: |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
235 # handle directory not found in Python version prior to 2.5 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
236 # Python <= 2.4 returns native Windows code 3 in errno |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
237 # Python >= 2.5 returns ENOENT and adds winerror field |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
238 # EINVAL is raised if dir is not a directory. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
239 if err.errno not in (3, errno.ENOENT, errno.EINVAL, |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
240 errno.ENOTDIR): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
241 raise |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
242 dmap = {} |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
243 cache = dircache.setdefault(dir, dmap) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
244 yield cache.get(base, None) |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
245 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
246 def username(uid=None): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
247 """Return the name of the user with the given uid. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
248 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
249 If uid is None, return the name of the current user.""" |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
250 return None |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
251 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
252 def groupname(gid=None): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
253 """Return the name of the group with the given gid. |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
254 |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
255 If gid is None, return the name of the current group.""" |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
256 return None |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
257 |
8364
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
258 def _removedirs(name): |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
259 """special version of os.removedirs that does not remove symlinked |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
260 directories or junction points if they actually contain files""" |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
261 if osutil.listdir(name): |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
262 return |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
263 os.rmdir(name) |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
264 head, tail = os.path.split(name) |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
265 if not tail: |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
266 head, tail = os.path.split(head) |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
267 while head and tail: |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
268 try: |
9572
1f665246dab3
windows: fix unlink() not dropping empty tree (issue1861)
Patrick Mezard <pmezard@gmail.com>
parents:
9448
diff
changeset
|
269 if osutil.listdir(head): |
8364
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
270 return |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
271 os.rmdir(head) |
14004
97ed99d1f419
eliminate various naked except clauses
Idan Kamara <idankk86@gmail.com>
parents:
13986
diff
changeset
|
272 except (ValueError, OSError): |
8364
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
273 break |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
274 head, tail = os.path.split(head) |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
275 |
13235
6bf39d88c857
rename util.unlink to unlinkpath
Adrian Buehlmann <adrian@cadifra.com>
parents:
13206
diff
changeset
|
276 def unlinkpath(f): |
8364
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
277 """unlink and remove the directory if it is empty""" |
13777
f6e5035dc81a
windows: use win32.unlink in unlinkpath()
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
278 unlink(f) |
8364
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
279 # try removing directories that might now be empty |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
280 try: |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
281 _removedirs(os.path.dirname(f)) |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
282 except OSError: |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
283 pass |
fa901423ac23
windows: avoid deleting non-empty reparse points
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8330
diff
changeset
|
284 |
9549
8b8920209317
util: move rename into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
9449
diff
changeset
|
285 def rename(src, dst): |
8b8920209317
util: move rename into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
9449
diff
changeset
|
286 '''atomically rename file src to dst, replacing dst if it exists''' |
8b8920209317
util: move rename into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
9449
diff
changeset
|
287 try: |
8b8920209317
util: move rename into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
9449
diff
changeset
|
288 os.rename(src, dst) |
13278
e9a52ed28157
windows.rename: check OSError for EEXIST
Adrian Buehlmann <adrian@cadifra.com>
parents:
13235
diff
changeset
|
289 except OSError, e: |
e9a52ed28157
windows.rename: check OSError for EEXIST
Adrian Buehlmann <adrian@cadifra.com>
parents:
13235
diff
changeset
|
290 if e.errno != errno.EEXIST: |
e9a52ed28157
windows.rename: check OSError for EEXIST
Adrian Buehlmann <adrian@cadifra.com>
parents:
13235
diff
changeset
|
291 raise |
13280
6052bbc7aabd
reintroduces util.unlink, for POSIX and Windows.
Adrian Buehlmann <adrian@cadifra.com>
parents:
13278
diff
changeset
|
292 unlink(dst) |
9549
8b8920209317
util: move rename into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
9449
diff
changeset
|
293 os.rename(src, dst) |
8b8920209317
util: move rename into posix.py and windows.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
9449
diff
changeset
|
294 |
10239
8e4be44a676f
Find right hg command for detached process
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
295 def gethgcmd(): |
8e4be44a676f
Find right hg command for detached process
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
296 return [sys.executable] + sys.argv[:1] |
8e4be44a676f
Find right hg command for detached process
Patrick Mezard <pmezard@gmail.com>
parents:
10237
diff
changeset
|
297 |
12689
c52c629ce19e
termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
298 def termwidth(): |
11010
18e81d42ee5c
util: fix default termwidth() under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
10394
diff
changeset
|
299 # cmd.exe does not handle CR like a unix console, the CR is |
18e81d42ee5c
util: fix default termwidth() under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
10394
diff
changeset
|
300 # counted in the line length. On 80 columns consoles, if 80 |
18e81d42ee5c
util: fix default termwidth() under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
10394
diff
changeset
|
301 # characters are written, the following CR won't apply on the |
18e81d42ee5c
util: fix default termwidth() under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
10394
diff
changeset
|
302 # current line but on the new one. Keep room for it. |
18e81d42ee5c
util: fix default termwidth() under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
10394
diff
changeset
|
303 return 79 |
18e81d42ee5c
util: fix default termwidth() under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
10394
diff
changeset
|
304 |
11138
99eee847beaa
acl: grp module is not available on windows
Patrick Mezard <pmezard@gmail.com>
parents:
11010
diff
changeset
|
305 def groupmembers(name): |
99eee847beaa
acl: grp module is not available on windows
Patrick Mezard <pmezard@gmail.com>
parents:
11010
diff
changeset
|
306 # Don't support groups on Windows for now |
99eee847beaa
acl: grp module is not available on windows
Patrick Mezard <pmezard@gmail.com>
parents:
11010
diff
changeset
|
307 raise KeyError() |
99eee847beaa
acl: grp module is not available on windows
Patrick Mezard <pmezard@gmail.com>
parents:
11010
diff
changeset
|
308 |
14926
4e7e63fc685a
util: eliminate wildcard imports
Adrian Buehlmann <adrian@cadifra.com>
parents:
14892
diff
changeset
|
309 def isexec(f): |
4e7e63fc685a
util: eliminate wildcard imports
Adrian Buehlmann <adrian@cadifra.com>
parents:
14892
diff
changeset
|
310 return False |
4e7e63fc685a
util: eliminate wildcard imports
Adrian Buehlmann <adrian@cadifra.com>
parents:
14892
diff
changeset
|
311 |
14927
2aa3e07b2f07
posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents:
14926
diff
changeset
|
312 class cachestat(object): |
2aa3e07b2f07
posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents:
14926
diff
changeset
|
313 def __init__(self, path): |
2aa3e07b2f07
posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents:
14926
diff
changeset
|
314 pass |
2aa3e07b2f07
posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents:
14926
diff
changeset
|
315 |
2aa3e07b2f07
posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents:
14926
diff
changeset
|
316 def cacheable(self): |
2aa3e07b2f07
posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents:
14926
diff
changeset
|
317 return False |
2aa3e07b2f07
posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents:
14926
diff
changeset
|
318 |
8614
573734e7e6d0
cmdutils: Take over glob expansion duties from util
Matt Mackall <mpm@selenic.com>
parents:
8559
diff
changeset
|
319 expandglobs = True |