Python sys.stderr() Examples
The following are 30
code examples of sys.stderr().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.

Example #1
Source File: test.py From aegea with Apache License 2.0 | 16 votes |
def call(self, cmd, **kwargs): print('Running "{}"'.format(cmd), file=sys.stderr) expect = kwargs.pop("expect", [dict(return_codes=[os.EX_OK], stdout=None, stderr=None)]) process = subprocess.Popen(cmd, stdin=kwargs.get("stdin", subprocess.PIPE), stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) out, err = process.communicate() return_code = process.poll() out = out.decode(sys.stdin.encoding) err = err.decode(sys.stdin.encoding) def match(return_code, out, err, expected): exit_ok = return_code in expected["return_codes"] stdout_ok = re.search(expected.get("stdout") or "", out) stderr_ok = re.search(expected.get("stderr") or "", err) return exit_ok and stdout_ok and stderr_ok if not any(match(return_code, out, err, exp) for exp in expect): print(err) e = subprocess.CalledProcessError(return_code, cmd, output=out) e.stdout, e.stderr = out, err raise e return self.SubprocessResult(out, err, return_code)
Example #2
Source File: util.py From mlbv with GNU General Public License v3.0 | 10 votes |
def init_logging(log_file=None, append=False, console_loglevel=logging.INFO): """Set up logging to file and console.""" if log_file is not None: if append: filemode_val = 'a' else: filemode_val = 'w' logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s", # datefmt='%m-%d %H:%M', filename=log_file, filemode=filemode_val) # define a Handler which writes INFO messages or higher to the sys.stderr console = logging.StreamHandler() console.setLevel(console_loglevel) # set a format which is simpler for console use formatter = logging.Formatter("%(message)s") console.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(console) global LOG LOG = logging.getLogger(__name__)
Example #3
Source File: train_models.py From Turku-neural-parser-pipeline with Apache License 2.0 | 8 votes |
def create_model_directory(args): # create necessary directories if os.path.isdir("models_{name}".format(name=args.name)): print("Directory models_{name} already exists, old files will be overwritten".format(name=args.name), file=sys.stderr) else: os.mkdir("models_{name}".format(name=args.name)) os.mkdir("models_{name}/Data".format(name=args.name)) os.mkdir("models_{name}/Tokenizer".format(name=args.name)) # copy necessary files if args.embeddings: # embeddings copyfile(args.embeddings, "models_{name}/Data/embeddings.vectors".format(name=args.name)) copyfile("{config}/pipelines.yaml".format(config=args.config_directory), "models_{name}/pipelines.yaml".format(name=args.name)) process_morpho(args) # train/dev files for tagger/parser process_config(args) # configs for tagger/parser
Example #4
Source File: notify.py From wechat-alfred-workflow with MIT License | 7 votes |
def convert_image(inpath, outpath, size): """Convert an image file using ``sips``. Args: inpath (str): Path of source file. outpath (str): Path to destination file. size (int): Width and height of destination image in pixels. Raises: RuntimeError: Raised if ``sips`` exits with non-zero status. """ cmd = [ b'sips', b'-z', str(size), str(size), inpath, b'--out', outpath] # log().debug(cmd) with open(os.devnull, 'w') as pipe: retcode = subprocess.call(cmd, stdout=pipe, stderr=subprocess.STDOUT) if retcode != 0: raise RuntimeError('sips exited with %d' % retcode)
Example #5
Source File: arm_now.py From arm_now with MIT License | 6 votes |
def check_dependencies_or_exit(): dependencies = [ which("e2cp", ubuntu="apt-get install e2tools", arch="yaourt -S e2tools", darwin="brew install e2tools gettext e2fsprogs\nbrew unlink e2fsprogs && brew link e2fsprogs -f"), which("qemu-system-arm", ubuntu="apt-get install qemu", kali="apt-get install qemu-system", arch="pacman -S qemu-arch-extra", darwin="brew install qemu"), which("unzip", ubuntu="apt-get install unzip", arch="pacman -S unzip", darwin="brew install unzip") ] if not all(dependencies): print("requirements missing, plz install them", file=sys.stderr) sys.exit(1)
Example #6
Source File: versioneer.py From aospy with Apache License 2.0 | 6 votes |
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None): """Call the given command(s).""" assert isinstance(commands, list) p = None for c in commands: try: dispcmd = str([c] + args) # remember shell=False, so use git.cmd on windows, not just git p = subprocess.Popen([c] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr else None)) break except EnvironmentError: e = sys.exc_info()[1] if e.errno == errno.ENOENT: continue if verbose: print("unable to run %s" % dispcmd) print(e) return None, None else: if verbose: print("unable to find command, tried %s" % (commands,)) return None, None stdout = p.communicate()[0].strip() if sys.version_info[0] >= 3: stdout = stdout.decode() if p.returncode != 0: if verbose: print("unable to run %s (error)" % dispcmd) print("stdout was %s" % stdout) return None, p.returncode return stdout, p.returncode
Example #7
Source File: _cplogging.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, appid=None, logger_root='cherrypy'): self.logger_root = logger_root self.appid = appid if appid is None: self.error_log = logging.getLogger('%s.error' % logger_root) self.access_log = logging.getLogger('%s.access' % logger_root) else: self.error_log = logging.getLogger( '%s.error.%s' % (logger_root, appid)) self.access_log = logging.getLogger( '%s.access.%s' % (logger_root, appid)) self.error_log.setLevel(logging.INFO) self.access_log.setLevel(logging.INFO) # Silence the no-handlers "warning" (stderr write!) in stdlib logging self.error_log.addHandler(NullHandler()) self.access_log.addHandler(NullHandler()) cherrypy.engine.subscribe('graceful', self.reopen_files)
Example #8
Source File: output_mod.py From Turku-neural-parser-pipeline with Apache License 2.0 | 6 votes |
def launch(args,q_in,q_out): start=time.time() total_parsed_trees=0 total_parsed_tokens=0 next_report=start+10.0 #report every 10sec at most while True: jobid,txt=q_in.get() if jobid=="FINAL": print("Output exiting",file=sys.stderr,flush=True) return total_parsed_trees+=sum(1 for line in txt.split("\n") if line.startswith("1\t")) total_parsed_tokens+=sum(1 for line in txt.split("\n") if re.match(token_regex, line)) if total_parsed_trees>0 and time.time()>next_report: time_spent=time.time()-start print("Runtime: {}:{} [m:s] Parsed: {} [trees], {} [tokens] Speed: {} [trees/sec] {} [sec/tree] {} [tokens/sec]".format(int(time_spent)//60,int(time_spent)%60,total_parsed_trees,total_parsed_tokens, total_parsed_trees/time_spent,time_spent/total_parsed_trees, total_parsed_tokens/time_spent) ,file=sys.stderr,flush=True) next_report=time.time()+10 print(txt,end="",flush=True)
Example #9
Source File: loggingwrapper.py From CAMISIM with Apache License 2.0 | 6 votes |
def add_log_stream(self, stream=sys.stderr, level=logging.INFO): """ Add a stream where messages are outputted to. @param stream: stderr/stdout or a file stream @type stream: file | FileIO | StringIO @param level: minimum level of messages to be logged @type level: int | long @return: None @rtype: None """ assert self.is_stream(stream) # assert isinstance(stream, (file, io.FileIO)) assert level in self._levelNames err_handler = logging.StreamHandler(stream) err_handler.setFormatter(self.message_formatter) err_handler.setLevel(level) self._logger.addHandler(err_handler)
Example #10
Source File: taxonomynode.py From CAMISIM with Apache License 2.0 | 6 votes |
def active_parent_nodes_consistency(oCurrNode): """ active_parent_nodes_consistency(oCurrNode) oCurrNode ... class Node ------------------------------------------------------------------------ Checks, if the parent node of an ncbi taxonomy node has at least one active child node. Every parent node of the ncbi taxonomy node that has no active child nodes will be inactivated. Returns the last node that has a parent with at least one active child. """ try: bCheckActiveChildNodes = False oChildrenNodes = oCurrNode.parent.children for oChildNode in oChildrenNodes: bCheckActiveChildNodes = bCheckActiveChildNodes or oChildNode.node_active if not bCheckActiveChildNodes: oCurrNode.parent.node_active = False oCurrNode = TaxonomyNode.active_parent_nodes_consistency(oCurrNode.parent) except Exception as e: print >> sys.stderr, str(e) # logging.error(str(e)) return oCurrNode
Example #11
Source File: test_basic.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #12
Source File: test_coop.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #13
Source File: test_hiv.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #14
Source File: test_fmarket.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #15
Source File: test_party.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #16
Source File: test_wolfsheep.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #17
Source File: test_grid.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #18
Source File: test_gridang.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #19
Source File: test_fashion.py From indras_net with GNU General Public License v3.0 | 5 votes |
def announce(name): present = date.today() print("Running " + name + " at " + str(present), file=sys.stderr) # make sure to run test file from root directory!
Example #20
Source File: test_models.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_models(self): for name, env in self.models.items(): print("Testing " + name + "...", file=sys.stderr) self.assertTrue(env.runN(2) > 0)
Example #21
Source File: export.py From svviz with MIT License | 5 votes |
def checkWebkitToPDF(): try: subprocess.check_call("webkitToPDF", stderr=subprocess.PIPE, shell=True) return True except subprocess.CalledProcessError: return False
Example #22
Source File: export.py From svviz with MIT License | 5 votes |
def _convertSVG_webkitToPDF(inpath, outpath, outformat): if outformat.lower() != "pdf": return None try: cmd = "webkitToPDF {} {}".format(inpath, outpath) subprocess.check_call(cmd, shell=True)#, stderr=subprocess.PIPE) except subprocess.CalledProcessError: return None return open(outpath, "rb").read()
Example #23
Source File: export.py From svviz with MIT License | 5 votes |
def _convertSVG_rsvg_convert(inpath, outpath, outformat): options = "" outformat = outformat.lower() if outformat == "png": options = "-a --background-color white" try: subprocess.check_call("rsvg-convert -f {} {} -o {} {}".format(outformat, options, outpath, inpath), shell=True) except subprocess.CalledProcessError as e: print("EXPORT ERROR:", str(e)) return open(outpath, "rb").read() # def test(): # base = """ <svg><rect x="10" y="10" height="100" width="100" style="stroke:#ffff00; stroke-width:3; fill: #0000ff"/><text x="25" y="25" fill="blue">{}</text></svg>""" # svgs = [base.format("track {}".format(i)) for i in range(5)] # tc = TrackCompositor(200, 600) # for i, svg in enumerate(svgs): # tc.addTrack(svg, i, viewbox="0 0 110 110") # outf = open("temp.svg", "w") # outf.write(tc.render()) # outf.flush() # outf.close() # pdfPath = convertSVGToPDF("temp.svg") # subprocess.check_call("open {}".format(pdfPath), shell=True) # if __name__ == '__main__': # test() # import sys # print(canConvertSVGToPDF(), file=sys.stderr)
Example #24
Source File: multiprocessor.py From svviz with MIT License | 5 votes |
def finish(self): text = [" "] if len(self.name) > 0: text.append(self.name) text.append("[completed] time elapsed: {}".format(formatTime(time.time()-self.t0))) text = " ".join(text) text = text.ljust(self.term_width) sys.stderr.write(text+"\n")
Example #25
Source File: multiprocessor.py From svviz with MIT License | 5 votes |
def redraw(self): if self.isatty or (time.time()-self.lastRedraw) > 30: overallTotal = sum(x[1] for x in list(self.barsToProgress.values())) overallCompleted = sum(x[0] for x in list(self.barsToProgress.values())) numBars = len(self.barsToProgress)+1 barWidth = (self.term_width-40-len(self.name)) // numBars - 1 if self.status == "+": self.status = " " else: self.status = "+" text = [" ", self.status] if len(self.name) > 0: text.append(self.name) text.append(self._getBar("total", overallCompleted, overallTotal, 25)) text.append("left:%s"%self.timeRemaining) if barWidth >= 6: for barid in sorted(self.barsToProgress): text.append(self._getBar(barid, self.barsToProgress[barid][0], self.barsToProgress[barid][1], barWidth)) else: text.append("[processes=%d]"%len(self.barsToProgress)) endmarker = "\n" if self.isatty: endmarker = "\r" sys.stderr.write(" ".join(text)+endmarker) self.lastRedraw = time.time()
Example #26
Source File: error_output_stream.py From clikit with MIT License | 5 votes |
def __init__(self): # type: () -> None super(ErrorOutputStream, self).__init__(sys.stderr)
Example #27
Source File: display.py From vergeml with MIT License | 5 votes |
def __init__(self, highlight_color=36, table_style='default', progress_style='default', is_interactive=True, stdout=sys.stdout, stderr=sys.stderr): self.stdout = stdout self.stderr = stderr self.highlight_color = highlight_color self.table_style = table_style self.progress_style = progress_style self.is_interactive = is_interactive self.cursor_hidden = False self.quiet = False
Example #28
Source File: ls.py From vergeml with MIT License | 5 votes |
def __call__(self, args, env): # Parse and partition into normal and comparison args. args, cargs = _parse_args(args, env) # When trainings dir does not exist, print an error and exit if not os.path.exists(env.get('trainings-dir')): print("No trainings found.", file=sys.stderr) return info, hyper = _find_trained_models(args, env) theader, tdata, left_align = _format_table(args, cargs, info, hyper) _output_table(args['output'], theader, tdata, left_align)
Example #29
Source File: ls.py From vergeml with MIT License | 5 votes |
def _output_table(output, theader, tdata, left_align): if not tdata: print("No matching trained models found.", file=sys.stderr) if output == 'table': if not tdata: return tdata.insert(0, theader) print(DISPLAY.table(tdata, left_align=left_align).getvalue(fit=True)) elif output == 'json': res = [] for row in tdata: res.append(dict(zip(theader, row))) print(json.dumps(res)) elif output == 'csv': buffer = io.StringIO() writer = csv.writer(buffer) writer.writerow(theader) for row in tdata: writer.writerow(row) val = buffer.getvalue() val = val.replace('\r', '') print(val.strip())
Example #30
Source File: libraries.py From vergeml with MIT License | 5 votes |
def version(): stderr = sys.stderr sys.stderr = open(os.devnull, 'w') import keras # pylint: disable=E0401 sys.stderr = stderr return keras.__version__