def go(self): db = get_easy_algo_db() extra = self.options.get_extra() if len(extra) > 1: msg = 'Only one extra param accepted.' raise DTUserError(msg) if len(extra) == 1: query = extra[0] else: query = 'all' persons = db.query_and_instance('person', query) if self.options.roster: out_file = expand_all(self.options.roster) outd = os.path.dirname(out_file) roster = create_roster(persons, outd) write_data_to_file(roster, out_file) else: # instance ll tags = set() for p in persons.values(): tags.update(p.get_tags()) print(list(persons)) print('tags: %s' % list(tags)) table = table_people(persons) print(table)
def check(self): d = 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): d = 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 _get_dir(variable_name): if not variable_name in os.environ: msg = 'Environment variable %r not defined.' % variable_name raise DTConfigException(msg) fn = expand_all(os.environ[variable_name]) if not os.path.exists(fn): msg = 'Could not get %s: dir does not exist: %s' % (variable_name, fn) raise DTConfigException(msg) return fn
def assert_is_git_repository(dirname, ExceptionName): """ Returns True if the directory exists and is a git repository. """ assert ExceptionName in [CheckError, CheckFailed] d = expand_all(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 ExceptionName(msg, l) gitd = os.path.join(d, '.git') if not os.path.exists(gitd): msg = 'The directory does not appear to be a Git repository.' l = 'The path %r does not exist' % gitd raise ExceptionName(msg)
def anti_instagram_annotations_test(dirname, out_base): base = expand_all(dirname) if not os.path.exists(base): msg = 'Could not find directory %s' % base raise Exception(msg) dirs = locate_files(base, '*.iids1', alsodirs=True) directory_results = {} overall_results = [] if not dirs: raise ValueError('No IIDS1 directories found') for d in dirs: out = os.path.join(out_base, os.path.basename(d) + '.v') if not os.path.exists(out): os.makedirs(out) results = examine_dataset(d, out) overall_results = merge_comparison_results(results, overall_results) directory_results[d] = results db = shelve.open('tests_results', flag='n') db['directory_results'] = directory_results db['overall_results'] = overall_results db.close() logger.info( "overall average error: %f" % (overall_results['total_error'] / overall_results['total_pixels'])) logger.info("overall regions checked: %f" % (overall_results['total_regions'])) for t in overall_results['v_vals'].keys(): logger.info("region %f: RGB %f,%f,%f, HSV %f,%f,%f" % (t, np.mean(overall_results['r_vals'][t]), np.mean(overall_results['g_vals'][t]), np.mean(overall_results['b_vals'][t]), np.mean(overall_results['h_vals'][t]), np.mean(overall_results['s_vals'][t]), np.mean(overall_results['v_vals'][t])))
def examine_dataset(dirname, out): logger.info(dirname) dirname = expand_all(dirname) jpgs = locate_files(dirname, '*.jpg') mats = locate_files(dirname, '*.mat') logger.debug('I found %d JPGs and %d .mat.' % (len(jpgs), len(mats))) if len(jpgs) == 0: msg = 'Not JPGs found in %r.' % dirname raise ValueError(msg) # if len(mats) == 0: # msg = 'Not enough mats.' # raise ValueError(msg) first_jpg = sorted(jpgs)[0] logger.debug('Using jpg %r to learn transformation.' % first_jpg) first_jpg_image = image_cv_from_jpg_fn(first_jpg) success, health, parameters = calculate_transform(first_jpg_image) s = "" s += 'success: %s\n' % str(success) s += 'health: %s\n' % str(health) s += 'parameters: %s\n' % str(parameters) w = os.path.join(out, 'learned_transform.txt') with open(w, 'w') as f: f.write(s) logger.info(s) transform = ScaleAndShift(**parameters) duckietown_package_dir = get_ros_package_path('duckietown') config_dir = os.path.join( duckietown_package_dir, 'config/baseline/line_detector/line_detector_node') if not os.path.exists(config_dir): msg = 'Could not find configuration dir %s' % config_dir raise Exception(msg) config_dir = expand_all(config_dir) configurations = locate_files(config_dir, '*.yaml') if not configurations: msg = 'Could not find any configuration file in %s.' % config_dir raise Exception(msg) #logger.info('configurations: %r' % configurations) for j in jpgs: summaries = [] shape = (200, 160) interpolation = cv2.INTER_NEAREST bn = os.path.splitext(os.path.basename(j))[0] fn = os.path.join(out, '%s.all.png' % (bn)) if os.path.exists(fn): logger.debug('Skipping because file exists: %r' % fn) else: for c in configurations: logger.info('Trying %r' % c) name = os.path.splitext(os.path.basename(c))[0] if name in ['oreo', 'myrtle', 'bad_lighting', '226-night']: continue with open(c) as f: stuff = yaml.load(f) if not 'detector' in stuff: msg = 'Cannot find "detector" section in %r' % c raise ValueError(msg) detector = stuff['detector'] logger.info(detector) if not isinstance(detector, list) and len(detector) == 2: raise ValueError(detector) def LineDetectorClass(): return instantiate(detector[0], detector[1]) s = run_detection(transform, j, out, shape=shape, interpolation=interpolation, name=name, LineDetectorClass=LineDetectorClass) summaries.append(s) together = make_images_grid(summaries, cols=1, pad=10, bgcolor=[.5, .5, .5]) cv2.imwrite(fn, zoom_image(together, 4)) overall_results = [] comparison_results = {} for m in mats: logger.debug(m) jpg = os.path.splitext(m)[0] + '.jpg' if not os.path.exists(jpg): msg = 'JPG %r for mat %r does not exist' % (jpg, m) logger.error(msg) else: frame_results = test_pair(transform, jpg, m, out) comparison_results[m] = frame_results overall_results = merge_comparison_results(comparison_results[m], overall_results) print "comparison_results[m]=frame_results" print "finished mats: " + dirname return overall_results