def test_stderr(self): """ Stderr should be printed to stderr and logged""" tmp_file = os.path.join(tmp_dir_path, 'tmp_log') saved_stderr = sys.stderr tmp_stderr = os.path.join(tmp_dir_path, 'tmp_stderr') with open(tmp_stderr, 'w') as sys.stderr: with EppLogger(tmp_file, prepend=False) as epp_logger: print('stderr nosetest', file=sys.stderr) sys.stderr = saved_stderr with open(tmp_stderr, 'r') as stderr: stream_lines = stderr.readlines() assert 'stderr nosetest' in stream_lines[-1] with open(tmp_file, 'r') as log_file: log_lines = log_file.readlines() assert 'stderr nosetest' in log_lines[-1]
def test_stdout(self): """ Stdout should be logged but not printed""" tmp_file = os.path.join(tmp_dir_path, 'tmp_log') saved_stdout = sys.stdout tmp_stdout = os.path.join(tmp_dir_path, 'tmp_stdout') with open(tmp_stdout, 'w') as sys.stdout: with EppLogger(tmp_file, prepend=False) as epp_logger: print('stdout nosetest', file=sys.stdout) sys.stdout = saved_stdout with open(tmp_stdout, 'r') as stdout: stream_lines = stdout.readlines() assert not stream_lines with open(tmp_file, 'r') as log_file: log_lines = log_file.readlines() assert 'stdout nosetest' in log_lines[-1]
x for x in io if x[1]['output-generation-type'] == 'PerInput' ] # Fetch the first input-output artifact pair (input, output) = io_filtered[0] # Instantiate the output artifact output_artifact = Artifact(output['limsid']) # Attach the file attach_file(args.file, output_artifact) if __name__ == "__main__": parser = ArgumentParser() # Arguments that are useful in all EPP scripts parser.add_argument("--log", default=sys.stdout, help="Log file") # Arguments specific for this scripts task parser.add_argument("--pid", help="Process id") parser.add_argument("--file", help="File to upload") args = parser.parse_args() # Log everything to log argument with EppLogger(args.log): lims = Lims(BASEURI, USERNAME, PASSWORD) lims.check_version() main(lims, args.pid, args.file)
"measurement!".format(R2)) else: QiT.missing_udfs.append('Linearity of standards') if QiT.missing_samps: QiT.abstract.append("The following samples are missing in Quant-iT " "result File 1 or 2: {0}.".format(', '.join( QiT.missing_samps))) if QiT.missing_udfs: QiT.abstract.append("Are all of the following udfs set? : {0}".format( ', '.join(QiT.missing_udfs))) print >> sys.stderr, ' '.join(QiT.abstract) if __name__ == "__main__": parser = ArgumentParser(description=DESC) parser.add_argument('--pid', default=None, dest='pid', help='Lims id for current Process') parser.add_argument('--log', dest='log', help=('File name for standard log file, ' 'for runtime information and problems.')) args = parser.parse_args() lims = Lims(BASEURI, USERNAME, PASSWORD) lims.check_version() with EppLogger(log_file=args.log, lims=lims, prepend=True) as epp_logger: main(lims, args.pid, epp_logger)
elif lines: # Avoid printing empty files lp_args = ["lp"] if args.hostname: #remove that when all the calls to this script have been updated if args.hostname == 'homer.scilifelab.se:631': args.hostname='homer2.scilifelab.se:631' lp_args += ["-h",args.hostname] if args.destination: lp_args += ["-d",args.destination] lp_args.append("-") # lp accepts stdin if '-' is given as filename logging.info('Ready to call lp for printing.') sp = subprocess.Popen(lp_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) sp.stdin.write(str('\n'.join(lines))) logging.info('lp command is called for printing.') stdout,stderr = sp.communicate() # Will wait for sp to finish logging.info('lp stdout: {0}'.format(stdout)) logging.info('lp stderr: {0}'.format(stderr)) logging.info('lp command finished') sp.stdin.close() if __name__ == '__main__': arguments = getArgs() lims = Lims(BASEURI,USERNAME,PASSWORD) lims.check_version() prepend = not arguments.no_prepend with EppLogger(arguments.log,lims=lims,prepend=prepend) as epp_logger: main(arguments,lims,epp_logger)