Skip to content

Commit fd19733

Browse files
committed
fix code
1 parent 0a2b9e8 commit fd19733

File tree

1 file changed

+55
-39
lines changed

1 file changed

+55
-39
lines changed

autosubmit/autosubmit.py

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5271,59 +5271,75 @@ def select_jobs_by_chunks(job_list: "JobList",
52715271
52725272
:param job_list: JobList object
52735273
:param filter_chunks: filter chunks
5274+
:return: list of jobs matching the filter
52745275
"""
5275-
def _prune_jobs(matching_jobs: list[Job], members: list[str], dates: list[str], chunks: int) -> list[Job]:
5276-
"""Return jobs from *matching_jobs* that match the given members, dates and chunk limits.
52775276

5278-
- If \"ANY\" is present in *members*, member and chunk checks are skipped.
5279-
- If \"ANY\" is present in *dates*, date checks are skipped.
5277+
def _setup_prune(json_filter: dict[str, Any]) -> tuple[list[str], list[str], int]:
5278+
"""Setup dates, members and chunks from json_filter.
5279+
5280+
:param json_filter: json filter with dates, members and chunks
5281+
:return: tuple of (dates, members, chunks)
5282+
"""
5283+
dates = []
5284+
members = []
5285+
chunks = 0
5286+
for d_json in json_filter['sds']:
5287+
if "ANY" == str(d_json['sd']).upper():
5288+
return [], [], len(job_list._chunk_list)
5289+
dates.append(d_json['sd'])
5290+
for m_json in d_json['ms']:
5291+
members.append(m_json['m'])
5292+
if str(m_json['cs'][0]).upper() == "ANY":
5293+
chunks = len(job_list._chunk_list)
5294+
else:
5295+
chunks = max(len(m_json['cs']), chunks)
5296+
chunks = min(chunks, len(job_list._chunk_list))
5297+
return dates, members, chunks
5298+
5299+
def _prune_jobs(jobs: list[Job], dates: list[str], members: list[str], chunks: int) -> list[Job]:
5300+
"""Return jobs from *jobs* that match the given members, dates and chunk limits.
5301+
:param jobs: list of jobs to prune
5302+
:param dates: list of dates to match
5303+
:param members: list of members to match
5304+
:param chunks: maximum chunk number to match
5305+
:return: pruned list of jobs
52805306
"""
5281-
any_member = "ANY" in members
5282-
any_date = "ANY" in dates
5307+
if "ANY" in dates:
5308+
return jobs
5309+
else:
5310+
return [j for j in jobs if
5311+
(
5312+
(j.date and date2str(j.date, "D") in dates)
5313+
and (j.member and (("ANY" in members) or (j.member.upper() in members)))
5314+
and (not j.synchronize or (j.chunk and j.chunk <= chunks))
5315+
)
5316+
]
52835317

5284-
def matches(job: Job) -> bool:
5285-
"""Return True if *job* passes member, chunk and date checks."""
5286-
if not any_member:
5287-
if not (getattr(job, "member", None) and job.member.upper() in members):
5288-
return False
5289-
if not (getattr(job, "chunk", None) and job.chunk <= chunks):
5290-
return False
5291-
if not any_date:
5292-
if not (getattr(job, "date", None) and date2str(job.date, "D") in dates):
5293-
return False
5294-
return True
5318+
final_list = []
52955319

5296-
return [job for job in matching_jobs if matches(job)]
5320+
if not filter_chunks or not isinstance(filter_chunks, str):
5321+
return []
52975322

5298-
final_list = []
52995323
filter_chunks = filter_chunks.upper()
5300-
sections = filter_chunks.split(",")[1:]
5301-
sections = [sect.strip(" ,") for sect in sections]
5302-
if "ANY" in sections:
5303-
matching_jobs = job_list.get_job_list()
5324+
matching_jobs = job_list.get_job_list()
5325+
if "," in filter_chunks:
5326+
splitted_filters = filter_chunks.split(",")
5327+
fc = splitted_filters[0]
5328+
sections = splitted_filters[1:]
5329+
sections = [sect.strip(" ,") for sect in sections]
5330+
if "ANY" not in sections:
5331+
matching_jobs = [job for job in matching_jobs if job.section in sections]
53045332
else:
5305-
matching_jobs = [job for job in job_list.get_job_list() if job.section in sections]
5333+
fc = filter_chunks
53065334

5307-
fc = filter_chunks
5308-
# Any located in chunks part
53095335
if str(fc).upper() != "ANY":
53105336
data = json.loads(Autosubmit._create_json(fc))
53115337

53125338
# Prune jobs by selected dates, members, chunks
5313-
dates = []
5314-
members = []
5315-
chunks = 0
5316-
for date_json in data['sds']:
5317-
dates.append(date_json['sd'])
5318-
for member_json in date_json['ms']:
5319-
members.append(member_json['m'])
5320-
if str(member_json['cs'][0]).upper() == "ANY":
5321-
chunks = len(job_list._chunk_list)
5322-
else:
5323-
chunks = max(len(member_json['cs']), chunks)
5324-
chunks = min(chunks, len(job_list._chunk_list))
5325-
matching_jobs = _prune_jobs(matching_jobs, members, dates, chunks)
5339+
filtered_dates, filtered_members, filtered_chunks = _setup_prune(data)
5340+
matching_jobs = _prune_jobs(matching_jobs, filtered_dates, filtered_members, filtered_chunks)
53265341

5342+
# Now, build final list according to the structure in data
53275343
for date_json in data['sds']:
53285344
date = date_json['sd']
53295345
jobs_of_this_date = [j for j in matching_jobs if date2str(j.date, "D") == date]

0 commit comments

Comments
 (0)