def check(self): fn = dtu.expand_all(self.filename) if not os.path.exists(fn): msg = 'Dir does not exist: %s' % fn raise CheckFailed(msg) if not os.path.isdir(fn): msg = 'Expect this to be a directory: %s' % fn raise CheckFailed(msg)
def check(self): try: contents = get_scuderia_contents() except ScuderiaException as e: msg = 'Invalid scuderia file.' l = str(e) raise CheckFailed(msg, l) if not contents: msg = 'Empty scuderia file.' l = 'The file %s is empty.' raise CheckFailed(msg, l)
def check(self): fn = expand_all(self.filename) short = os.path.basename(self.filename) if not os.path.exists(fn): msg = 'Path does not exist: %s' % short l = 'Complete path:\n %s' % fn raise CheckFailed(msg, l) if os.path.isdir(fn): msg = 'Expect this to be a file, not a directory: %s' % short l = 'Complete path:\n %s' % fn raise CheckFailed(msg)
def check(self): hostname = socket.gethostname() initial = 'duckiebot-not-configured' if hostname == initial: msg = 'The hostname is not configured; it is still %r.' % initial raise CheckFailed(msg) fn = '/etc/hostname' contents = open(fn).read().strip() if contents != hostname: msg = 'The hostname is %r but it does not match %s.' % (hostname, fn) l = 'Entire contents of %s:\n' % fn + indent(contents, ' > ') raise CheckFailed(msg, l)
def check(self): initial = 'duckiebot-not-configured' cmd = 'iwconfig' try: res = system_cmd_result(None, cmd, display_stdout=False, display_stderr=False, raise_on_error=True, capture_keyboard_interrupt=False, env=None) except CmdException as e: msg = 'The command failed\n' msg += '\n' + 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' + indent( res.stdout, ' > ') raise CheckFailed(msg, l)
def check(self): for package in self.packages: try: __import__(package, fromlist=['dummy']) except ImportError as e: msg = 'Cannot import package %r: %s\n' % (package, e) raise CheckFailed(msg)
def check(self): cmd = ['ssh', '-T', '*****@*****.**'] res = 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)
def check(self): expect = '4.4.38-v7+' cmd = ['uname', '-r'] try: res = system_cmd_result(None, cmd, display_stdout=False, display_stderr=False, raise_on_error=True, capture_keyboard_interrupt=False, env=None) except CmdException as e: msg = 'The command failed\n' msg += '\n' + 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): try: urllib.urlopen(self.url) # print "Connected" except IOError as e: msg = 'Cannot connect to %s' % self.url l = str(e) raise CheckFailed(msg, l)
def check(self): try: path = get_machines_files_path() except DTConfigException as e: msg = 'Could not get path to machines.' raise_wrapped(CheckError, e, msg) if not os.path.exists(path): msg = 'Machines file does not exist.' l = 'File does not exist: %s ' % path raise CheckFailed(msg, l) hostname = socket.gethostname() contents = open(path).read() if not '"%s"' % hostname in contents: msg = 'This robot, "%s" is not mentioned in the machines file.' % hostname raise CheckFailed(msg)
def check(self): d = dtu.expand_all(self.dirname) if not os.path.exists(d): msg = 'The repo does not exist' l = 'The repo does not exist in directory:\n %s' % d raise CheckFailed(msg, l) cwd = '.' cmd = ['git', '-C', d, 'remote', 'get-url', 'origin'] fail_if_stdout_contains(cwd, cmd, 'https')
def check(self): fn = dtu.expand_all(self.filename) short = os.path.basename(self.filename) if not os.path.exists(fn): msg = 'Path does not exist: %s' % short l = 'Complete path:\n %s' % fn raise CheckFailed(msg, l) if os.path.isdir(fn): msg = 'Expect this to be a file, not a directory: %s' % short l = 'Complete path:\n %s' % fn raise CheckFailed(msg) data = open(fn).read() lines = data.split('\n') maxlen = max(map(len, lines)) if len(lines) < 100 and maxlen < 80: return data
def check(self): if self.name not in os.environ: msg = 'Could not find environment variable %r.' % self.name raise CheckError(msg) value = os.environ[self.name] if value != self.expected: msg = 'Value of $%s is %r instead of %r.' % (self.name, value, self.expected) raise CheckFailed(msg)
def check(self): d = dtu.expand_all(self.dirname) assert_is_git_repository(d, CheckError) # error = abort age = get_repo_age(d) max_age = self.max_age_hours * 60 * 60 if age > max_age: d1 = duration_compact(age) d2 = duration_compact(max_age) msg = "The repository has not been pulled for %s (maximum tolerated %s). " % ( d1, d2) raise CheckFailed(msg)
def check(self): try: path = get_machines_files_path() except DTConfigException as e: msg = 'Could not get path to machines.' raise_wrapped(CheckError, e, msg) if not os.path.exists(path): msg = 'Machines file does not exist.' l = 'File does not exist: %s ' % path raise CheckFailed(msg, l)
def check(self): configured_groups = get_groups_in_etc(self.username) active_groups = get_active_groups(self.username) if not self.group in configured_groups: msg = 'You are currently not a member of the group %r' % self.group l = """ You can correct this by adding yourself to the group, with the command: $ sudo adduser %s %s """ % (self.username, self.group) raise CheckFailed(msg, l) if not self.group in active_groups: msg = 'The user %r was added to group %r, but the change is not effective yet.' % ( self.username, self.group) l = 'While you have added yourself to the group %r using `adduser`,\n' % self.group l += 'the change will not take effect until you close all terminals.\n' l += 'You can verify whether the change is effective by using the command:\n\n' l += ' $ groups %s' % self.username raise CheckFailed(msg, l)
def check(self): # read hosts file fn = '/etc/hosts' contents = open(fn).read() l = 'Entire contents of %s:\n' % fn + indent(contents, ' > ') if '10.' in contents or '192.' in contents: msg = 'The %s file contains hard-wired IPs.' % fn raise CheckFailed(msg, l) if '.local' in contents: msg = 'The %s file contains hard-wired host names.' % fn raise CheckFailed(msg, l) hostname = socket.gethostname() if not hostname in contents: msg = 'The %s file does not contain an entry for your hostname %r.' % ( fn, hostname) raise CheckFailed(msg, l)
def check(self): try: contents = get_scuderia_contents() except ScuderiaException as e: msg = 'Invalid scuderia file.' l = str(e) raise CheckError(msg, l) robot_name = socket.gethostname() if not robot_name in contents: msg = 'There is no entry "%s" in the scuderia file.' % robot_name raise CheckFailed(msg)
def check_no_tabs(filename): # Things to check: # there is an "encoding" file line, and the encoding is utf-8 contents = open(filename).read() if '\t' in contents: n = 0 for c in contents: if c == '\t': n += 1 msg = 'The file contains %d tab characters. The tab characters are evil!' % n raise CheckFailed(msg)
def check(self): try: from duckietown_msgs.msg import ( AntiInstagramTransform, BoolStamped, Segment, # @UnusedImport SegmentList, Vector2D) # @UnusedImport except ImportError as e: msg = str(e) msg += '\n\n This can usually be fixed by building everything ("make build").' msg += '\nOr in extreme cases, "make catkin-clean build".' raise CheckFailed(msg)
def check(self): fn = expand_all(self.filename) if not os.path.exists(fn): msg = 'File does not exist: %s' % fn raise CheckError(msg) contents = open(fn).read() l = 'Entire contents of %s:\n' % fn + indent(contents, ' > ') if not self.string in contents: msg = 'String %r not contained in %s' % (self.string, fn) raise CheckFailed(msg, l)
def check(self): out = "" for package in self.packages: try: p = __import__(package, fromlist=['dummy']) out += '%s: %s\n' % (package, package_info(p)) except ImportError as e: msg = 'Cannot import package %r: %s\n' % (package, e) raise CheckFailed(msg) return out
def check(self): cmd = ['git', 'lfs'] res = 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.' raise CheckFailed(msg)
def check(self): fn = expand_all(self.filename) if not os.path.exists(fn): msg = 'Cannot check permissions if file or dir does not exist.' raise CheckError(msg) fstats = os.stat(fn) filemode = oct(stat.S_IMODE(fstats.st_mode)) if len(filemode) > 4: filemode = filemode[-4:] if filemode != self.expected: msg = ('Expected mode %r, obtained %r.' % (self.expected, filemode)) raise CheckFailed(msg)
def check(self): # find a try: python_files = locate_files(self.dirname, '*.py') for filename in python_files: try: check_no_half_merges(filename) if DuckietownConstants.enforce_no_tabs: check_no_tabs(filename) if DuckietownConstants.enforce_naming_conventions: check_good_name(filename) except CheckFailed as e: msg = 'Check failed for file %s:' % filename raise_wrapped(CheckFailed, e, msg, compact=True) except CheckFailed as e: msg = 'Checks failed for package %s.' % self.package_name l = str(e) raise CheckFailed(msg, l)
def fail_if_stdout_contains(cwd, cmd, substring): try: res = system_cmd_result(cwd, cmd, display_stdout=False, display_stderr=False, raise_on_error=True, capture_keyboard_interrupt=False, env=None) except CmdException as e: msg = 'The command failed\n' msg += '\n' + 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' + indent( res.stdout.strip(), ' > ') raise CheckFailed(compact, long_explanation)
def fail_if_stdout_does_not_contain(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 not substring in res.stdout: compact = ('Could not find string "%s" in output of %s.' % (substring, cmd)) long_explanation = 'Complete output is:\n\n' + dtu.indent( res.stdout, ' > ') raise CheckFailed(compact, long_explanation)
def check(self): try: path_machines = get_machines_files_path() path_scuderia = get_scuderia_path() except DTConfigException as e: msg = 'Could not get path to machines.' raise_wrapped(CheckError, e, msg) if not os.path.exists(path_machines): msg = 'Machines file does not exist.' raise CheckError(msg) if not os.path.exists(path_scuderia): msg = 'Scuderia file does not exist.' raise CheckError(msg) f1 = os.path.getmtime(path_machines) f2 = os.path.getmtime(path_scuderia) if f2 > f1: msg = 'The machines file is older than the scuderia file.' raise CheckFailed(msg)
def check(self): username = getpass.getuser() if username == self.username: msg = 'You are logged in as user %s' % username raise CheckFailed(msg)
def check(self): msg = 'Always fails' l = "(long error)" if self.has_long_error else None raise CheckFailed(msg, l)