1 |
commit: aa63202838c5346692b49ae26fff16b6977fb56c |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue May 1 02:26:52 2012 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue May 1 02:30:10 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=aa632028 |
7 |
|
8 |
repoman: ignore false Service desktop entry error |
9 |
|
10 |
This will fix bug #414125. |
11 |
|
12 |
--- |
13 |
bin/repoman | 8 ++-- |
14 |
pym/portage/util/_desktop_entry.py | 70 ++++++++++++++++++++++++++++++++++++ |
15 |
2 files changed, 74 insertions(+), 4 deletions(-) |
16 |
|
17 |
diff --git a/bin/repoman b/bin/repoman |
18 |
index 0163f8d..1cdfcf6 100755 |
19 |
--- a/bin/repoman |
20 |
+++ b/bin/repoman |
21 |
@@ -76,6 +76,7 @@ from portage.output import bold, create_color_func, \ |
22 |
green, nocolor, red |
23 |
from portage.output import ConsoleStyleFile, StyleWriter |
24 |
from portage.util import cmp_sort_key, writemsg_level |
25 |
+from portage.util._desktop_entry import validate_desktop_entry |
26 |
from portage.package.ebuild.digestgen import digestgen |
27 |
from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use |
28 |
|
29 |
@@ -1565,15 +1566,14 @@ for x in effective_scanlist: |
30 |
(checkdir, y, m.group(0))) |
31 |
|
32 |
if desktop_file_validate and desktop_pattern.match(y): |
33 |
- status, cmd_output = subprocess_getstatusoutput( |
34 |
- "'%s' '%s'" % (desktop_file_validate, full_path)) |
35 |
- if os.WIFEXITED(status) and os.WEXITSTATUS(status) != os.EX_OK: |
36 |
+ cmd_output = validate_desktop_entry(full_path) |
37 |
+ if cmd_output: |
38 |
# Note: in the future we may want to grab the |
39 |
# warnings in addition to the errors. We're |
40 |
# just doing errors now since we don't want |
41 |
# to generate too much noise at first. |
42 |
error_re = re.compile(r'.*\s*error:\s*(.*)') |
43 |
- for line in cmd_output.splitlines(): |
44 |
+ for line in cmd_output: |
45 |
error_match = error_re.match(line) |
46 |
if error_match is None: |
47 |
continue |
48 |
|
49 |
diff --git a/pym/portage/util/_desktop_entry.py b/pym/portage/util/_desktop_entry.py |
50 |
new file mode 100644 |
51 |
index 0000000..101965f |
52 |
--- /dev/null |
53 |
+++ b/pym/portage/util/_desktop_entry.py |
54 |
@@ -0,0 +1,70 @@ |
55 |
+# Copyright 2012 Gentoo Foundation |
56 |
+# Distributed under the terms of the GNU General Public License v2 |
57 |
+ |
58 |
+import io |
59 |
+import subprocess |
60 |
+ |
61 |
+try: |
62 |
+ from configparser import Error as ConfigParserError, RawConfigParser |
63 |
+except ImportError: |
64 |
+ from ConfigParser import Error as ConfigParserError, RawConfigParser |
65 |
+ |
66 |
+from portage import _encodings, _unicode_encode, _unicode_decode |
67 |
+ |
68 |
+def parse_desktop_entry(path): |
69 |
+ """ |
70 |
+ Parse the given file with RawConfigParser and return the |
71 |
+ result. This may raise an IOError from io.open(), or a |
72 |
+ ParsingError from RawConfigParser. |
73 |
+ """ |
74 |
+ parser = RawConfigParser() |
75 |
+ |
76 |
+ # use read_file/readfp in order to control decoding of unicode |
77 |
+ try: |
78 |
+ # Python >=3.2 |
79 |
+ read_file = parser.read_file |
80 |
+ except AttributeError: |
81 |
+ read_file = parser.readfp |
82 |
+ |
83 |
+ with io.open(_unicode_encode(path, |
84 |
+ encoding=_encodings['fs'], errors='strict'), |
85 |
+ mode='r', encoding=_encodings['repo.content'], |
86 |
+ errors='replace') as f: |
87 |
+ read_file(f) |
88 |
+ |
89 |
+ return parser |
90 |
+ |
91 |
+_ignored_service_errors = ( |
92 |
+ 'error: required key "Name" in group "Desktop Entry" is not present', |
93 |
+ 'error: key "Actions" is present in group "Desktop Entry", but the type is "Service" while this key is only valid for type "Application"', |
94 |
+ 'error: key "MimeType" is present in group "Desktop Entry", but the type is "Service" while this key is only valid for type "Application"', |
95 |
+) |
96 |
+ |
97 |
+def validate_desktop_entry(path): |
98 |
+ proc = subprocess.Popen([b"desktop-file-validate", _unicode_encode(path)], |
99 |
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
100 |
+ output_lines = _unicode_decode(proc.communicate()[0]).splitlines() |
101 |
+ proc.wait() |
102 |
+ |
103 |
+ if output_lines: |
104 |
+ try: |
105 |
+ desktop_entry = parse_desktop_entry(path) |
106 |
+ except ConfigParserError: |
107 |
+ pass |
108 |
+ else: |
109 |
+ if desktop_entry.has_section("Desktop Entry"): |
110 |
+ try: |
111 |
+ entry_type = desktop_entry.get("Desktop Entry", "Type") |
112 |
+ except ConfigParserError: |
113 |
+ pass |
114 |
+ else: |
115 |
+ if entry_type == "Service": |
116 |
+ # Filter false errors for Type=Service (bug #414125). |
117 |
+ filtered_output = [] |
118 |
+ for line in output_lines: |
119 |
+ if line[len(path)+2:] in _ignored_service_errors: |
120 |
+ continue |
121 |
+ filtered_output.append(line) |
122 |
+ output_lines = filtered_output |
123 |
+ |
124 |
+ return output_lines |