# Path: crmsh/utils.py
# def ext_cmd(cmd, shell=True):
#     cmd = add_sudo(cmd)
#     if options.regression_tests:
#         print(".EXT", cmd)
#     logger.debug("invoke: %s", cmd)
#     return subprocess.call(cmd, shell=shell)
# 
# def show_dot_graph(dotfile, keep_file=False, desc="transition graph"):
#     cmd = "%s %s" % (config.core.dotty, dotfile)
#     if not keep_file:
#         cmd = "(%s; rm -f %s)" % (cmd, dotfile)
#     if options.regression_tests:
#         print(".EXT", cmd)
#     subprocess.Popen(cmd, shell=True, bufsize=0,
#                      stdin=None, stdout=None, stderr=None, close_fds=True)
#     logger.info("starting %s to show %s", config.core.dotty, desc)
# 
# def page_string(s):
#     'Page string rendered for TERM.'
#     if not s:
#         return
#     constants.need_reset = True
#     w, h = get_winsize()
#     if not need_pager(s, w, h):
#         print(term_render(s))
#     elif not config.core.pager or not can_ask() or options.batch:
#         print(term_render(s))
#     else:
#         pipe_string(get_pager_cmd(), term_render(s).encode('utf-8'))
#     constants.need_reset = False


import os
from tempfile import mkstemp
from lxml import etree
from . import tmpfiles
from . import xmlutil
from . import utils
from . import config
from .utils import ext_cmd, show_dot_graph, page_string
from . import log
        else:
            dest_path = cib_path(self.origin)
        if cib != self.cib:
            status = cib.find("status")
            xmlutil.rmnode(status)
            cib.append(self.status_node)
        xml = etree.tostring(cib)
        try:
            f = open(dest_path, "w")
        except IOError as msg:
            logger.error(msg)
            return False
        f.write(xml)
        f.close()
        return True

    def _crm_simulate(self, cmd, nograph, scores, utilization, verbosity):
        if not self.origin:
            self.initialize()
        if verbosity:
            cmd = "%s -%s" % (cmd, verbosity.upper())
        if scores:
            cmd = "%s -s" % cmd
        if utilization:
            cmd = "%s -U" % cmd
        if config.core.dotty and not nograph:
            fd, dotfile = mkstemp()
            cmd = "%s -D %s" % (cmd, dotfile)
        else:
            dotfile = None

# Path: crmsh/utils.py
# def ext_cmd(cmd, shell=True):
#     cmd = add_sudo(cmd)
#     if options.regression_tests:
#         print(".EXT", cmd)
#     logger.debug("invoke: %s", cmd)
#     return subprocess.call(cmd, shell=shell)
# 
# def show_dot_graph(dotfile, keep_file=False, desc="transition graph"):
#     cmd = "%s %s" % (config.core.dotty, dotfile)
#     if not keep_file:
#         cmd = "(%s; rm -f %s)" % (cmd, dotfile)
#     if options.regression_tests:
#         print(".EXT", cmd)
#     subprocess.Popen(cmd, shell=True, bufsize=0,
#                      stdin=None, stdout=None, stderr=None, close_fds=True)
#     logger.info("starting %s to show %s", config.core.dotty, desc)
# 
# def page_string(s):
#     'Page string rendered for TERM.'
#     if not s:
#         return
#     constants.need_reset = True
#     w, h = get_winsize()
#     if not need_pager(s, w, h):
#         print(term_render(s))
#     elif not config.core.pager or not can_ask() or options.batch:
#         print(term_render(s))
#     else:
#         pipe_string(get_pager_cmd(), term_render(s).encode('utf-8'))
#     constants.need_reset = False


# Path: crmsh/cibstatus.py
import os
from tempfile import mkstemp
from lxml import etree
from . import tmpfiles
from . import xmlutil
from . import utils
from . import config
from .utils import ext_cmd, show_dot_graph, page_string
from . import log

        else:
            dest_path = cib_path(self.origin)
        if cib != self.cib:
            status = cib.find("status")
            xmlutil.rmnode(status)
            cib.append(self.status_node)
        xml = etree.tostring(cib)
        try:
            f = open(dest_path, "w")
        except IOError as msg:
            logger.error(msg)
            return False
        f.write(xml)
        f.close()
        return True

    def _crm_simulate(self, cmd, nograph, scores, utilization, verbosity):
        if not self.origin:
            self.initialize()
        if verbosity:
            cmd = "%s -%s" % (cmd, verbosity.upper())
        if scores:
            cmd = "%s -s" % cmd
        if utilization:
            cmd = "%s -U" % cmd
        if config.core.dotty and not nograph:
            fd, dotfile = mkstemp()
            cmd = "%s -D %s" % (cmd, dotfile)
        else:
            dotfile = None

        rc = ext_cmd(cmd % self.source_file())