From b5df44c75922d0bd952240d9a11dd0667bdc6784 Mon Sep 17 00:00:00 2001 From: BO ZHANG Date: Fri, 11 Aug 2023 23:14:05 +0800 Subject: [PATCH] tweaks --- csst_common/pipeline.py | 9 +++++++-- csst_common/time.py | 15 --------------- csst_common/wrapper.py | 10 +++++----- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/csst_common/pipeline.py b/csst_common/pipeline.py index 851df60..72ac210 100644 --- a/csst_common/pipeline.py +++ b/csst_common/pipeline.py @@ -13,7 +13,6 @@ from .logger import get_logger class Pipeline: def __init__( self, - name="", dir_in="/pipeline/input", dir_out="/pipeline/output", dir_aux="/pipeline/aux", @@ -28,7 +27,11 @@ class Pipeline: dfs=True, crds=False, ): - self.name = name + # get pipeline information from environ + self.name = os.getenv("PIPELINE", "-") + self.build = os.getenv("BUILD", "-") + + # set directory information self.dir_in = dir_in self.dir_out = dir_out self.dir_aux = dir_aux @@ -37,10 +40,12 @@ class Pipeline: self.crds_cache = crds_cache self.clean = clean + # set resource information self.n_jobs_cpu = n_jobs_cpu self.n_jobs_gpu = n_jobs_gpu self.device = device.upper() + # set logger self.pipeline_logger = get_logger(name="pipeline", filename=os.path.join(self.dir_out, "pipeline.log")) self.module_logger = get_logger(name="module", filename=os.path.join(self.dir_out, "module.log")) diff --git a/csst_common/time.py b/csst_common/time.py index fe5d6bc..7c14655 100644 --- a/csst_common/time.py +++ b/csst_common/time.py @@ -1,7 +1,5 @@ import datetime -from astropy import time - def now(): """ Return ISOT8601 format datetime, for time stamps in data products. """ @@ -11,16 +9,3 @@ def now(): def now_dfs(): """ Return ISOT8601 format datetime, for DFS usage only. """ return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') - - -class TimeStamp: - def __init__(self, file_path=""): - self.file_path = file_path - - def truncate(self): - with open(self.file_path, 'w') as file: - file.truncate(0) - - def punch_in(self): - with open(self.file_path, "a+") as f: - f.write(f"{time.Time.now().isot}+00:00\n") diff --git a/csst_common/wrapper.py b/csst_common/wrapper.py index 368a2b0..a8ddb81 100644 --- a/csst_common/wrapper.py +++ b/csst_common/wrapper.py @@ -9,7 +9,7 @@ from csst_common.data_manager import CsstMsDataManager from csst_common.file_recorder import FileRecorder from csst_common.status import CsstStatus -__all__ = ["ModuleResult", "l1ppl_module"] +__all__ = ["ModuleResult", "l1ppl_module", "module_wrapper"] # module should return ModuleResult as result ModuleResult = namedtuple("ModuleResult", ["module", "timecost", "status", "fr", "output"]) @@ -100,6 +100,7 @@ def module_wrapper(func): if __name__ == "__main__": + @l1ppl_module def call_add(dm, a, b): if isinstance(a, float) and isinstance(b, float): @@ -107,7 +108,6 @@ if __name__ == "__main__": else: return ModuleResult(CsstStatus.ERROR, None, (a, b)) - - dm = CsstMsDataManager() - print(call_add(dm, 1., 2.)) - print(call_add(dm, 1., None)) + # dm = CsstMsDataManager() + # print(call_add(dm, 1., 2.)) + # print(call_add(dm, 1., None)) -- GitLab