Live logging (requires unbuffered program output from stitching)
This commit is contained in:
parent
aed5a22983
commit
e6eb4d419d
1 changed files with 24 additions and 14 deletions
|
|
@ -14,7 +14,7 @@ from scipy.stats import norm
|
||||||
from scipy.ndimage import zoom
|
from scipy.ndimage import zoom
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from subprocess import CompletedProcess, Popen, PIPE, SubprocessError, run
|
from subprocess import CompletedProcess, Popen, PIPE, SubprocessError, run, STDOUT
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
import glob
|
import glob
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
@ -1003,12 +1003,29 @@ class SmartScanThing(Thing):
|
||||||
) -> CompletedProcess:
|
) -> CompletedProcess:
|
||||||
"""Run a subprocess and log any output"""
|
"""Run a subprocess and log any output"""
|
||||||
logger.info(f"Running command in subprocess: `{' '.join(cmd)}`")
|
logger.info(f"Running command in subprocess: `{' '.join(cmd)}`")
|
||||||
output = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
|
|
||||||
for pipe in [output.stdout, output.stderr]:
|
|
||||||
if pipe:
|
p = Popen(cmd, stdout=PIPE, stderr = STDOUT, bufsize=1, universal_newlines=True)
|
||||||
logger.info(pipe)
|
os.set_blocking(p.stdout.fileno(), False)
|
||||||
output.check_returncode()
|
logger.info(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
|
||||||
return output
|
while p.poll() == None:
|
||||||
|
try:
|
||||||
|
output = p.stdout.readline()
|
||||||
|
if output != "" and output != None:
|
||||||
|
logger.info(output)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for line in p.stdout:
|
||||||
|
try:
|
||||||
|
output = p.stdout.readline()
|
||||||
|
if output != "" and output != None:
|
||||||
|
logger.info(output)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
logger.info('Stitching complete')
|
||||||
|
return p
|
||||||
|
|
||||||
@thing_action
|
@thing_action
|
||||||
def stitch_scan(self, logger: InvocationLogger, scan_name: Optional[str]=None, overlap: float = 0.0) -> None:
|
def stitch_scan(self, logger: InvocationLogger, scan_name: Optional[str]=None, overlap: float = 0.0) -> None:
|
||||||
|
|
@ -1039,13 +1056,6 @@ class SmartScanThing(Thing):
|
||||||
raise FileNotFoundError(f"Tried to make a zip archive of {images_folder} but it does not exist.")
|
raise FileNotFoundError(f"Tried to make a zip archive of {images_folder} but it does not exist.")
|
||||||
# logger.info("Creating zip archive of images (may take some time)...")
|
# logger.info("Creating zip archive of images (may take some time)...")
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
root_directory = Path(images_folder)
|
|
||||||
print(sum(f.stat().st_size for f in root_directory.glob('**/*') if f.is_file()))
|
|
||||||
|
|
||||||
zip_fname = f'{os.path.join(scan_folder, "images")}.zip'
|
|
||||||
|
|
||||||
# Create an empty zip file - we don't want to autofill it with files,
|
# Create an empty zip file - we don't want to autofill it with files,
|
||||||
# as some of them should only be added at the end (as we can't overwrite)
|
# as some of them should only be added at the end (as we can't overwrite)
|
||||||
# them once they change
|
# them once they change
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue