1 |
Author: zmedico |
2 |
Date: 2009-04-30 07:10:58 +0000 (Thu, 30 Apr 2009) |
3 |
New Revision: 13500 |
4 |
|
5 |
Modified: |
6 |
main/branches/2.1.6/pym/portage/__init__.py |
7 |
Log: |
8 |
Convert portage.bsd_chflags into a class with chflags() and lchflags() class |
9 |
methods. (trunk r13343) |
10 |
|
11 |
Modified: main/branches/2.1.6/pym/portage/__init__.py |
12 |
=================================================================== |
13 |
--- main/branches/2.1.6/pym/portage/__init__.py 2009-04-30 07:10:46 UTC (rev 13499) |
14 |
+++ main/branches/2.1.6/pym/portage/__init__.py 2009-04-30 07:10:58 UTC (rev 13500) |
15 |
@@ -43,35 +43,6 @@ |
16 |
sys.stderr.write(" "+str(e)+"\n\n"); |
17 |
raise |
18 |
|
19 |
-bsd_chflags = None |
20 |
-if platform.system() in ["FreeBSD"]: |
21 |
- def bsd_chflags(): |
22 |
- pass |
23 |
- def _chflags(path, flags, opts=""): |
24 |
- cmd = "chflags %s %o '%s'" % (opts, flags, path) |
25 |
- status, output = commands.getstatusoutput(cmd) |
26 |
- if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK: |
27 |
- return |
28 |
- # Try to generate an ENOENT error if appropriate. |
29 |
- if "h" in opts: |
30 |
- os.lstat(path) |
31 |
- else: |
32 |
- os.stat(path) |
33 |
- # Make sure the binary exists. |
34 |
- if not portage.process.find_binary("chflags"): |
35 |
- raise portage.exception.CommandNotFound("chflags") |
36 |
- # Now we're not sure exactly why it failed or what |
37 |
- # the real errno was, so just report EPERM. |
38 |
- e = OSError(errno.EPERM, output) |
39 |
- e.errno = errno.EPERM |
40 |
- e.filename = path |
41 |
- e.message = output |
42 |
- raise e |
43 |
- def _lchflags(path, flags): |
44 |
- return _chflags(path, flags, opts="-h") |
45 |
- bsd_chflags.chflags = _chflags |
46 |
- bsd_chflags.lchflags = _lchflags |
47 |
- |
48 |
try: |
49 |
from portage.cache.cache_errors import CacheError |
50 |
import portage.proxy.lazyimport |
51 |
@@ -149,7 +120,49 @@ |
52 |
# END OF IMPORTS -- END OF IMPORTS -- END OF IMPORTS -- END OF IMPORTS -- END |
53 |
# =========================================================================== |
54 |
|
55 |
+def _shell_quote(s): |
56 |
+ """ |
57 |
+ Quote a string in double-quotes and use backslashes to |
58 |
+ escape any backslashes, double-quotes, dollar signs, or |
59 |
+ backquotes in the string. |
60 |
+ """ |
61 |
+ for letter in "\\\"$`": |
62 |
+ if letter in s: |
63 |
+ s = s.replace(letter, "\\" + letter) |
64 |
+ return "\"%s\"" % s |
65 |
|
66 |
+bsd_chflags = None |
67 |
+ |
68 |
+if platform.system() in ('FreeBSD',): |
69 |
+ |
70 |
+ class bsd_chflags(object): |
71 |
+ |
72 |
+ @classmethod |
73 |
+ def chflags(cls, path, flags, opts=""): |
74 |
+ cmd = 'chflags %s %o %s' % (opts, flags, _shell_quote(path)) |
75 |
+ status, output = commands.getstatusoutput(cmd) |
76 |
+ if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK: |
77 |
+ return |
78 |
+ # Try to generate an ENOENT error if appropriate. |
79 |
+ if 'h' in opts: |
80 |
+ os.lstat(path) |
81 |
+ else: |
82 |
+ os.stat(path) |
83 |
+ # Make sure the binary exists. |
84 |
+ if not portage.process.find_binary('chflags'): |
85 |
+ raise portage.exception.CommandNotFound('chflags') |
86 |
+ # Now we're not sure exactly why it failed or what |
87 |
+ # the real errno was, so just report EPERM. |
88 |
+ e = OSError(errno.EPERM, output) |
89 |
+ e.errno = errno.EPERM |
90 |
+ e.filename = path |
91 |
+ e.message = output |
92 |
+ raise e |
93 |
+ |
94 |
+ @classmethod |
95 |
+ def lchflags(cls, path, flags): |
96 |
+ return cls.chflags(path, flags, opts='-h') |
97 |
+ |
98 |
def load_mod(name): |
99 |
modname = ".".join(name.split(".")[:-1]) |
100 |
mod = __import__(modname) |
101 |
@@ -3146,17 +3159,6 @@ |
102 |
keys = __iter__ |
103 |
items = iteritems |
104 |
|
105 |
-def _shell_quote(s): |
106 |
- """ |
107 |
- Quote a string in double-quotes and use backslashes to |
108 |
- escape any backslashes, double-quotes, dollar signs, or |
109 |
- backquotes in the string. |
110 |
- """ |
111 |
- for letter in "\\\"$`": |
112 |
- if letter in s: |
113 |
- s = s.replace(letter, "\\" + letter) |
114 |
- return "\"%s\"" % s |
115 |
- |
116 |
# In some cases, openpty can be slow when it fails. Therefore, |
117 |
# stop trying to use it after the first failure. |
118 |
_disable_openpty = False |