Skip to content

Commit

Permalink
[ConvertFile] Bump Docker version (#33141)
Browse files Browse the repository at this point in the history
* Update Docker version

* Bump version

* ruff

* Bump pack from version CommonScripts to 1.14.4.

* Bump Docker version

* Bump pack from version CommonScripts to 1.14.5.

* Bump pack from version CommonScripts to 1.14.6.

---------

Co-authored-by: Content Bot <bot@demisto.com>
  • Loading branch information
MichaelYochpaz and Content Bot committed Mar 4, 2024
1 parent 8e01a4c commit 7f45027
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
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 @@ def test_convert_to_html(mocker):
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,7 +79,7 @@ def test_convert_pdf_to_html(mocker):
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()
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

0 comments on commit 7f45027

Please sign in to comment.