Exemplo n.º 1
0
 def _worddiff(self, s1, s2):
     s = None
     f1 = utils.str2tmp(s1)
     f2 = utils.str2tmp(s2)
     if f1 and f2:
         rc, s = utils.get_stdout("wdiff %s %s" % (f1, f2))
     try:
         os.unlink(f1)
     except:
         pass
     try:
         os.unlink(f2)
     except:
         pass
     return s
Exemplo n.º 2
0
 def _worddiff(self, s1, s2):
     s = None
     f1 = utils.str2tmp(s1)
     f2 = utils.str2tmp(s2)
     if f1 and f2:
         rc, s = utils.get_stdout("wdiff %s %s" % (f1, f2))
     try:
         os.unlink(f1)
     except:
         pass
     try:
         os.unlink(f2)
     except:
         pass
     return s
Exemplo n.º 3
0
def cibdump2tmp():
    try:
        _, outp, _ = sudocall(cib_dump)
        if outp is not None:
            return str2tmp(outp)
    except IOError, msg:
        common_err(msg)
Exemplo n.º 4
0
def cibdump2tmp():
    try:
        _, outp, _ = sudocall(cib_dump)
        if outp is not None:
            return str2tmp(outp)
    except IOError, msg:
        common_err(msg)
Exemplo n.º 5
0
 def _unidiff(self, s1, s2, t1, t2):
     s = None
     f1 = utils.str2tmp(s1)
     f2 = utils.str2tmp(s2)
     if f1 and f2:
         rc, s = utils.get_stdout("diff -U 0 -d -b --label %s --label %s %s %s" %
                                  (t1, t2, f1, f2))
     try:
         os.unlink(f1)
     except:
         pass
     try:
         os.unlink(f2)
     except:
         pass
     return s
Exemplo n.º 6
0
 def _unidiff(self, s1, s2, t1, t2):
     s = None
     f1 = utils.str2tmp(s1)
     f2 = utils.str2tmp(s2)
     if f1 and f2:
         rc, s = utils.get_stdout(
             "diff -U 0 -d -b --label %s --label %s %s %s" %
             (t1, t2, f1, f2))
     try:
         os.unlink(f1)
     except:
         pass
     try:
         os.unlink(f2)
     except:
         pass
     return s
Exemplo n.º 7
0
 def do_dump(self, context, t, *args):
     '''dump configuration or status to a file and print file
     name.
     NB: The configuration is color rendered, but note that
     that depends on the current value of the TERM variable.
     '''
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     if "status" in opt_l:
         s = self._render_pe(self._pe_status_nohdr, t)
     else:
         s = utils.term_render(self._render_pe(self._pe_config_plain, t))
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if not s:
         return False
     print utils.str2tmp(s)
Exemplo n.º 8
0
 def do_dump(self, context, t, *args):
     '''dump configuration or status to a file and print file
     name.
     NB: The configuration is color rendered, but note that
     that depends on the current value of the TERM variable.
     '''
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     if "status" in opt_l:
         s = self._render_pe(self._pe_status_nohdr, t)
     else:
         s = utils.term_render(self._render_pe(self._pe_config_plain, t))
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if not s:
         return False
     print utils.str2tmp(s)
Exemplo n.º 9
0
def test_str2tmp():
    txt = "This is a test string"
    filename = utils.str2tmp(txt)
    assert os.path.isfile(filename)
    assert open(filename).read() == txt + "\n"
    assert utils.file2str(filename) == txt
    # TODO: should this really return
    # an empty line at the end?
    assert utils.file2list(filename) == [txt, '']
    os.unlink(filename)
Exemplo n.º 10
0
def cibdump2tmp():
    cmd = add_sudo(cib_dump)
    if options.regression_tests:
        print ".EXT", cmd
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    try:
        tmpf = str2tmp(''.join(p.stdout))
        p.wait()
    except IOError, msg:
        common_err(msg)
        return None
Exemplo n.º 11
0
def cibdump2tmp():
    cmd = add_sudo(cib_dump)
    if options.regression_tests:
        print ".EXT", cmd
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    try:
        tmpf = str2tmp(''.join(p.stdout))
        p.wait()
    except IOError, msg:
        common_err(msg)
        return None
Exemplo n.º 12
0
 def do_apply(self, context, *args):
     "usage: apply [<method>] [<config>]"
     method = "replace"
     name = ''
     if len(args) > 0:
         i = 0
         if args[0] in ("replace", "update"):
             method = args[0]
             i += 1
         if len(args) > i:
             name = args[i]
     if not name and not self.curr_conf:
         common_err("please load a config first")
         return False
     if name:
         if not self.config_exists(name):
             return False
         s = self.process(name)
     else:
         s = self.process()
     if not s:
         return False
     tmp = utils.str2tmp(s)
     if not tmp:
         return False
     if method == "replace":
         if options.interactive and cib_factory.has_cib_changed():
             if not utils.ask(
                     "This operation will erase all changes. Do you want to proceed?"
             ):
                 return False
         cib_factory.erase()
     set_obj = mkset_obj()
     rc = set_obj.import_file(method, tmp)
     try:
         os.unlink(tmp)
     except:
         pass
     return rc
Exemplo n.º 13
0
 def do_apply(self, context, *args):
     "usage: apply [<method>] [<config>]"
     method = "replace"
     name = ''
     if len(args) > 0:
         i = 0
         if args[0] in ("replace", "update"):
             method = args[0]
             i += 1
         if len(args) > i:
             name = args[i]
     if not name and not self.curr_conf:
         common_err("please load a config first")
         return False
     if name:
         if not self.config_exists(name):
             return False
         s = self.process(name)
     else:
         s = self.process()
     if not s:
         return False
     tmp = utils.str2tmp(s)
     if not tmp:
         return False
     if method == "replace":
         if options.interactive and cib_factory.has_cib_changed():
             if not utils.ask("This operation will erase all changes. Do you want to proceed?"):
                 return False
         cib_factory.erase()
     set_obj = mkset_obj()
     rc = set_obj.import_file(method, tmp)
     try:
         os.unlink(tmp)
     except:
         pass
     return rc
Exemplo n.º 14
0
Arquivo: crm_gv.py Projeto: lge/crmsh
 def totmpf(self):
     return utils.str2tmp('\n'.join(self.repr()))
Exemplo n.º 15
0
 def totmpf(self):
     return utils.str2tmp('\n'.join(self.repr()))