Python sys.stderr() Examples

The following are 30 code examples for showing how to use sys.stderr(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module sys , or try the search function .

Example 1
Project: mlbv   Author: kmac   File: util.py    License: GNU General Public License v3.0 7 votes vote down vote up
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 2
Project: Turku-neural-parser-pipeline   Author: TurkuNLP   File: train_models.py    License: Apache License 2.0 7 votes vote down vote up
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 3
Project: aegea   Author: kislyuk   File: test.py    License: Apache License 2.0 6 votes vote down vote up
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 4
Project: arm_now   Author: nongiach   File: arm_now.py    License: MIT License 6 votes vote down vote up
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 5
Project: wechat-alfred-workflow   Author: TKkk-iOSer   File: notify.py    License: MIT License 6 votes vote down vote up
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 6
Project: cherrypy   Author: cherrypy   File: _cplogging.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 7
Project: Turku-neural-parser-pipeline   Author: TurkuNLP   File: output_mod.py    License: Apache License 2.0 6 votes vote down vote up
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 8
Project: CAMISIM   Author: CAMI-challenge   File: loggingwrapper.py    License: Apache License 2.0 6 votes vote down vote up
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 9
Project: CAMISIM   Author: CAMI-challenge   File: taxonomynode.py    License: Apache License 2.0 6 votes vote down vote up
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 10
Project: indras_net   Author: gcallah   File: test_basic.py    License: GNU General Public License v3.0 5 votes vote down vote up
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 11
Project: indras_net   Author: gcallah   File: test_coop.py    License: GNU General Public License v3.0 5 votes vote down vote up
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
Project: indras_net   Author: gcallah   File: test_hiv.py    License: GNU General Public License v3.0 5 votes vote down vote up
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
Project: indras_net   Author: gcallah   File: test_fmarket.py    License: GNU General Public License v3.0 5 votes vote down vote up
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
Project: indras_net   Author: gcallah   File: test_party.py    License: GNU General Public License v3.0 5 votes vote down vote up
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
Project: indras_net   Author: gcallah   File: test_wolfsheep.py    License: GNU General Public License v3.0 5 votes vote down vote up
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
Project: indras_net   Author: gcallah   File: test_grid.py    License: GNU General Public License v3.0 5 votes vote down vote up
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
Project: indras_net   Author: gcallah   File: test_gridang.py    License: GNU General Public License v3.0 5 votes vote down vote up
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
Project: indras_net   Author: gcallah   File: test_fashion.py    License: GNU General Public License v3.0 5 votes vote down vote up
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
Project: indras_net   Author: gcallah   File: test_models.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_models(self):
        for name, env in self.models.items():
            print("Testing " + name + "...", file=sys.stderr)
            self.assertTrue(env.runN(2) > 0) 
Example 20
Project: svviz   Author: svviz   File: export.py    License: MIT License 5 votes vote down vote up
def checkWebkitToPDF():
    try:
        subprocess.check_call("webkitToPDF", stderr=subprocess.PIPE, shell=True)
        return True
    except subprocess.CalledProcessError:
        return False 
Example 21
Project: svviz   Author: svviz   File: export.py    License: MIT License 5 votes vote down vote up
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 22
Project: svviz   Author: svviz   File: export.py    License: MIT License 5 votes vote down vote up
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 23
Project: svviz   Author: svviz   File: multiprocessor.py    License: MIT License 5 votes vote down vote up
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 24
Project: svviz   Author: svviz   File: multiprocessor.py    License: MIT License 5 votes vote down vote up
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 25
Project: clikit   Author: sdispater   File: error_output_stream.py    License: MIT License 5 votes vote down vote up
def __init__(self):  # type: () -> None
        super(ErrorOutputStream, self).__init__(sys.stderr) 
Example 26
Project: vergeml   Author: mme   File: display.py    License: MIT License 5 votes vote down vote up
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 27
Project: vergeml   Author: mme   File: ls.py    License: MIT License 5 votes vote down vote up
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 28
Project: vergeml   Author: mme   File: ls.py    License: MIT License 5 votes vote down vote up
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 29
Project: vergeml   Author: mme   File: libraries.py    License: MIT License 5 votes vote down vote up
def version():
        stderr = sys.stderr
        sys.stderr = open(os.devnull, 'w')
        import keras # pylint: disable=E0401
        sys.stderr = stderr
        return keras.__version__ 
Example 30
Project: aegea   Author: kislyuk   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def main(args=None):
    parsed_args = parser.parse_args(args=args)
    logger.setLevel(parsed_args.log_level)
    has_attrs = (getattr(parsed_args, "sort_by", None) and getattr(parsed_args, "columns", None))
    if has_attrs and parsed_args.sort_by not in parsed_args.columns:
        parsed_args.columns.append(parsed_args.sort_by)
    try:
        result = parsed_args.entry_point(parsed_args)
    except Exception as e:
        if isinstance(e, NoRegionError):
            msg = "The AWS CLI is not configured."
            msg += " Please configure it using instructions at"
            msg += " http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html"
            exit(msg)
        elif logger.level < logging.ERROR:
            raise
        else:
            err_msg = traceback.format_exc()
            try:
                err_log_filename = os.path.join(config.user_config_dir, "error.log")
                with open(err_log_filename, "ab") as fh:
                    print(datetime.datetime.now().isoformat(), file=fh)
                    print(err_msg, file=fh)
                exit("{}: {}. See {} for error details.".format(e.__class__.__name__, e, err_log_filename))
            except Exception:
                print(err_msg, file=sys.stderr)
                exit(os.EX_SOFTWARE)
    if isinstance(result, SystemExit):
        raise result
    elif result is not None:
        if isinstance(result, dict) and "ResponseMetadata" in result:
            del result["ResponseMetadata"]
        print(json.dumps(result, indent=2, default=str))