diff --git a/mglib/tiff.py b/mglib/tiff.py index 3756235..c539180 100644 --- a/mglib/tiff.py +++ b/mglib/tiff.py @@ -7,16 +7,33 @@ from .conf import settings logger = logging.getLogger(__name__) -def convert_tiff2pdf(doc_url): +def pdfname_from_tiffname(doc_url): + """ + Given tiff document url, will return + respective pdf file name. Returned + file name can be use used as destination + for tiff2pdf tool. - logger.debug(f"convert_tiff2pdf for {doc_url}") + Returns a tuple (new_doc_url, new_filename). + new_doc_url - is new absolute path to the pdf file + new_filename - is new pdf filename + """ # basename is filename + ext (no path) - basename = os.path.basename(doc_url) base_root, base_ext = os.path.splitext(basename) root, ext = os.path.splitext(doc_url) new_doc_url = f"{root}.pdf" + return new_doc_url, f"{base_root}.pdf" + +def convert_tiff2pdf(doc_url): + + logger.debug(f"convert_tiff2pdf for {doc_url}") + + new_doc_url, new_filename = pdfname_from_tiffname( + doc_url + ) + logger.debug( f"tiff2pdf source={doc_url} dest={new_doc_url}" ) @@ -30,4 +47,4 @@ def convert_tiff2pdf(doc_url): run(cmd) # returns new filename - return f"{base_root}.pdf" + return new_filename