1 |
Author: volkmar |
2 |
Date: 2009-07-30 20:36:02 +0000 (Thu, 30 Jul 2009) |
3 |
New Revision: 13858 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/_emerge/actions.py |
7 |
main/trunk/pym/portage/util.py |
8 |
Log: |
9 |
Add get_updated_config_files in portage API |
10 |
chk_updated_cfg_files in _emerge API is now using get_updated_config_files |
11 |
It lets other app to get updated config files without ouputs |
12 |
|
13 |
|
14 |
Modified: main/trunk/pym/_emerge/actions.py |
15 |
=================================================================== |
16 |
--- main/trunk/pym/_emerge/actions.py 2009-07-30 07:31:06 UTC (rev 13857) |
17 |
+++ main/trunk/pym/_emerge/actions.py 2009-07-30 20:36:02 UTC (rev 13858) |
18 |
@@ -2610,59 +2610,20 @@ |
19 |
return settings, trees, mtimedb |
20 |
|
21 |
def chk_updated_cfg_files(target_root, config_protect): |
22 |
- if config_protect: |
23 |
- #number of directories with some protect files in them |
24 |
- procount=0 |
25 |
- for x in config_protect: |
26 |
- x = os.path.join(target_root, x.lstrip(os.path.sep)) |
27 |
- if not os.access(x, os.W_OK): |
28 |
- # Avoid Permission denied errors generated |
29 |
- # later by `find`. |
30 |
- continue |
31 |
- try: |
32 |
- mymode = os.lstat(x).st_mode |
33 |
- except OSError: |
34 |
- continue |
35 |
- if stat.S_ISLNK(mymode): |
36 |
- # We want to treat it like a directory if it |
37 |
- # is a symlink to an existing directory. |
38 |
- try: |
39 |
- real_mode = os.stat(x).st_mode |
40 |
- if stat.S_ISDIR(real_mode): |
41 |
- mymode = real_mode |
42 |
- except OSError: |
43 |
- pass |
44 |
- if stat.S_ISDIR(mymode): |
45 |
- mycommand = "find '%s' -name '.*' -type d -prune -o -name '._cfg????_*'" % x |
46 |
- else: |
47 |
- mycommand = "find '%s' -maxdepth 1 -name '._cfg????_%s'" % \ |
48 |
- os.path.split(x.rstrip(os.path.sep)) |
49 |
- mycommand += " ! -name '.*~' ! -iname '.*.bak' -print0" |
50 |
- a = commands.getstatusoutput(mycommand) |
51 |
- if a[0] != 0: |
52 |
- sys.stderr.write(" %s error scanning '%s': " % (bad("*"), x)) |
53 |
- sys.stderr.flush() |
54 |
- # Show the error message alone, sending stdout to /dev/null. |
55 |
- os.system(mycommand + " 1>/dev/null") |
56 |
- else: |
57 |
- files = a[1].split('\0') |
58 |
- # split always produces an empty string as the last element |
59 |
- if files and not files[-1]: |
60 |
- del files[-1] |
61 |
- if files: |
62 |
- procount += 1 |
63 |
- print "\n"+colorize("WARN", " * IMPORTANT:"), |
64 |
- if stat.S_ISDIR(mymode): |
65 |
- print "%d config files in '%s' need updating." % \ |
66 |
- (len(files), x) |
67 |
- else: |
68 |
- print "config file '%s' needs updating." % x |
69 |
+ result = portage.util.get_updated_config_files(target_root, config_protect) |
70 |
|
71 |
- if procount: |
72 |
- print " "+yellow("*")+" See the "+colorize("INFORM","CONFIGURATION FILES")+ \ |
73 |
- " section of the " + bold("emerge") |
74 |
- print " "+yellow("*")+" man page to learn how to update config files." |
75 |
+ for x in result: |
76 |
+ print "\n"+colorize("WARN", " * IMPORTANT:"), |
77 |
+ if not x[1]: # it's a protected file |
78 |
+ print "config file '%s' needs updating." % x[0] |
79 |
+ else: # it's a protected dir |
80 |
+ print "%d config files in '%s' need updating." % (len(x[1]), x[0]) |
81 |
|
82 |
+ if result != []: |
83 |
+ print " "+yellow("*")+" See the "+colorize("INFORM","CONFIGURATION FILES")\ |
84 |
+ + " section of the " + bold("emerge") |
85 |
+ print " "+yellow("*")+" man page to learn how to update config files." |
86 |
+ |
87 |
def display_news_notification(root_config, myopts): |
88 |
target_root = root_config.root |
89 |
trees = root_config.trees |
90 |
|
91 |
Modified: main/trunk/pym/portage/util.py |
92 |
=================================================================== |
93 |
--- main/trunk/pym/portage/util.py 2009-07-30 07:31:06 UTC (rev 13857) |
94 |
+++ main/trunk/pym/portage/util.py 2009-07-30 20:36:02 UTC (rev 13858) |
95 |
@@ -5,13 +5,14 @@ |
96 |
__all__ = ['apply_permissions', 'apply_recursive_permissions', |
97 |
'apply_secpass_permissions', 'apply_stat_permissions', 'atomic_ofstream', |
98 |
'cmp_sort_key', 'ConfigProtect', 'dump_traceback', 'ensure_dirs', |
99 |
- 'getconfig', 'getlibpaths', 'grabdict', 'grabdict_package', 'grabfile', |
100 |
- 'grabfile_package', 'grablines', 'initialize_logger', 'LazyItemsDict', |
101 |
- 'map_dictlist_vals', 'new_protect_filename', 'normalize_path', |
102 |
- 'pickle_read', 'stack_dictlist', 'stack_dicts', 'stack_lists', |
103 |
- 'unique_array', 'varexpand', 'write_atomic', 'writedict', 'writemsg', |
104 |
- 'writemsg_level', 'writemsg_stdout'] |
105 |
+ 'getconfig', 'getlibpaths', 'get_updated_config_files' 'grabdict', |
106 |
+ 'grabdict_package', 'grabfile', 'grabfile_package', 'grablines', |
107 |
+ 'initialize_logger', 'LazyItemsDict', 'map_dictlist_vals', |
108 |
+ 'new_protect_filename', 'normalize_path', 'pickle_read', 'stack_dictlist', |
109 |
+ 'stack_dicts', 'stack_lists', 'unique_array', 'varexpand', 'write_atomic', |
110 |
+ 'writedict', 'writemsg', 'writemsg_level', 'writemsg_stdout'] |
111 |
|
112 |
+import commands |
113 |
import codecs |
114 |
import os |
115 |
import errno |
116 |
@@ -1290,6 +1291,63 @@ |
117 |
return old_pfile |
118 |
return new_pfile |
119 |
|
120 |
+def get_updated_config_files(target_root, config_protect): |
121 |
+ """ |
122 |
+ Return a list of configuration files that needs to be updated. |
123 |
+ The list contains tuple organized like this: |
124 |
+ [ protected_dir, file_list ] |
125 |
+ If the protected config isn't a protected_dir but a procted_file, tuple is: |
126 |
+ [ protected_file, None ] |
127 |
+ If no configuration files needs to be updated, [] is returned |
128 |
+ """ |
129 |
+ |
130 |
+ rval = [] |
131 |
+ |
132 |
+ if config_protect: |
133 |
+ # directories with some protect files in them |
134 |
+ for x in config_protect: |
135 |
+ files = [] |
136 |
+ |
137 |
+ x = os.path.join(target_root, x.lstrip(os.path.sep)) |
138 |
+ if not os.access(x, os.W_OK): |
139 |
+ continue |
140 |
+ try: |
141 |
+ mymode = os.lstat(x).st_mode |
142 |
+ except OSError: |
143 |
+ continue |
144 |
+ |
145 |
+ if stat.S_ISLNK(mymode): |
146 |
+ # We want to treat it like a directory if it |
147 |
+ # is a symlink to an existing directory. |
148 |
+ try: |
149 |
+ real_mode = os.stat(x).st_mode |
150 |
+ if stat.S_ISDIR(real_mode): |
151 |
+ mymode = real_mode |
152 |
+ except OSError: |
153 |
+ pass |
154 |
+ |
155 |
+ if stat.S_ISDIR(mymode): |
156 |
+ mycommand = \ |
157 |
+ "find '%s' -name '.*' -type d -prune -o -name '._cfg????_*'" % x |
158 |
+ else: |
159 |
+ mycommand = "find '%s' -maxdepth 1 -name '._cfg????_%s'" % \ |
160 |
+ os.path.split(x.rstrip(os.path.sep)) |
161 |
+ mycommand += " ! -name '.*~' ! -iname '.*.bak' -print0" |
162 |
+ a = commands.getstatusoutput(mycommand) |
163 |
+ |
164 |
+ if a[0] == 0: |
165 |
+ files = a[1].split('\0') |
166 |
+ # split always produces an empty string as the last element |
167 |
+ if files and not files[-1]: |
168 |
+ del files[-1] |
169 |
+ if files: |
170 |
+ if stat.S_ISDIR(mymode): |
171 |
+ rval.append([x, files]) |
172 |
+ else: |
173 |
+ rval.append([x, None]) |
174 |
+ |
175 |
+ return rval |
176 |
+ |
177 |
def getlibpaths(root): |
178 |
""" Return a list of paths that are used for library lookups """ |