Skip to content

Commit

Permalink
Apply github/super-linter@v4 diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Oct 10, 2024
1 parent 393a4d1 commit 287f6b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
22 changes: 8 additions & 14 deletions files/galaxy_jwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ def main():
backends = parse_object_store(object_store_conf)

# Add pulsar staging directory (runner: pulsar_embedded) to backends
backends["pulsar_embedded"] = get_pulsar_staging_dir(
galaxy_pulsar_app_conf
)
backends["pulsar_embedded"] = get_pulsar_staging_dir(galaxy_pulsar_app_conf)

# Connect to Galaxy database
db = Database(
Expand All @@ -181,9 +179,7 @@ def main():
if args.operation == "get":
job_id = args.job_id
object_store_id, job_runner_name = db.get_job_info(job_id)
jwd_path = decode_path(
job_id, [object_store_id], backends, job_runner_name
)
jwd_path = decode_path(job_id, [object_store_id], backends, job_runner_name)

# Check
if jwd_path:
Expand All @@ -200,8 +196,7 @@ def main():
# Check if the given Galaxy log directory exists
if not os.path.isdir(galaxy_log_dir):
raise ValueError(
f"The given Galaxy log directory {galaxy_log_dir} does not"
f"exist"
f"The given Galaxy log directory {galaxy_log_dir} does not" f"exist"
)

# Set variables
Expand Down Expand Up @@ -299,7 +294,7 @@ def parse_object_store(object_store_conf: str) -> dict:
"""
if object_store_conf.endswith(".xml"):
return parse_object_store_xml(object_store_conf)
if object_store_conf.split('.')[-1] in ('yml', 'yaml'):
if object_store_conf.split(".")[-1] in ("yml", "yaml"):
return parse_object_store_yaml(object_store_conf)
raise ValueError("Invalid object store configuration file extension")

Expand All @@ -321,11 +316,11 @@ def parse_object_store_yaml(object_store_conf: str) -> dict:
with open(object_store_conf, "r") as f:
data = yaml.safe_load(f)
backends = {}
for backend in data['backends']:
backend_id = backend['id']
for backend in data["backends"]:
backend_id = backend["id"]
backends[backend_id] = {}
# Get the extra_dir's path for each backend if type is "job_work"
if 'extra_dirs' in backend:
if "extra_dirs" in backend:
for extra_dir in backend["extra_dirs"]:
if extra_dir.get("type") == "job_work":
backends[backend_id] = extra_dir["path"]
Expand Down Expand Up @@ -390,8 +385,7 @@ def decode_path(
jwd_path = f"{backends_dict['pulsar_embedded']}/{job_id}"
else:
jwd_path = (
f"{backends_dict[metadata[0]]}/"
f"0{job_id[0:2]}/{job_id[2:5]}/{job_id}"
f"{backends_dict[metadata[0]]}/" f"0{job_id[0:2]}/{job_id[2:5]}/{job_id}"
)

# Validate that the path is a JWD
Expand Down
36 changes: 17 additions & 19 deletions files/walle.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ def collect_files_in_a_directory(
continue
file = pathlib.Path(os.path.join(root, filename))
file_stat = file.stat()
if not file_in_size_range(
file_stat, args.min_size, args.max_size
):
if not file_in_size_range(file_stat, args.min_size, args.max_size):
logger.debug(f"File {file} not in size range")
elif not file_accessed_in_range(file_stat, args.since):
logger.debug(f"File {file} not in access date range")
Expand Down Expand Up @@ -472,7 +470,9 @@ def scan_file_for_malware(
sha1 = None
for malware in lib:
if malware.crc32 == crc32:
logger.debug(f"File {file} CRC32 matches {malware.program} {malware.version}")
logger.debug(
f"File {file} CRC32 matches {malware.program} {malware.version}"
)
if sha1 is None:
sha1 = digest_file_sha1(chunksize, file)
if malware.sha1 == sha1:
Expand All @@ -485,9 +485,11 @@ def scan_file_for_malware(


def report_matching_malware(job: Job, malware: Malware, path: pathlib.Path) -> str:
return (f"Job user: {job.user_name} Job ID: {job.galaxy_id}"
f"{malware.malware_class} {malware.program} {malware.version}"
f" {path}")
return (
f"Job user: {job.user_name} Job ID: {job.galaxy_id}"
f"{malware.malware_class} {malware.program} {malware.version}"
f" {path}"
)


def construct_malware_list(malware_yaml: dict) -> [Malware]:
Expand Down Expand Up @@ -619,27 +621,23 @@ def kill_job(job: Job, debug=False):
serial_args = [
[
GXADMIN_PATH,
'mutate',
'fail-job',
"mutate",
"fail-job",
str(job.galaxy_id),
'--commit',
"--commit",
],
[
GXADMIN_PATH,
'mutate',
'fail-terminal-datasets',
'--commit',
"mutate",
"fail-terminal-datasets",
"--commit",
],
]
for args in serial_args:
if debug:
logger.debug(f"COMMAND: {' '.join(args)}")
try:
result = subprocess.run(
args,
check=True,
capture_output=True,
text=True)
result = subprocess.run(args, check=True, capture_output=True, text=True)
if debug:
if result.stdout:
logger.debug(f"COMMAND STDOUT:\n{result.stdout}")
Expand All @@ -662,7 +660,7 @@ def evaluate_match_for_deletion(
args = make_parser().parse_args()
logging.basicConfig(
level=logging.DEBUG if args.debug else logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
format="%(asctime)s - %(levelname)s - %(message)s",
)
logger.info("Starting scan...")
jwd_getter = JWDGetter()
Expand Down

0 comments on commit 287f6b4

Please sign in to comment.