def description(self): ''' We have to ensure that the description text is formatted correctly, it gets dumped into a <pre> tag which will honor whitespace this will split all of the text and insert newlines every 70 chars +2 whitespace at be beginning of each line, so the indents line up nicely. ''' if self.autoformat: index, step = 0, 70 ls = [' '] if 0 < len(self._description): text = self._description.replace('\n', '') while index < len(text): ls.append(" " + text[index:index + step]) index += step if len(ls) == 1: if self.category_id: ls.append(" Category: %s\n" % Category.by_id(self.category_id).category) else: ls.append(" No information on file.") else: if self.category_id: ls.append("\n Category: %s\n" % Category.by_id(self.category_id).category) if self.operating_system != "none": ls.append("\n Operating System: %s\n" % self.operating_system) if self.difficulty != "Unknown": ls.append(" Reported Difficulty: %s\n" % self.difficulty) if not str(ls[-1]).endswith("\n"): ls[-1] = ls[-1] + "\n" return unicode("\n".join(ls)) else: return self._description
def to_xml(self, parent): ''' Convert object to XML ''' box_elem = ET.SubElement(parent, "box") box_elem.set("gamelevel", str(self.game_level.number)) ET.SubElement(box_elem, "name").text = self.name ET.SubElement( box_elem, "operatingsystem").text = self._operating_system ET.SubElement(box_elem, "description").text = self._description ET.SubElement(box_elem, "flag_submission_type").text = FlagsSubmissionType(self.flag_submission_type).name ET.SubElement(box_elem, "difficulty").text = self._difficulty ET.SubElement(box_elem, "garbage").text = self.garbage if self.category_id: ET.SubElement(box_elem, "category").text = Category.by_id(self.category_id).category flags_elem = ET.SubElement(box_elem, "flags") flags_elem.set("count", str(len(self.flags))) for flag in self.flags: flag.to_xml(flags_elem) hints_elem = ET.SubElement(box_elem, "hints") count = 0 for hint in self.hints: if hint.flag_id is None: hint.to_xml(hints_elem) count += 1 hints_elem.set("count", str(count)) ips_elem = ET.SubElement(box_elem, "ipaddresses") ips_elem.set("count", str(len(self.ip_addresses))) for ip in self.ip_addresses: ip.to_xml(ips_elem) with open(options.avatar_dir + '/' + self.avatar, mode='rb') as _avatar: data = _avatar.read() ET.SubElement(box_elem, "avatar").text = data.encode('base64')
def to_xml(self, parent): ''' Convert object to XML ''' box_elem = ET.SubElement(parent, "box") box_elem.set("gamelevel", str(self.game_level.number)) ET.SubElement(box_elem, "name").text = self.name ET.SubElement( box_elem, "operatingsystem").text = self._operating_system ET.SubElement(box_elem, "description").text = self._description ET.SubElement(box_elem, "flag_submission_type").text = FlagsSubmissionType(self.flag_submission_type).name ET.SubElement(box_elem, "difficulty").text = self._difficulty ET.SubElement(box_elem, "garbage").text = self.garbage if self.category_id: ET.SubElement(box_elem, "category").text = Category.by_id(self.category_id).category flags_elem = ET.SubElement(box_elem, "flags") flags_elem.set("count", str(len(self.flags))) for flag in self.flags: flag.to_xml(flags_elem) hints_elem = ET.SubElement(box_elem, "hints") count = 0 for hint in self.hints: if hint.flag_id is None: hint.to_xml(hints_elem) count += 1 hints_elem.set("count", str(count)) ips_elem = ET.SubElement(box_elem, "ipaddresses") ips_elem.set("count", str(len(self.ip_addresses))) for ip in self.ip_addresses: ip.to_xml(ips_elem) avatarfile = os.path.join(options.avatar_dir, self.avatar) if self.avatar and os.path.isfile(avatarfile): with open(avatarfile, mode='rb') as _avatar: data = _avatar.read() ET.SubElement(box_elem, "avatar").text = data.encode('base64') else: ET.SubElement(box_elem, "avatar").text = "none"
def to_dict(self): ''' Returns editable data as a dictionary ''' corp = Corporation.by_id(self.corporation_id) game_level = GameLevel.by_id(self.game_level_id) cat = Category.by_id(self.category_id) if cat: category = cat.uuid else: category = "" return { 'name': self.name, 'uuid': self.uuid, 'corporation': corp.uuid, 'category': category, 'operating_system': self.operating_system, 'description': self._description, 'difficulty': self.difficulty, 'game_level': game_level.uuid, 'flaglist': self.flaglist(self.id) }
def to_dict(self): ''' Returns editable data as a dictionary ''' corp = Corporation.by_id(self.corporation_id) game_level = GameLevel.by_id(self.game_level_id) cat = Category.by_id(self.category_id) if cat: category = cat.uuid else: category = "" return { 'name': self.name, 'uuid': self.uuid, 'corporation': corp.uuid, 'category': category, 'operating_system': self.operating_system, 'description': self._description, 'difficulty': self.difficulty, 'game_level': game_level.uuid, 'flag_submission_type': self.flag_submission_type, 'flaglist': self.flaglist(self.id) }
def to_dict(self): """ Returns editable data as a dictionary """ corp = Corporation.by_id(self.corporation_id) game_level = GameLevel.by_id(self.game_level_id) cat = Category.by_id(self.category_id) if cat: category = cat.uuid else: category = "" return { "name": self.name, "uuid": self.uuid, "corporation": corp.uuid, "category": category, "operating_system": self.operating_system, "description": self._description, "difficulty": self.difficulty, "game_level": game_level.uuid, "flag_submission_type": self.flag_submission_type, "flaglist": self.flaglist(self.id), }
def to_xml(self, parent): """ Convert object to XML """ box_elem = ET.SubElement(parent, "box") box_elem.set("gamelevel", "%s" % str(self.game_level.number)) ET.SubElement(box_elem, "name").text = self.name ET.SubElement(box_elem, "operatingsystem").text = self._operating_system ET.SubElement(box_elem, "description").text = self._description ET.SubElement(box_elem, "capture_message").text = self.capture_message ET.SubElement(box_elem, "value").text = str(self.value) ET.SubElement(box_elem, "flag_submission_type").text = FlagsSubmissionType( self.flag_submission_type).name ET.SubElement(box_elem, "difficulty").text = self._difficulty ET.SubElement(box_elem, "garbage").text = str(self.garbage) if self.category_id: ET.SubElement(box_elem, "category").text = Category.by_id( self.category_id).category flags_elem = ET.SubElement(box_elem, "flags") flags_elem.set("count", "%s" % str(len(self.flags))) for flag in self.flags: flag.to_xml(flags_elem) hints_elem = ET.SubElement(box_elem, "hints") count = 0 for hint in self.hints: if hint.flag_id is None: hint.to_xml(hints_elem) count += 1 hints_elem.set("count", "%s" % str(count)) ips_elem = ET.SubElement(box_elem, "ipaddresses") ips_elem.set("count", "%s" % str(len(self.ip_addresses))) for ip in self.ip_addresses: ip.to_xml(ips_elem) avatarfile = os.path.join(options.avatar_dir, self.avatar) if self.avatar and os.path.isfile(avatarfile): with open(avatarfile, mode="rb") as _avatar: data = _avatar.read() ET.SubElement(box_elem, "avatar").text = encode(data, "base64") else: ET.SubElement(box_elem, "avatar").text = "none"