def upload_target(client, target_file, image_file, team_id=None, actionable_override=None): """Upload a single target to the server Args: client: interop.Client connected to the server target_file: Path to file containing target details in the Object File Format. image_file: Path to target thumbnail. May be None. team_id: The username of the team on whose behalf to submit targets. Defaults to None. actionable_override: Manually sets the target to be actionable. Defaults to None. """ with open(target_file) as f: target = Target.deserialize(json.load(f)) id = target.id target.team_id = team_id target.actionable_override = actionable_override logger.info('Uploading target %s: %r' % (target_file, target)) target = client.post_target(target) if image_file: logger.info('Uploading target thumbnail %s' % image_file) with open(image_file) as img: client.post_target_image(id, img.read()) else: logger.warning('No thumbnail for target %s' % target_file)
def upload_target(client, target_file, image_file, team_id=None, actionable_override=None): """Upload a single target to the server Args: client: interop.Client connected to the server target_file: Path to file containing target details in the Object File Format. image_file: Path to target thumbnail. May be None. team_id: The username of the team on whose behalf to submit targets. Defaults to None. actionable_override: Manually sets the target to be actionable. Defaults to None. """ with open(target_file) as f: target = Target.deserialize(json.load(f)) target.team_id = team_id target.actionable_override = actionable_override logger.info('Uploading target %s: %r' % (target_file, target)) target = client.post_target(target) if image_file: logger.info('Uploading target thumbnail %s' % image_file) with open(image_file) as img: client.post_target_image(target.id, img.read()) else: logger.warning('No thumbnail for target %s' % target_file)
def testTarget(client, mission): target_pos = mission.off_axis_target_pos target = Target(type='standard', latitude=38.145215, longitude=-76.427942, orientation='n', shape='square', background_color='green', alphanumeric='A', alphanumeric_color='white') target = client.post_target(target) print target
def upload_target(client, target_file, image_file): """Upload a single target to the server Args: client: interop.Client connected to the server target_file: Path to file containing target details in the Object File Format. image_file: Path to target thumbnail. May be None. """ with open(target_file) as f: target = Target.deserialize(json.load(f)) logger.info('Uploading target %s: %r' % (target_file, target)) target = client.post_target(target) if image_file: logger.info('Uploading target thumbnail %s' % image_file) with open(image_file) as img: client.post_target_image(target.id, img.read()) else: logger.warning('No thumbnail for target %s' % target_file)
def load_target_file(target_filepath): """Loads targets from the given file. Args: target_filepath: The path to the target file to load. Returns: A list of (target, image_filepath) tuples. Raises: ValueError if the file is not properly formatted. """ targets = [] with open(target_filepath, 'r') as f: reader = csv.reader(f, delimiter='\t') for row in reader: target_type = row[1] latitude_str = row[2] longitude_str = row[3] orientation = row[4].lower() shape = row[5] background_color = row[6] alphanumeric = row[7] alphanumeric_color = row[8] image_filepath = row[9] description = row[10] target = Target() if target_type not in TARGET_TYPE_MAP: raise ValueError('Type %s not in %s' % (target_type, str(TARGET_TYPE_MAP))) target.type = TARGET_TYPE_MAP[target_type] # Parse latitude. Not required for off axis. if target.type != 'off_axis': match = LATITUDE_REGEX.match(latitude_str) if match: latitude = LATITUDE_DIR[match.group('dir')] * ( float(match.group('deg')) + float(match.group('min')) / 60 + float(match.group('sec')) / 3600) target.latitude = latitude else: raise ValueError('Latitude is not valid: %s' % latitude_str) # Parse longitude. Not required for off axis. if target.type != 'off_axis': match = LONGITUDE_REGEX.match(longitude_str) if match: longitude = LONGITUDE_DIR[match.group('dir')] * ( float(match.group('deg')) + float(match.group('min')) / 60 + float(match.group('sec')) / 3600) target.longitude = longitude else: raise ValueError('Longitude is not valid: %s' % longitude_str) if orientation: target.orientation = orientation if shape: target.shape = shape if background_color: target.background_color = background_color if alphanumeric: target.alphanumeric = alphanumeric if alphanumeric_color: target.alphanumeric_color = alphanumeric_color if description: target.description = description targets.append((target, image_filepath)) return targets
def target_data(self, target): # the ** operator unwraps the dictionary (here a json object) # into an actual argument list, and then we use that to create # an instance of the interop Target class t = Target(**target) self.client.post_target(t)