1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import base64
18 import os
19 import sys
20 import errno
21 from rhn.i18n import bstr
22
23 import gettext
24 t = gettext.translation('spacewalk-abrt', fallback=True)
25 _ = t.ugettext
26
27 from up2date_client import config
28 from up2date_client import up2dateAuth
29 from up2date_client import rhnserver
30 from up2date_client import up2dateLog
31
32 encodestring = base64.encodestring
33 if hasattr(base64, 'encodebytes'):
34 encodestring = base64.encodebytes
35
37 firstline = None
38 try:
39 f = open(filepath, 'r')
40 firstline = f.readline().strip()
41 f.close()
42 except IOError:
43 e = sys.exc_info()[1]
44 if e.errno == errno.ENOENT:
45 pass
46 else:
47 raise
48 return firstline
49
50
59
60
62 problem_dir = os.path.normpath(os.path.abspath(problem_dir))
63 basename = os.path.basename(problem_dir)
64 log = up2dateLog.initLog()
65 if not (os.path.exists(problem_dir) and os.path.isdir(problem_dir)):
66 log.log_me("The specified path [%s] is not a valid directory." % problem_dir)
67 return -1
68
69 crash_items = ['analyzer', 'cmdline', 'reason']
70 if os.path.exists(os.path.join(problem_dir, 'vmcore')):
71 crash_items = ['analyzer', 'vmcore-dmesg.txt']
72
73 for item in crash_items:
74 item_path = os.path.join(problem_dir, item)
75 if not os.path.exists(item_path):
76 log.log_me("Crash directory [%s] is incomplete or invalid" % problem_dir)
77 return -1
78
79 server = rhnserver.RhnServer()
80 if not server.capabilities.hasCapability('abrt'):
81 return -1
82
83 systemid = up2dateAuth.getSystemId()
84
85
86 pkg_data = {}
87 for item in ['package', 'pkg_name', 'pkg_epoch', 'pkg_version', 'pkg_release', 'pkg_arch']:
88 pkg_item_path = os.path.join(problem_dir, item)
89 if os.path.exists(pkg_item_path):
90 filecontent = _readline(pkg_item_path)
91
92 if filecontent:
93 pkg_data[item] = filecontent
94
95
96 crash_data = {'crash': basename, 'path': problem_dir}
97
98 crash_count = _readline(os.path.join(problem_dir, 'count'))
99 if crash_count:
100 crash_data['count'] = crash_count
101
102
103 r = server.abrt.create_crash(systemid, crash_data, pkg_data)
104
105 if (r < 0):
106 log.log_me("Error creating new crash report.")
107 return -1
108
109
110 for i in os.listdir(problem_dir):
111 path = os.path.join(problem_dir, i)
112 if not os.path.isfile(path):
113 continue
114
115 filesize = os.stat(path).st_size
116
117 crash_file_data = {'filename': os.path.basename(i),
118 'path': path,
119 'filesize': filesize,
120 'filecontent': encodestring(bstr("")),
121 'content-encoding': 'base64'}
122 if server.abrt.is_crashfile_upload_enabled(systemid) and filesize <= server.abrt.get_crashfile_uploadlimit(systemid):
123 f = open(path, 'r')
124 try:
125 crash_file_data['filecontent'] = encodestring(bstr(f.read()))
126 finally:
127 f.close()
128
129 server.abrt.upload_crash_file(systemid, basename, crash_file_data)
130
131 return 1
132
133
156
157
159 abrt_dir = os.path.normpath(_get_abrt_dir())
160 if not (os.path.exists(abrt_dir) and os.path.isdir(abrt_dir)):
161 log.log_me("The specified path [%s] is not a valid directory." % abrt_dir)
162 return -1
163
164 for i in os.listdir(abrt_dir):
165 problem_dir = os.path.join(abrt_dir, i)
166 if not os.path.isdir(problem_dir):
167 continue
168
169 report(problem_dir)
170
171 return 1
172