Commit 423d83a5 authored by Betoule Marc's avatar Betoule Marc
Browse files

Try to make glob_seg specific to the fatherhood

parent 423d1c24
......@@ -182,25 +182,33 @@ class Environment(EnvironmentBase):
self.logger.info ("hooking %s"%hook_name)
return self._hook(hook_name, glo)
def glob_seg(self, x, y):
def glob_seg(self, y, segs=None):
""" Globbing limited to the fatherhood
For unlimited globbing see glob_seg_all.
Parameters
----------
x: string, segment name
y: string, globbing pattern
segs: List of segment to glob in
Returns
-------
Return the list of filename matching the pattern y in the
data directory of parent tasks from the parent segment x.
data directory of parent tasks.
"""
segx = self._worker.pipe.find_seg(self._worker.task.seg, x)
if segx is None:
self.logger.warning("No parent segment matching %s found"%x)
str_parents = self._worker.task.str_parents
if segs is None:
segs = str_parents.keys
res=[]
for x in segs:
segx = self._worker.pipe.find_seg(self._worker.task.seg, x)
if segx is None:
self.logger.warning("No parent segment matching %s found"%x)
for t in str_parents[segx]:
res+=glob(path.join(self._worker.pipe.get_data_dir(segx),t,y))
return res
def glob_seg_all(self, x, y):
""" Return the list of filename matching y in the working
directory of segment x.
......
......@@ -59,7 +59,7 @@ class Task:
## List of the task id whose output become the input of this task
self.parents = parents
## List of str_input of the parent tasks
self.str_parents = []
self.str_parents = {}
def __str__(self):
......
......@@ -169,7 +169,8 @@ class SqliteTracker(Tracker,threading.Thread):
## dictionnary of segment ids
self.seg_id_cache = {}
self.seg_name_cache = {}
## string, sql filename
self.sqlfile = path.join(pipe._prefix,'.sqlstatus')
if self.pipe.sqlfile is not None:
......@@ -214,6 +215,7 @@ class SqliteTracker(Tracker,threading.Thread):
'select seg_id from segments where curr_dir = ? limit 1',
(curr_dir,)).fetchone()[0]
self.seg_id_cache[s] = seg_id
self.seg_name_cache[seg_id] = s
logger.debug("Segment %s instance (%s) already registered in db."%(s, curr_dir))
except TypeError:
logger.debug("Creating segment %s instance (%s)."%(s, curr_dir))
......@@ -222,6 +224,7 @@ class SqliteTracker(Tracker,threading.Thread):
,(s, curr_dir, docline))
seg_id = c.lastrowid
self.seg_id_cache[s] = seg_id
self.seg_name_cache[seg_id] = s
logger.debug("Storing connectivity for segment %s."%s)
for p in self.pipe._parents[s]:
......@@ -327,9 +330,13 @@ class SqliteTracker(Tracker,threading.Thread):
logger.debug('for task:\n%s\nparents:\n%s\n'%(str(t),str(t.parents)))
self.conn.executemany('insert into task_relations (father_id, child_id) values (?, ?)',((fid, t.id) for fid in t.parents))
for fid in t.parents:
c = self.conn.execute('select str_input from tasks where task_id=?', ((fid,)))
c = self.conn.execute('select seg_id, str_input from tasks where task_id=?', ((fid,)))
for e in c:
t.str_parents.append(e[0])
s = self.seg_name_cache[e[0]]
try:
t.str_parents[s].append(e[1])
except KeyError:
t.str_parents[s] = [e[1]]
return t
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment