Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ConvertFile] Bump Docker version #33141

Merged
merged 11 commits into from Mar 4, 2024
6 changes: 6 additions & 0 deletions Packs/CommonScripts/ReleaseNotes/1_14_6.md
@@ -0,0 +1,6 @@

#### Scripts

##### ConvertFile

- Updated the Docker image to: *demisto/office-utils:2.0.0.88735*.
25 changes: 12 additions & 13 deletions Packs/CommonScripts/Scripts/ConvertFile/ConvertFile.py
Expand Up @@ -7,7 +7,6 @@
import tempfile
import shutil
import traceback
from typing import List


def find_zombie_processes():
Expand All @@ -29,35 +28,35 @@ def find_zombie_processes():
return zombies, ps_out


def convert_file(file_path: str, out_format: str, all_files: bool, outdir: str) -> List[str]:
def convert_file(file_path: str, out_format: str, all_files: bool, outdir: str) -> list[str]:
try:
run_cmd = ['soffice', '--headless', '-env:UserInstallation=file:///tmp/convertfile/.config',
'--convert-to', out_format, file_path, '--outdir', outdir]
env = os.environ.copy()
env['HOME'] = '/tmp/convertfile'
res = subprocess.check_output(run_cmd, stderr=subprocess.STDOUT, universal_newlines=True, env=env)
demisto.debug("completed running: {}. With result: {}".format(run_cmd, res))
demisto.debug(f"completed running: {run_cmd}. With result: {res}")
if all_files:
files = glob.glob(outdir + '/*')
else:
ext = out_format.split(':')[0]
files = glob.glob(outdir + '/*.' + ext)
if not files:
raise ValueError('Failed convert for output format: {}. Convert process log: {}'.format(out_format, res))
raise ValueError(f'Failed convert for output format: {out_format}. Convert process log: {res}')
return files
finally:
# make sure we don't have zombie processes (seen when converting pdf to html)
try:
zombies, ps_out = find_zombie_processes()
if zombies: # pragma no cover
demisto.info("Found zombie processes will waitpid: {}".format(ps_out))
demisto.info(f"Found zombie processes will waitpid: {ps_out}")
for pid in zombies:
waitres = os.waitpid(int(pid), os.WNOHANG)
demisto.info("waitpid result: {}".format(waitres))
demisto.info(f"waitpid result: {waitres}")
else:
demisto.debug("No zombie processes found for ps output: {}".format(ps_out))
demisto.debug(f"No zombie processes found for ps output: {ps_out}")
except Exception as ex:
demisto.error("Failed checking for zombie processes: {}. Trace: {}".format(ex, traceback.format_exc()))
demisto.error(f"Failed checking for zombie processes: {ex}. Trace: {traceback.format_exc()}")


def main():
Expand All @@ -68,8 +67,8 @@ def main():
try:
result = demisto.getFilePath(entry_id)
if not result:
return_error("Couldn't find entry id: {}".format(entry_id))
demisto.debug('going to convert: {}'.format(result))
return_error(f"Couldn't find entry id: {entry_id}")
demisto.debug(f'going to convert: {result}')
file_path = result['path']
file_path_name_only = os.path.splitext(os.path.basename(file_path))[0]
file_name = result.get('name')
Expand All @@ -78,7 +77,7 @@ def main():
with tempfile.TemporaryDirectory() as outdir:
files = convert_file(file_path, out_format, all_files, outdir)
if not files:
return_error('No file result returned for convert format: {}'.format(out_format))
return_error(f'No file result returned for convert format: {out_format}')
return
for f in files:
temp = demisto.uniqueFile()
Expand All @@ -94,9 +93,9 @@ def main():
'FileID': temp
})
except subprocess.CalledProcessError as e:
return_error("Failed converting file. Output: {}. Error: {}".format(e.output, e))
return_error(f"Failed converting file. Output: {e.output}. Error: {e}")
except Exception as e:
return_error("Failed converting file. General exception: {}.\n\nTrace:\n{}".format(e, traceback.format_exc()))
return_error(f"Failed converting file. General exception: {e}.\n\nTrace:\n{traceback.format_exc()}")


# python2 uses __builtin__ python3 uses builtins
Expand Down
2 changes: 1 addition & 1 deletion Packs/CommonScripts/Scripts/ConvertFile/ConvertFile.yml
Expand Up @@ -42,7 +42,7 @@ outputs:
description: The file type.
type: String
scripttarget: 0
dockerimage: demisto/office-utils:2.0.0.82639
dockerimage: demisto/office-utils:2.0.0.88735
runas: DBotWeakRole
tests:
- No tests (auto formatted)
6 changes: 3 additions & 3 deletions Packs/CommonScripts/Scripts/ConvertFile/ConvertFile_test.py
Expand Up @@ -53,9 +53,9 @@
assert results[0]['Type'] == entryTypes['file']
assert results[0]['File'] == 'test.html'
glob_list = glob.glob('./*' + results[0]['FileID'])
logging.getLogger().info('glob list for results: {}. list: {}'.format(results[0], glob_list))
logging.getLogger().info(f'glob list for results: {results[0]}. list: {glob_list}')
assert glob_list
with open(glob_list[0], "r") as f:
with open(glob_list[0]) as f:
contents = f.read()
assert 'Extensions to the Office Open XML' in contents
# assert the next result is an image
Expand All @@ -79,12 +79,12 @@
assert results[0]['Type'] == entryTypes['file']
assert results[0]['File'] == 'test.html'
glob_list = glob.glob('./*' + results[0]['FileID'])
logging.getLogger().info('glob list for results: {}. list: {}'.format(results[0], glob_list))
logging.getLogger().info(f'glob list for results: {results[0]}. list: {glob_list}')
assert glob_list
# check no defunct processed
zombies, output = find_zombie_processes()
assert not zombies
assert 'defunct' not in output

Check failure on line 87 in Packs/CommonScripts/Scripts/ConvertFile/ConvertFile_test.py

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

test_convert_pdf_to_html AssertionError: assert 'defunct' not in ' PID ...,state,cmd\n' 'defunct' is contained here: PID PPID S CMD 1 0 S python /src/Tests/scripts/script_runner.py coverage run -p --source=. -m pytest -v --override-ini='asyncio_mode=auto' --rootdir=/src --junitxml=/src/.pre-commit/pytest-junit/.report_pytest.xml --color=yes --files Packs/CommonScripts/Scripts/ConvertFile/ConvertFile_test.py 13 1 S /usr/local/bin/python /usr/local/bin/coverage run -p --source=. -m pytest -v --override-ini='asyncio_mode=auto' --rootdir=/src --junitxml=/src/.pre-commit/pytest-junit/.report_pytest.xml --color=yes /src/Packs/CommonScripts/Scripts/... ...Full output truncated (24 lines hidden), use '-vv' to show

Check failure on line 87 in Packs/CommonScripts/Scripts/ConvertFile/ConvertFile_test.py

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

test_convert_pdf_to_html AssertionError: assert 'defunct' not in ' PID ...,state,cmd\n' 'defunct' is contained here: PID PPID S CMD 1 0 S python /src/Tests/scripts/script_runner.py coverage run -p --source=. -m pytest -v --override-ini='asyncio_mode=auto' --rootdir=/src --junitxml=/src/.pre-commit/pytest-junit/.report_pytest.xml --color=yes --files Packs/CommonScripts/Scripts/ConvertFile/ConvertFile_test.py 14 1 S /usr/local/bin/python3.10 /usr/local/bin/coverage run -p --source=. -m pytest -v --override-ini='asyncio_mode=auto' --rootdir=/src --junitxml=/src/.pre-commit/pytest-junit/.report_pytest.xml --color=yes /src/Packs/CommonScripts/Scri... ...Full output truncated (24 lines hidden), use '-vv' to show


def test_convert_failure(mocker):
Expand Down
2 changes: 1 addition & 1 deletion Packs/CommonScripts/pack_metadata.json
Expand Up @@ -2,7 +2,7 @@
"name": "Common Scripts",
"description": "Frequently used scripts pack.",
"support": "xsoar",
"currentVersion": "1.14.5",
"currentVersion": "1.14.6",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down