virt.virt_test_utils: run_autotest - 'tar' needs relative paths to strip the leading '/'
[autotest-zwu.git] / client / common_lib / pidfile.py
blob4a9917258155586ffd1fcdbbb45b58311c438688
1 import os
4 class PidFileManager(object):
5 def __init__(self, label, results_dir):
6 self.path = os.path.join(results_dir, ".%s_execute" % label)
7 self.pid_file = None
8 self.num_tests_failed = 0
11 def open_file(self):
12 self.pid_file = open(self.path, "w")
13 self.pid_file.write("%s\n" % os.getpid())
14 self.pid_file.flush()
17 def close_file(self, exit_code, signal_code=0):
18 if not self.pid_file:
19 return
20 pid_file = self.pid_file
21 self.pid_file = None
22 encoded_exit_code = ((exit_code & 0xFF) << 8) | (signal_code & 0xFF)
23 pid_file.write("%s\n" % encoded_exit_code)
24 pid_file.write("%s\n" % self.num_tests_failed)
25 pid_file.close()