def doscmd(cmd): """Execute a command.""" if flag_echo: sys.stderr.write("executing: " + cmd + "\n") if flag_dryrun: return u.doscmd(cmd)
def parse_args(): """Command line argument parsing.""" global whichdev try: optlist, args = getopt.getopt(sys.argv[1:], "d") except getopt.GetoptError as err: # unrecognized option usage(str(err)) for opt, _ in optlist: if opt == "-d": u.increment_verbosity() if args: usage("unrecognized arg") # Check to make sure we can run adb u.doscmd("which adb") # Collect device flavor lines = u.docmdlines("whichdevice.sh") if len(lines) != 1: u.error("unexpected output from whichdevice.sh") whichdev = lines[0].strip() u.verbose(1, "device: %s" % whichdev)
def doscmd(cmd, nf=None): """Execute a command.""" if flag_echo: sys.stderr.write("executing: " + cmd + "\n") if flag_dryrun: return u.doscmd(cmd, nf)
def doscmd(cmd): """Execute a command.""" if flag_echo: sys.stderr.write("executing: " + cmd + "\n") if flag_dryrun: return if flag_show_output: u.docmd(cmd) else: u.doscmd(cmd)
def collectem(): """Locate and upload tombstones.""" # Need root access to get at /data/tombstones u.doscmd("adb root") # See what's available lines = u.docmdlines("adb shell ls -l /data/tombstones") # Things we found fnames = [] # -rw------- system system 56656 2015-05-25 03:01 tombstone_09 matcher = re.compile(r"^\S+\s+\S+\s+\S+\s+\d+\s+(\S+)\s+(\S+)\s+(tomb\S+)\s*$") for line in lines: u.verbose(3, "line is: %s" % line) m = matcher.match(line) if m: datestr = m.group(1) timestr = m.group(2) fname = m.group(3) fnames.append(fname) u.verbose(1, ("found tombstone %s date %s time %s" % (fname, datestr, timestr))) u.docmd("mkdir -p /tmp/tombstones/%s" % whichdev) newname = ("/tmp/tombstones/%s/%s_%s_%s" % (whichdev, fname, datestr, timestr)) u.docmd("adb pull /data/tombstones/%s %s_tmp" % (fname, newname)) if os.path.exists(newname): # already there? rc = u.docmdnf("cmp -s %s %s_tmp" % (newname, newname)) if rc == 0: print "file %s already uploaded, skipping..." % fname else: print "overwriting existing %s with new version" % fname else: u.docmdnf("mv %s_tmp %s" % (newname, newname)) print "uploaded new tombstone to %s" % newname # Anything there? if not fnames: print "No tombstones found... terminating."
def run_cmake(builddir, cmake_cmd): """Cmake run helper.""" try: os.chdir(builddir) except OSError as err: u.warning("chdir failed: %s" % err) return 1 rv = u.doscmd(cmake_cmd, True) if not rv: u.warning("cmd command returned bad status: %s" % cmake_cmd) return 1 return 0
def examine(afile): """Dump go exports for specified file.""" objfile = afile arcmd = "ar t %s" % afile # Run 'ar' command, suppressing error output. If # if succeeds, then continue on the ar path, otherwise # treat input as an object. if u.doscmd(arcmd, True, True): # Handle archives lines = u.docmdlines(arcmd, True) if not lines: u.warning("skipping %s, can't index archive %s", afile) return # Extract elem from archive elem = lines[0].strip() u.verbose(1, "%s contains %s" % (afile, elem)) rc = u.docmdnf("ar x %s %s" % (afile, elem)) if rc: u.warning("skipping %s, can't extract object" % afile) return objfile = elem gexptemp = tempfile.NamedTemporaryFile(mode="w", prefix="go_export", delete=True) # Handle objects cmd = ("objcopy -O binary --only-section=.go_export " "--set-section-flags .go_export=alloc %s " "%s" % (objfile, gexptemp.name)) rc = u.docmdnf(cmd) if rc: u.warning("skipping %s, can't extract export " "data (cmd failed: %s)" % (objfile, cmd)) return try: inf = open(gexptemp.name, "rb") except IOError as e: u.error("unable to open tempfile %s: " "%s" % (gexptemp.name, e.strerror)) print "== %s ==" % afile lines = inf.readlines() if not lines: u.warning("skipping %s, no .go_export section present" % objfile) for line in lines: print line.strip() inf.close() if objfile != afile: os.unlink(objfile)
def setup(): """Perform assorted setups prior to main part of run.""" global abt, apo, whichdev, cpu_arch, dxpath # Check to make sure we can run adb, etc u.doscmd("which adb") rc = u.docmdnf("which dx") if rc != 0: u.doscmd("which prebuilts/sdk/tools/dx") dxpath = "prebuilts/sdk/tools/dx" u.doscmd("which javac") # Collect device flavor lines = u.docmdlines("whichdevice.sh") if len(lines) != 1: u.error("unexpected output from whichdevice.sh") whichdev = lines[0].strip() u.verbose(1, "device: %s" % whichdev) bitness = 32 cpu_tup_idx = 0 if flag_64bit: bitness = 64 cpu_tup_idx = 1 # Figure out what architecture we're working with, # and make sure it supports the requested mode (32 or 64 bit) output = u.docmdlines("adb shell uname -m") tag = output[0].strip() if tag not in uname_to_cpu_arch: u.error("internal error: unsupported output %s from " "from uname -m -- please update script" % tag) tup = uname_to_cpu_arch[tag] cpu_arch = tup[cpu_tup_idx] if not cpu_arch: u.error("%d-bit support not available on " "this arch (uname -m: %s)" % (bitness, tag)) # Did we run lunch? abt = os.getenv("ANDROID_BUILD_TOP") if abt is None: u.error("ANDROID_BUILD_TOP not set (did you run lunch?)") apo = os.getenv("ANDROID_PRODUCT_OUT") if apo is None: u.error("ANDROID_PRODUCT_OUT not set (did you run lunch?)") u.verbose(1, "ANDROID_PRODUCT_OUT: %s" % apo)
usage("specify at most one of -t, -a") parse_args() u.setdeflanglocale() if not flag_toplevel and not flag_dependencies: mkfile = os.path.join(flag_subdir, "Android.mk") if not os.path.exists(mkfile): u.error("can't access %s" % mkfile) os.environ["ONE_SHOT_MAKEFILE"] = mkfile if flag_dryrun: u.verbose(0, "setting os.environ[\"ONE_" "SHOT_MAKEFILE\"] to %s" % mkfile) if not flag_dryrun: rc = u.doscmd("which jack-admin", nf=True) if rc == 0: flag_use_jack = True u.doscmd("jack-admin start-server") here = os.getcwd() am = "all_modules" if flag_toplevel: am = "" if flag_extra_make_args: am = " %s" % " ".join(flag_extra_make_args) if flag_checkbuild: am += " checkbuild" elif flag_dependencies: am = "MODULES-IN-%s" % re.sub("/", "-", flag_subdir) cmd = ("%smake %s -j%d -C %s -f build/core/main.mk "
def parse_args(): """Command line argument parsing.""" global flag_showall try: optlist, _ = getopt.getopt(sys.argv[1:], "da") except getopt.GetoptError as err: # unrecognized option usage(str(err)) for opt, _ in optlist: if opt == "-d": u.increment_verbosity() elif opt == "-a": flag_showall = True # ---------main portion of script ------------- u.setdeflanglocale() parse_args() # Check to make sure we can run adb u.doscmd("which adb") # run perform() # done exit(0)
def test_doscmd_fail_with_rc(self): rc = u.doscmd("/bin/false", True) self.assertTrue(rc != 0)
def test_doscmd_fail(self): with self.assertRaises(Exception): u.doscmd("date -XYZ")
def test_doscmd_pass(self): u.doscmd("uname -a")