1 """Help collect and process results for submission
3 from collections import MutableMapping
8 from collections import namedtuple
10 LOGGER = logging.getLogger(__name__)
12 class ResultMap(MutableMapping):
13 """Store list of results
16 self.results_order = []
20 for item in self.results_order:
25 assert l == len(self.results_order)
28 def __setitem__(self, key, value):
29 self.results_order.append(key)
30 self.results[key] = value
32 def __getitem__(self, key):
33 return self.results[key]
35 def __delitem__(self, key):
37 i = self.results_order.index(key)
38 del self.results_order[i]
40 def add_results_from_file(self, filename):
41 pathname = os.path.abspath(filename)
42 basepath, name = os.path.split(pathname)
43 results = read_result_list(filename)
44 for lib_id, lib_path in results:
45 if not os.path.isabs(lib_path):
46 lib_path = os.path.join(basepath, lib_path)
47 self[lib_id] = lib_path
49 def make_tree_from(self, source_path, destpath = None, link=True):
50 """Create a tree using data files from source path.
53 destpath = os.getcwd()
55 LOGGER.debug("Source_path: %s", source_path)
56 LOGGER.debug("Dest_path: %s", destpath)
57 for lib_id in self.results_order:
58 lib_path = self.results[lib_id]
59 LOGGER.debug("lib_path: %s", lib_path)
60 if os.path.isabs(lib_path):
61 lib_path = os.path.relpath(lib_path, destpath)
63 LOGGER.debug('lib_path: %s', lib_path)
64 lib_destination = os.path.join(destpath, lib_path)
65 if not os.path.exists(lib_destination):
66 LOGGER.info("Making dir {0}".format(lib_destination))
67 os.mkdir(lib_destination)
69 source_rel_dir = os.path.join(source_path, lib_path)
70 source_lib_dir = os.path.abspath(source_rel_dir)
71 LOGGER.debug("source_lib_dir: %s", source_lib_dir)
73 for filename in os.listdir(source_lib_dir):
74 source_pathname = os.path.join(source_lib_dir, filename)
75 target_pathname = os.path.join(lib_destination, filename)
76 if not os.path.exists(source_pathname):
78 "{0} does not exist".format(source_pathname))
79 if not (os.path.exists(target_pathname) or os.path.isdir(source_pathname)):
81 os.symlink(source_pathname, target_pathname)
83 shutil.copy(source_pathname, target_pathname)
85 'LINK {0} to {1}'.format(source_pathname,
88 def read_result_list(filename):
90 Read a file that maps library id to result directory.
91 Does not support spaces in filenames.
96 stream = open(filename, 'r')
97 results = parse_result_list(stream)
102 def parse_result_list(stream):
106 if not line.startswith('#') and len(line) > 0:
107 library_id, result_dir = line.split()
108 results.append((library_id, result_dir))