1 """Help collect and process results for submission
3 from collections import MutableMapping
7 from collections import namedtuple
9 LOGGER = logging.getLogger(__name__)
11 class ResultMap(MutableMapping):
12 """Store list of results
15 self.results_order = []
19 for item in self.results_order:
24 assert l == len(self.results_order)
27 def __setitem__(self, key, value):
28 self.results_order.append(key)
29 self.results[key] = value
31 def __getitem__(self, key):
32 return self.results[key]
34 def __delitem__(self, key):
36 i = self.results_order.index(key)
37 del self.results_order[i]
39 def add_results_from_file(self, filename):
40 pathname = os.path.abspath(filename)
41 basepath, name = os.path.split(pathname)
42 results = read_result_list(filename)
43 for lib_id, lib_path in results:
44 if not os.path.isabs(lib_path):
45 lib_path = os.path.join(basepath, lib_path)
46 self[lib_id] = lib_path
48 def make_tree_from(self, source_path, destpath = None):
49 """Create a tree using data files from source path.
52 destpath = os.getcwd()
54 for lib_id in self.results_order:
55 lib_path = self.results[lib_id]
56 lib_destination = os.path.join(destpath, lib_path)
57 if not os.path.exists(lib_destination):
58 LOGGER.info("Making dir {0}".format(lib_destination))
59 os.mkdir(lib_destination)
61 source_rel_dir = os.path.join(source_path, lib_path)
62 source_lib_dir = os.path.abspath(source_rel_dir)
64 for filename in os.listdir(source_lib_dir):
65 source_pathname = os.path.join(source_lib_dir, filename)
66 target_pathname = os.path.join(lib_destination, filename)
67 if not os.path.exists(source_pathname):
69 "{0} does not exist".format(source_pathname))
70 if not os.path.exists(target_pathname):
71 os.symlink(source_pathname, target_pathname)
73 'LINK {0} to {1}'.format(source_pathname,
76 def read_result_list(filename):
78 Read a file that maps library id to result directory.
79 Does not support spaces in filenames.
84 stream = open(filename, 'r')
85 results = parse_result_list(stream)
90 def parse_result_list(stream):
94 if not line.startswith('#') and len(line) > 0:
95 library_id, result_dir = line.split()
96 results.append((library_id, result_dir))