""" DCM Relay Error files """ body += "Begin Error files...\n" for err in glob(os.path.expanduser('~/dcmrelay/*.err')): text_lines = [] text_lines.append("Begin %s..." % err) out, _ = tail(err, n=20) text_lines.append(out) text_lines.append("End %s.\n\n" % err) body += '\n'.join(text_lines) body += "End Error files.\n" """ Xnat statistics """ body += "XNAT system statistics...\n" x = xnat() body += "# users: %d\n" % len(x.manage.users()) all_projs = x.select.projects().get() body += "# projects: %d\n" % len(all_projs) # There's probably a better way to do this, but for now... all_sessions = [] for p in all_projs: proj = x.select.project(p) all_sessions.extend(proj.experiments().get()) body += "# sessions: %d\n" % len(all_sessions) # We could go deeper into database if we wanted... body += "Finish at %s" % time.strftime('%H:%M:%S') to = ['*****@*****.**', '*****@*****.**'] sub = "XNAT Health Check %s" % time.strftime('%a %d %b %Y %H:%M') mail(to=to, subject=sub, body=body)
# TODO Fix # We probably are using --force pass try: new_files, message = mirror(xsub.label(), xexp, dcm_dir) # Make new files only readable to owner and group [chmod_440(f) for f in new_files] # Touch touch_file open(touch_file(top_dir), "w").close() email_body += "\n".join(new_files) email_body += message if args.convert_nii: email_body += "\n\nDoing DCM --> NII conversion...\n\n" if new_files: nii_dir = os.path.join(top_dir, "NIFTI") if not os.path.isdir(nii_dir): os.makedirs(nii_dir) output = dcm_to_nii(new_files[0], nii_dir) email_body += output else: email_body += "No new files to convert\n" except MirrorError as e: email_body += "ERROR OCCURED DURING MIRROR FUNCTION\n" email_body += e.args else: # Skip to next subject pass if email_body: email_subject = "%s: Automatic Import Report" % args.project mail(TO, email_subject, email_body)