1 import os
, sys
, datetime
, re
4 _debug_logger
= sys
.stderr
6 print >> _debug_logger
, msg
9 def redirect_parser_debugging(ostream
):
11 _debug_logger
= ostream
14 def get_timestamp(mapping
, field
):
15 val
= mapping
.get(field
, None)
17 val
= datetime
.datetime
.fromtimestamp(int(val
))
21 def find_toplevel_job_dir(start_dir
):
22 """ Starting from start_dir and moving upwards, find the top-level
23 of the job results dir. We can't just assume that it corresponds to
24 the actual job.dir, because job.dir may just be a subdir of the "real"
25 job dir that autoserv was launched with. Returns None if it can't find
28 while not os
.path
.exists(os
.path
.join(job_dir
, ".autoserv_execute")):
31 job_dir
= os
.path
.dirname(job_dir
)
35 def drop_redundant_messages(messages
):
36 """ Given a set of message strings discard any 'redundant' messages which
37 are simple a substring of the existing ones.
39 @param messages - a set of message strings
41 @return - a subset of messages with unnecessary strings dropped
43 sorted_messages
= sorted(messages
, key
=len, reverse
=True)
44 filtered_messages
= set()
45 for message
in sorted_messages
:
46 for filtered_message
in filtered_messages
:
47 if message
in filtered_message
:
50 filtered_messages
.add(message
)
51 return filtered_messages
54 def get_afe_job_id(tag
):
55 """ Given a tag return the afe_job_id (if any).
58 tag: afe_job_id is extracted from this tag
61 returns the afe_job_id if regex matches, else return ''
64 match
= re
.search('^([0-9]+)-.+/.+$', tag
)