Commits

Erik Grinaker committed ec7798c

moved convert_entry_generic() to the Entry.convert_generic() method

Comments (0)

Files changed (6)

 - generate ChangeLog from subversion log during make dist
 - removed gnomemisc module
 - don't use deprecated gnome-python modules
+- moved convert_entry_generic() to the Entry.convert_generic() method
 
 
 2006-02-06: Revelation 0.4.7
   (http://blogs.gnome.org/view/ryanl/2006/07/27/0)
 - fix translation of entry type names (needs to be done with
   instantiation, or initialize gettext before importing entry module)
-- convert_entry_generic() should be a method of Entry
 
 0.6.x:
 - ensure complete UTF-8 support

src/lib/datahandler/fpm.py

 			e = entrystore.get_entry(iter)
 
 			if type(e) != entry.FolderEntry:
-				e = entry.convert_entry_generic(e)
+				e = e.convert_generic()
 
 				xml += "		<PasswordItem>\n"
 				xml += "			<title>%s</title>\n" % e.name

src/lib/datahandler/gpass.py

 			e = entrystore.get_entry(iter)
 
 			if type(e) != entry.FolderEntry:
-				e = entry.convert_entry_generic(e)
+				e = e.convert_generic()
 
 				data += e.name + "\n"
 				data += e[entry.UsernameField] + "\n"
 				foldermap[path] = id
 
 			elif type(e) != entry.GenericEntry:
-				e = entry.convert_entry_generic(e)
+				e = e.convert_generic()
 
 
 			entrydata	= ""

src/lib/datahandler/pwsafe.py

 			e = entrystore.get_entry(iter)
 
 			if type(e) != entry.FolderEntry:
-				e = entry.convert_entry_generic(e)
+				e = e.convert_generic()
 
 				edata = ""
 				edata += create_field(e.name.encode(enc, "replace") + "\xAD" + e[entry.UsernameField].encode("iso-8859-1"))
 			e = entrystore.get_entry(iter)
 
 			if type(e) != entry.FolderEntry:
-				e = entry.convert_entry_generic(e)
+				e = e.convert_generic()
 
 				uuid = util.random_string(16)
 
 		self.get_field(key).value = value
 
 
+	def convert_generic(self):
+		"Creates a GenericEntry with the data from this entry"
+
+		generic = GenericEntry()
+		generic.name = self.name
+		generic.description = self.description
+		generic.updated = self.updated
+
+		# do direct field copies
+		for field in generic.fields:
+			if self.has_field(type(field)):
+				field.value = self[type(field)]
+
+		# handle special conversions
+		if type(self) == CreditcardEntry:
+			generic[UsernameField] = self[CardnumberField]
+			generic[PasswordField] = self[PINField]
+
+		elif type(self) == CryptoKeyEntry:
+			generic[UsernameField] = self[KeyfileField]
+
+		elif type(self) == DatabaseEntry:
+			if self[DatabaseField] != "":
+				generic[HostnameField] = self[DatabaseField] + "@" + self[HostnameField]
+
+		elif type(self) == DoorEntry:
+			generic[PasswordField] = self[CodeField]
+			generic[HostnameField] = self[LocationField]
+
+		elif type(self) == FTPEntry:
+			if self[PortField] not in ( "", "21" ):
+				generic[HostnameField] += ":" + self[PortField]
+
+		elif type(self) == PhoneEntry:
+			generic[UsernameField] = self[PhonenumberField]
+			generic[PasswordField] = self[PINField]
+
+		elif type(self) == WebEntry:
+			generic[HostnameField] = self[URLField]
+
+
+		return generic
+
+
 	def copy(self):
 		"Create a copy of the entry"
 
 	UsernameField
 ]
 
-
-
-def convert_entry_generic(entry):
-	"Converts an entry to GenericEntry, tries to keep as much data as possible"
-
-	generic = GenericEntry()
-	generic.name = entry.name
-	generic.description = entry.description
-	generic.updated = entry.updated
-
-	# do direct field copies
-	for field in generic.fields:
-		if entry.has_field(type(field)):
-			field.value = entry[type(field)]
-
-	# handle special conversions
-	if type(entry) == CreditcardEntry:
-		generic[UsernameField] = entry[CardnumberField]
-		generic[PasswordField] = entry[PINField]
-
-	elif type(entry) == CryptoKeyEntry:
-		generic[UsernameField] = entry[KeyfileField]
-
-	elif type(entry) == DatabaseEntry:
-		if entry[DatabaseField] != "":
-			generic[HostnameField] = entry[DatabaseField] + "@" + entry[HostnameField]
-
-	elif type(entry) == DoorEntry:
-		generic[PasswordField] = entry[CodeField]
-		generic[HostnameField] = entry[LocationField]
-
-	elif type(entry) == FTPEntry:
-		if entry[PortField] not in ( "", "21" ):
-			generic[HostnameField] += ":" + entry[PortField]
-
-	elif type(entry) == PhoneEntry:
-		generic[UsernameField] = entry[PhonenumberField]
-		generic[PasswordField] = entry[PINField]
-
-	elif type(entry) == WebEntry:
-		generic[HostnameField] = entry[URLField]
-
-
-	return generic
-