Delete old function in global_common, and remove useless stuff from container.convert

This commit is contained in:
Micah Lee 2021-11-23 16:20:51 -08:00
parent edbd3aa88a
commit 7c4f35e0f8
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
4 changed files with 1 additions and 39 deletions

View file

@ -101,7 +101,6 @@ def cli_main(output_filename, ocr_lang, filename):
click.echo(f"Invalid JSON returned from container: {line}")
if convert(
global_common,
common.input_filename,
common.output_filename,
ocr_lang,

View file

@ -56,7 +56,7 @@ def exec_container(args, stdout_callback=None):
return exec(args, stdout_callback)
def convert(global_common, input_filename, output_filename, ocr_lang, stdout_callback):
def convert(input_filename, output_filename, ocr_lang, stdout_callback):
success = False
if ocr_lang:
@ -73,8 +73,6 @@ def convert(global_common, input_filename, output_filename, ocr_lang, stdout_cal
os.makedirs(pixel_dir, exist_ok=True)
os.makedirs(safe_dir, exist_ok=True)
container_output_filename = os.path.join(safe_dir, "safe-output-compressed.pdf")
# Convert document to pixels
args = [
"run",
@ -113,9 +111,6 @@ def convert(global_common, input_filename, output_filename, ocr_lang, stdout_cal
if ret != 0:
print("pixels-to-pdf failed")
else:
# Move the final file to the right place
os.rename(container_output_filename, output_filename)
# We did it
success = True

View file

@ -411,9 +411,6 @@ class GlobalCommon(object):
resource_path = os.path.join(prefix, filename)
return resource_path
def exec_dangerzone_container(self, input_filename, output_filename, ocr_lang):
convert(self, input_filename, output_filename, ocr_lang)
def get_subprocess_startupinfo(self):
if platform.system() == "Windows":
startupinfo = subprocess.STARTUPINFO()
@ -422,34 +419,6 @@ class GlobalCommon(object):
else:
return None
def container_exists(self, container_name):
"""
Check if container_name is a valid container. Returns a tuple like:
(success (boolean), error_message (str))
"""
# Do we have this container?
with self.exec_dangerzone_container(
["ls", "--container-name", container_name]
) as p:
stdout_data, _ = p.communicate()
lines = stdout_data.split(b"\n")
if b"> " in lines[0]:
stdout_data = b"\n".join(lines[1:])
# The user canceled, or permission denied
if p.returncode == 126 or p.returncode == 127:
return False, "Authorization failed"
return
elif p.returncode != 0:
return False, "Container error"
return
# Check the output
if container_name.encode() not in stdout_data:
return False, f"Container '{container_name}' not found"
return True, True
def install_container(self):
"""
Make sure the podman container is installed. Linux only.

View file

@ -499,7 +499,6 @@ class ConvertThread(QtCore.QThread):
]
if convert(
self.global_common,
self.common.input_filename,
self.common.output_filename,
ocr_lang,