def test_cli2(): cmd = ['rosrun', 'easy_algo', 'summary', 'robot'] dtu.system_cmd_result(_cwd(), cmd, display_stdout=True, display_stderr=True, raise_on_error=True)
def run1(): cmd = ['rosrun', 'duckieteam', 'create-machines', '--print'] cwd = '.' system_cmd_result(cwd,cmd, display_stdout=False, display_stderr=False, raise_on_error=True)
def run(): cmd = ['rosrun', 'duckieteam', 'create-roster'] cwd = '.' system_cmd_result(cwd,cmd, display_stdout=False, display_stderr=False, raise_on_error=True)
def run2(): tmpfile = '/tmp/tmp' cmd = ['rosrun', 'duckieteam', 'create-roster', '--roster', tmpfile] cwd = '.' system_cmd_result(cwd,cmd, display_stdout=False, display_stderr=False, raise_on_error=True)
def run_one(cmd): v = False cwd = dtu.get_output_dir_for_test() if not os.path.exists(cwd): dtu.mkdirs_thread_safe(cwd) dtu.write_data_to_file('config echo 1', os.path.join(cwd, '.compmake.rc')) try: dtu.system_cmd_result(cwd, cmd, display_stdout=v, display_stderr=v, raise_on_error=True) finally: pass
def get_image_for_person(pid, size): basename2filename = get_images() b = '%s.jpg' % pid if not b in basename2filename: b = nopic tmp = 'tmp.jpg' cwd = '.' cmd = ['convert', basename2filename[b], '-resize', str(size), tmp] system_cmd_result(cwd, cmd, display_stdout=False, display_stderr=False, raise_on_error=True) jpg = open(tmp).read() return jpg
def check(self): expect = '4.4.38-v7+' cmd = ['uname', '-r'] try: res = dtu.system_cmd_result('.', cmd, display_stdout=False, display_stderr=False, raise_on_error=True, capture_keyboard_interrupt=False, env=None) except dtu.CmdException as e: msg = 'The command failed\n' msg += '\n' + dtu.indent(e, ' >') raise CheckError(msg) found = res.stdout.strip() if found != expect: msg = 'You are running kernel %r instead of %r.' % (found, expect) l = 'The kernel version is important because otherwise the Edimax\n' l += 'driver will not work correctly and needs to be recompiled.\n' l += '\n' l += 'Please report this error because we thought that the kernel\n' l += 'was prevented to update.' raise CheckFailed(msg, l)
def check(self): initial = 'duckiebot-not-configured' cmd = 'iwconfig' try: res = dtu.system_cmd_result('.', cmd, display_stdout=False, display_stderr=False, raise_on_error=True, capture_keyboard_interrupt=False, env=None) except dtu.CmdException as e: msg = 'The command failed\n' msg += '\n' + dtu.indent(e, ' >') raise CheckError(msg) if initial in res.stdout: msg = 'The robot is creating a network %r.' % initial l = 'According to iwconfig, you are creating a network %r.' % initial l += '\nThis means that you have failed to properly configure the robot.' l += '\nIt is likely the people around you are trying to connect to your robot.' l += '\n\nEntire output of iwconfig:\n\n' + dtu.indent( res.stdout, ' > ') raise CheckFailed(msg, l)
def git_cmd(cmd): cwd = dtu.get_duckietown_root() res = dtu.system_cmd_result(cwd, cmd, display_stdout=False, display_stderr=False, raise_on_error=True) return res.stdout.strip()
def get_hash_for_bytes(s): cmd = base + ['add'] cwd = '.' res = dtu.system_cmd_result(cwd, cmd, raise_on_error=True, write_stdin=s) hashed = res.stdout.split()[1] if not 'Qm' in hashed: msg = 'Invalid response, no Qm:\n%s' % indent(res.stdout, ' ') raise Exception(msg) return hashed
def run(which, expect): v = False cwd = dtu.get_output_dir_for_test() if not os.path.exists(cwd): dtu.mkdirs_thread_safe(cwd) try: cmd = ['rosrun', 'easy_regression', 'run', '--expect', expect, '--test', which, '-o', '.', '-c', 'rmake'] dtu.system_cmd_result(cwd, cmd, display_stdout=v, display_stderr=v, raise_on_error=True) finally: if False: shutil.rmtree(cwd)
def iids_tests(): out_base = 'anti_instagram_annotations_test' zipname = require_resource('ii-datasets.zip') dirname = os.path.dirname(zipname) base = os.path.join(dirname, 'ii-datasets') cmd = ['unzip', '-o', zipname] cwd = dirname system_cmd_result(cwd, cmd, display_stdout=False, display_stderr=False, raise_on_error=True) if not os.path.exists(base): msg = 'Could not find expected unzipped directory:\n %s' % base raise Exception(msg) anti_instagram_annotations_test(base, out_base)
def test_cli2(): cmd = ['rosrun', 'what_the_duck', 'what-the-duck'] res = dtu.system_cmd_result(_cwd(), cmd, display_stdout=True, display_stderr=True, raise_on_error=False) if False: if not (res.ret == 0): raise Exception(str(res)) else: warnings.warn('XXX temporary hack')
def detect_ipfs(): cmd = base + ['--version'] cwd = '.' try: _res = dtu.system_cmd_result(cwd, cmd, display_stdout=False, display_stderr=False, raise_on_error=True) except: return False return True
def get_active_groups(username): cmd = ['groups', username] try: res = dtu.system_cmd_result('.', cmd, display_stdout=False, display_stderr=False, raise_on_error=True, capture_keyboard_interrupt=False, env=None) except dtu.CmdException as e: raise CheckError(str(e)) active_groups = res.stdout.split() # XXX return active_groups
def get_ipfs_hash(self): dag = self.get_dag() dag_json = json.dumps(dag) cmd = base + ['object', 'put'] cwd = '.' res = dtu.system_cmd_result(cwd, cmd, raise_on_error=True, write_stdin=dag_json) hashed = res.stdout.split()[1] assert 'Qm' in hashed, hashed print('Directory of %d links: %s' % (len(self.links), hashed)) return hashed
def check(self): cmd = ['git', 'lfs'] res = dtu.system_cmd_result('.', cmd, display_stdout=False, display_stderr=False, raise_on_error=False, capture_keyboard_interrupt=True, # XXX? env=None) if res.ret != 0: msg = '`git lfs` returned non-zero.' msg += '\n' + dtu.indent(res, '> ') raise CheckFailed(msg)
def get_ipfs_hash(filename): # ipfs add --only-hash LICENSE # added QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC LICENSE dtu.logger.debug('Computing IPFS hash for %s' % filename) cmd = base + ['add', '--only-hash', filename] cwd = '.' res = dtu.system_cmd_result(cwd, cmd, display_stdout=False, display_stderr=False, raise_on_error=True) out = res.stdout.strip().split(' ') # print out if (len(out) < 3 or out[0] != 'added' or not out[1].startswith('Qm')): msg = 'Invalid output for ipds:\n%s' % dtu.indent(res.stdout, ' > ') raise Exception(msg) hashed = out[1] return hashed
def fail_if_stdout_contains(cwd, cmd, substring): try: res = dtu.system_cmd_result(cwd, cmd, display_stdout=False, display_stderr=False, raise_on_error=True, capture_keyboard_interrupt=False, env=None) except dtu.CmdException as e: msg = 'The command failed\n' msg += '\n' + dtu.indent(e, ' >') raise CheckError(msg) if substring in res.stdout: compact = ('I found the string "%s" in output of `%s`' % (substring, " ".join(cmd))) long_explanation = 'Complete output is:\n\n' + dtu.indent( res.stdout.strip(), ' > ') raise CheckFailed(compact, long_explanation)
def find_cmds_to_shortcut(): package2dir = dtu.get_list_of_packages_in_catkin_ws() for package, src in package2dir.items(): src = dtu.get_ros_package_path(package) cmd = ['find', src, '-type', 'f', '-executable'] res = dtu.system_cmd_result(cwd='.', cmd=cmd, display_stdout=False, display_stderr=False, raise_on_error=True) filenames = [x for x in res.stdout.strip().split('\n') if x] for fn in filenames: data = open(fn).read() if tag in data: b = os.path.basename(fn) desc = None yield Script(package=package, script=b, desc=desc, filename=fn) else: pass dtu.logger.debug('ignoring %s' % fn)
def is_package_installed(package_name): if '\n' in package_name or ' ' in package_name: raise ValueError(package_name) cmd = [ 'dpkg-query', '--show', "--showformat='${db:Status-Status}\n'", package_name ] res = dtu.system_cmd_result('.', cmd, display_stdout=False, display_stderr=False, raise_on_error=False, capture_keyboard_interrupt=False, env=None) is_installed = (res.ret == 0) and ('installed' in res.stdout) if is_installed: return True else: return False
def check(self): cmd = ['ssh', '-T', '*****@*****.**'] res = dtu.system_cmd_result('.', cmd, display_stdout=False, display_stderr=False, raise_on_error=False, capture_keyboard_interrupt=True, # XXX? env=None) expect = 'successfully authenticated' if res.ret == 1 and expect in res.stderr: # ok return if res.ret == 255 and 'denied' in res.stderr: msg = 'You do not have access to Github. ' l = summary_of_cmdres(res) raise CheckFailed(msg, l) msg = 'There is something wrong with contacting Github.' raise_CheckError_from_CommandResult(res, msg)