Commit 3a7215ea authored by Maude Le Jeune's avatar Maude Le Jeune
Browse files

No commit message

No commit message
parent 5601df0c
from pipelet.environment import *
class PlanckEnvironment(Environment):
def my_function (self):
""" My function do nothing
"""
return
def get_data_fn (x, dmc=False, grp=None):
""" Complete the filename with the path to the working
directory.
If dmc is True a DMC object name is returned
using grp as group name and an empty file pointing to the DMC
object is made.
Parameters
----------
x: string, filename suffix
grp: string, DMC group name
Returns
-------
string, filename
"""
## dmc object
if dmc:
x = x.split(".")[0] ## remove extension
x = x+"_"+self._worker.pipe._hashes[self._worker.task.seg] ## add key
if grp is None:
logger.error ("groupname is None for DMC object %s"%x)
import piolib
x = path.join(grp, x)
dmcname = path.join(piolib.GetDataDB(), x)
locname = self._get_data_fn(x.replace("/", ":"))
os.system("touch %s"%locname)
return dmcname
## local file
else:
return self._get_data_fn(x)
def glob_default(self, x, y):
""" Return the list of filename matching y in the working
directory of segment x.
Parameters
----------
x: string, segment name
y: string, regexp of file to glob.
Returns
-------
list of filenames.
"""
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)
return glob(path.join(self._worker.pipe.get_data_dir(segx),y))\
+glob(path.join(self._worker.pipe.get_data_dir(segx),path.join('*/',y)))
def glob_seg(x, y):
""" Return the list of filename matching y in the working
directory of segment x.
Parameters
----------
x: string, segment name
y: string, regexp of file to glob.
Returns
-------
list of filenames.
"""
f = self.glob_default(x, y)
if not f:
#z = y.replace(".fits", "")
z = "*:"+y
f = self.glob_default(x, z)
if f:
lst = []
for fi in f:
## if dmc object -> replace : with /
if len(fi.split("."))==1:
lst.append(os.path.basename(fi).replace(":", "/"))
f = lst
return f
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