コード例 #1
0
	def startElement(self, name, attrs):
		if name == 'vampire':
			if not attrs.has_key('name'):
				return
			v = Vampire()
			v.read_attributes(attrs)
			self.current_vampire = v

		elif name == 'experience':
			if self.current_experience:
				raise IOError('Experience encountered while still reading traitlist')
			exp = Experience()
			exp.read_attributes(attrs)
			self.current_experience = exp
			if self.current_vampire:
				self.current_vampire.add_experience(exp)

		elif name == 'entry':
			if not self.current_experience:
				raise IOError('Entry without bounding Experience')
			ent = ExperienceEntry()
			ent.read_attributes(attrs)
			self.current_experience.add_entry(ent, False)

		elif name == 'entry':
			pass

		elif name == 'biography':
			self.reading_biography = True

		elif name == 'notes':
			self.reading_notes = True

		elif name == 'traitlist':
			if self.current_traitlist:
				raise IOError('TraitList encountered while still reading traitlist')
			tl = TraitList()
			tl.read_attributes(attrs)
			self.current_traitlist = tl
			if self.current_vampire:
				self.current_vampire.add_traitlist(tl)

		elif name == 'trait':
			if not self.current_traitlist:
				raise IOError('Trait without bounding traitlist')
			t = Trait()
			t.read_attributes(attrs)
			self.current_traitlist.add_trait(t)
コード例 #2
0
ファイル: xml_uploader.py プロジェクト: gnu-lorien/vinesphere
    def __init__(self, vampire_sheet):
        from uploader import VAMPIRE_TAG_DATES, VAMPIRE_TAG_RENAMES
        from uploader import TRAIT_TAG_RENAMES
        from uploader import TRAITLIST_TAG_RENAMES
        from uploader import ENTRY_TAG_DATES, ENTRY_TAG_RENAMES
        from uploader import translate_date, map_attributes

        self.sheet = vampire_sheet

        vamp_attrs = dict((k, str(v)) for k,v in self.sheet.__dict__.iteritems())
        vamp_attrs.update((k, str(v)) for k,v in self.sheet.vampiresheet.__dict__.iteritems())
        vamp_attrs['player'] = self.sheet.player.username
        vamp_attrs['npc'] = 'yes' if self.sheet.npc else 'no'
        vamp_attrs['name'] = self.sheet.name
        for date_attribute in VAMPIRE_TAG_DATES:
            vamp_attrs[date_attribute] = translate_date(getattr(self.sheet, date_attribute))
        reversed_map = dict((v, k) for k, v in VAMPIRE_TAG_RENAMES.iteritems())
        map_attributes(reversed_map, vamp_attrs)
        #pprint(vamp_attrs)
        self.vampire = CrapvineVampire()
        self.vampire.read_attributes(vamp_attrs)
        #pprint(self.vampire.startdate)
        #pprint(self.vampire.npc)

        for tlp in self.sheet.get_traitlist_properties():
            tl_attrs = dict((k, str(v)) for k,v in tlp.__dict__.iteritems())
            tl_attrs['name'] = tlp.name.name
            map_attributes(dict((v,k) for k,v in TRAITLIST_TAG_RENAMES.iteritems()), tl_attrs)
            #pprint(tl_attrs)
            ctl = CrapvineTraitList()
            ctl.read_attributes(tl_attrs)

            for t in self.sheet.get_traits(tlp.name.name):
                t_attrs = dict((k, str(v)) for k,v in t.__dict__.iteritems())
                map_attributes(dict((v, k) for k, v in TRAIT_TAG_RENAMES.iteritems()), t_attrs)
                ct = CrapvineTrait()
                ct.read_attributes(t_attrs)
                ctl.add_trait(ct)

            self.vampire.add_traitlist(ctl)

        e = CrapvineExperience()
        e.read_attributes({
            'unspent':str(self.sheet.experience_unspent),
            'earned':str(self.sheet.experience_earned)})

        for ee in self.sheet.experience_entries.all():
            ee_attrs = dict((k, str(v)) for k,v in ee.__dict__.iteritems())
            for date_attribute in ENTRY_TAG_DATES:
                ee_attrs[date_attribute] = translate_date(getattr(ee, date_attribute))
            map_attributes(dict((v, k) for k, v in ENTRY_TAG_RENAMES.iteritems()), ee_attrs)
            cee = CrapvineExperienceEntry()
            cee.read_attributes(ee_attrs)
            e.add_entry(cee)

        self.vampire.add_experience(e)