def perform_diff(): """Perform graphical diff.""" (modified, rightrev) = get_pred_revision_and_modified() ltf = None leftname = None if flag_prev_revision: rightrev = flag_prev_revision if flag_revision_pair: if modified: u.warning("warning: working copy of %s is " "modified" % flag_target_file) leftrev = flag_revision_pair[0] rightrev = flag_revision_pair[1] ltf = tempfile.NamedTemporaryFile(mode="w", prefix="svnpreddifftmp_REV%s_" % leftrev, delete=True) leftname = ltf.name u.verbose(1, "left temp file is: %s" % leftname) u.docmdout("svn cat -r%d %s" % (leftrev, flag_target_file), leftname) if flag_save_temps: save_temps(ltf, leftrev) else: u.verbose(1, "left file is: %s" % flag_target_file) leftname = flag_target_file rtf = tempfile.NamedTemporaryFile(mode="w", prefix="svnpreddifftmp_REV%s_" % rightrev, delete=True) rightname = rtf.name u.verbose(1, "right temp file is: %s" % rightname) u.docmdout("svn cat -r%d %s" % (rightrev, flag_target_file), rightname) if flag_save_temps: save_temps(rtf, rightrev) # Perform diff u.docmd("%s %s %s" % (flag_diff_cmd, leftname, rightname))
def docmdout(cmd, outfile): """Execute a command.""" if flag_echo: sys.stderr.write("executing: " + cmd + " > %s\n" % outfile) if flag_dryrun: return u.docmdout(cmd, outfile)
def docmdout(cmd, outfile): """Execute a command to an output file.""" if flag_echo: sys.stderr.write("executing: " + cmd + "\n") if flag_dryrun: return u.docmdout(cmd, outfile)
def test_docmdout_pass(self): outf = tempfile.NamedTemporaryFile(mode="w", delete=True) u.docmdout("uname", outf.name) verif = open(outf.name, "r") lines = verif.readlines() verif.close() self.assertTrue(lines[0].strip() == "Linux")
def process_volsnap(v): """Examine a given subvolume or snapshot.""" me = whoami sv = re.sub("/", "_", v) tf1 = "/tmp/ssnap-%s-%s-du.txt" % (me, sv) os.chdir(v) u.verbose(1, "collecting disk for %s into %s" % (v, tf1)) u.docmdout("du -sh", tf1) tf2 = None rp = os.path.join(v, ".repo") if os.path.exists(rp): tf2 = "/tmp/ssnap-%s-%s-rpstat.txt" % (me, sv) u.verbose(1, "collecting rpstat for %s into %s" % (v, tf2)) u.docmdout("repo status", tf2) return (tf1, tf2)
def docmdout(cmd, outfile, nf): """Execute a command redirecting output to a file.""" if flag_echo: sys.stderr.write("executing: " + cmd + " > " + outfile + "\n") if flag_dryrun: return return u.docmdout(cmd, outfile, nf)
def docmdout(cmd, outfile, nf=None): """Execute a command redirecting output to a file.""" if flag_dryrun or u.verbosity_level() > 0: sys.stderr.write("executing: " + cmd + " > " + outfile + "\n") if flag_dryrun: return return u.docmdout(cmd, outfile, nf)
def perform(): """Main driver routine.""" # Check for existence of ninja log file if not os.path.exists(".ninja_log"): u.error("unable to access .ninja_log file") # Generate json file from ninja log if flag_dryrun or flag_echo: u.verbose(0, "%s .ninja_log > trace.json" % flag_ninjatracing) if not flag_dryrun: u.docmdout("%s .ninja_log" % flag_ninjatracing, "trace.json") # Generate trace.html file from json cmd = ("%s/tracing/bin/trace2html trace.json " "--output=%s" % (flag_catapult, flag_outfile)) if flag_dryrun or flag_echo: u.verbose(0, cmd) if not flag_dryrun: u.docmd(cmd)
def summarize_dwarf(abuild): """Produce a report on dwarf producer.""" apo = os.environ["ANDROID_PRODUCT_OUT"] if not apo: u.error("internal error -- no ANDROID_PRODUCT_OUT env setting") symsdir = "%s/symbols" % apo if os.path.exists(symsdir): lines = u.docmdlines("find %s -type f -print" % symsdir) slines = [] for line in lines: slines.append(line.strip()) if slines: outfile = "llvm-dwflavor-report.%s.txt" % abuild cmd = "llvm-dwflavor %s" % " ".join(slines) if flag_dryrun: u.verbose(1, "cmd: %s > %s" % (cmd, outfile)) else: u.docmdout("llvm-dwflavor -show-comp-units " "%s" % " ".join(slines), outfile, True) else: u.verbose(1, "DWARF flavor report stubbed " "out -- %s doesn't exist" % symsdir)
def test_docmdout_nf(self): val = u.docmdout("/bin/false", "/dev/null", True) self.assertTrue(val == None)
def test_docmdout_fail(self): with self.assertRaises(Exception): outf = tempfile.NamedTemporaryFile(mode="w", delete=True) u.docmdout("date -XYZ", outf.name)