# HG changeset patch # User Erik Grinaker # Date 1091891976 0 # Node ID a78b3bc44c12ae4b64945cfb0e31af4ca08162be # Parent f5321aba18db1acac614fee1b0b291de860eede3 minor code cleanups diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be ChangeLog --- a/ChangeLog Fri Aug 06 13:10:02 2004 +0000 +++ b/ChangeLog Sat Aug 07 15:19:36 2004 +0000 @@ -2,6 +2,10 @@ ---------------[ xxxx-xx-xx : 0.3.1 ]--------------- +2004-08-07 Erik Grinaker + + * minor code cleanups + 2004-08-06 Erik Grinaker * updated NEWS file diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be TODO --- a/TODO Fri Aug 06 13:10:02 2004 +0000 +++ b/TODO Sat Aug 07 15:19:36 2004 +0000 @@ -1,10 +1,7 @@ 0.3.x: - password strength check (cracklib?) - option for autolocking the file after a period of inactivity -- don't use modal dialogs unless absolutely necessary - add a password generator dialog (under Tools/Password Generator menu) -- add info about file as cmdline-arg in --help text -- string cleanups - program-launchers for misc account types (announce on rvl-list when done in svn) - export to XHTML/CSS files @@ -32,6 +29,9 @@ - use a spin button for integer fields (port) - add a dropdown widget for list fields (like email protocol etc) - use the row= arg to the TreeStore functions to avoid column indexes +- add info about file as cmdline-arg in --help text +- string cleanups +- don't use modal dialogs unless absolutely necessary 0.5.x: - remove support for version 0 data files diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/data.py --- a/src/lib/data.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/data.py Sat Aug 07 15:19:36 2004 +0000 @@ -314,7 +314,7 @@ # check the entry type - if entry.type == revelation.entry.ENTRY_FOLDER and not self.folders: + if entry.type == revelation.entry.ENTRY_FOLDER and self.folders == gtk.FALSE: return gtk.FALSE if self.type is not None and entry.type not in [ self.type, revelation.entry.ENTRY_FOLDER ]: @@ -462,7 +462,6 @@ for i in range(source.iter_n_children(None)): sourceiter = source.iter_nth_child(None, i) newiter = source.export_entry(sourceiter, self, parent, sibling) - newiters.append(newiter) return newiters @@ -508,8 +507,9 @@ if iter is None or self.get_entry(iter).type != revelation.entry.ENTRY_FOLDER: return - if open: + elif open: self.set_value(iter, ENTRYSTORE_COL_ICON, revelation.stock.STOCK_FOLDER_OPEN) + else: self.set_value(iter, ENTRYSTORE_COL_ICON, revelation.stock.STOCK_FOLDER) diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/datahandler/base.py --- a/src/lib/datahandler/base.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/datahandler/base.py Sat Aug 07 15:19:36 2004 +0000 @@ -52,7 +52,7 @@ def __init__(self): gobject.GObject.__init__(self) - self.cipher = None + self.cipher = None def compress_zlib(self, data): @@ -169,13 +169,11 @@ "Initializes an XML importer" try: - doc = libxml2.parseDoc(xml) + return libxml2.parseDoc(xml) except (libxml2.parserError, TypeError): raise FormatError - return doc - def xml_import_scan(self, node, childname): "Scans an XML node for a named child" diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/datahandler/fpm.py --- a/src/lib/datahandler/fpm.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/datahandler/fpm.py Sat Aug 07 15:19:36 2004 +0000 @@ -71,7 +71,6 @@ for i in range(len(data) / 2): high = ord(data[2 * i]) - ord("a") low = ord(data[2 * i + 1]) - ord("a") - res += chr(high * 16 + low) return res @@ -95,7 +94,6 @@ for i in range(len(data)): high = ord(data[i]) / 16 low = ord(data[i]) - high * 16 - res += chr(ord('a') + high) + chr(ord('a') + low) return res @@ -209,40 +207,44 @@ while fieldnode is not None: - if fieldnode.type == "element": - content = self.__decrypt_field(fieldnode.content).strip() + if fieldnode.type != "element": + fieldnode = fieldnode.next + continue - if fieldnode.name == "title": - entry.name = content - elif fieldnode.name == "user": - entry.set_field(revelation.entry.FIELD_GENERIC_USERNAME, content) + content = self.__decrypt_field(fieldnode.content).strip() - elif fieldnode.name == "url": - entry.set_field(revelation.entry.FIELD_GENERIC_HOSTNAME, content) + if fieldnode.name == "title": + entry.name = content - elif fieldnode.name == "password": - entry.set_field(revelation.entry.FIELD_GENERIC_PASSWORD, content) + elif fieldnode.name == "user": + entry.set_field(revelation.entry.FIELD_GENERIC_USERNAME, content) - elif fieldnode.name == "notes": - entry.description = content + elif fieldnode.name == "url": + entry.set_field(revelation.entry.FIELD_GENERIC_HOSTNAME, content) - elif fieldnode.name == "category": - foldername = content + elif fieldnode.name == "password": + entry.set_field(revelation.entry.FIELD_GENERIC_PASSWORD, content) - if foldername == "": - pass + elif fieldnode.name == "notes": + entry.description = content - elif folders.has_key(foldername): - parent = folders[foldername] + elif fieldnode.name == "category": + foldername = content - else: - folderentry = revelation.entry.Entry(revelation.entry.ENTRY_FOLDER) - folderentry.name = foldername - folderentry.updated = time.time() + if foldername == "": + pass - parent = entrystore.add_entry(None, folderentry) - folders[foldername] = parent + elif folders.has_key(foldername): + parent = folders[foldername] + + else: + folderentry = revelation.entry.Entry(revelation.entry.ENTRY_FOLDER) + folderentry.name = foldername + folderentry.updated = time.time() + + parent = entrystore.add_entry(None, folderentry) + folders[foldername] = parent fieldnode = fieldnode.next @@ -250,7 +252,6 @@ entrynode = entrynode.next - def __xml_get_keyinfo(self, root): "Looks up the key info from the XML" @@ -277,13 +278,11 @@ try: self.check_data(header) + return gtk.TRUE except base.FormatError: return gtk.FALSE - else: - return gtk.TRUE - def export_data(self, entrystore, password): "Exports data from an entrystore into a data stream" diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/datahandler/gpass.py --- a/src/lib/datahandler/gpass.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/datahandler/gpass.py Sat Aug 07 15:19:36 2004 +0000 @@ -53,59 +53,6 @@ base.DataHandler.__init__(self) - def __decrypt(self, data, password): - "Decrypts the data" - - self.cipher_init( - Blowfish, SHA.new(password).digest(), - "\x05\x17\x01\x7b\x0c\x03\x36\x5e", 8 - ) - - plain = self.cipher_decrypt(data) - - if plain[0:23] != "GNOME Password Manager\n": - raise base.PasswordError - - plain = plain[23:] - - - # remove padding - padchar = plain[-1] - - if plain[-ord(padchar):] != padchar * ord(padchar): - raise base.FormatError - - plain = plain[:-ord(padchar)] - - return plain - - - - def __encrypt(self, data, password): - "Encrypts the data" - - # prepend a magic string - data = "GNOME Password Manager\n" + data - - # pad the data - padlen = 8 - (len(data) % 8) - if padlen == 0: - padlen = 8 - - data += (chr(padlen) * padlen) - - - # encrypt the data - self.cipher_init( - Blowfish, SHA.new(password).digest(), - "\x05\x17\x01\x7b\x0c\x03\x36\x5e", 8 - ) - - cipher = self.cipher_encrypt(data) - - return cipher - - def __parse(self, data): "Parses the data, returns an entrystore" @@ -164,7 +111,6 @@ else: continue - index += 1 @@ -202,17 +148,59 @@ def export_data(self, entrystore, password): "Exports data to a data stream" + # serialize data data = self.__serialize(entrystore) - cipher = self.__encrypt(data, password) - return cipher + + # prepend magic string + data = "GNOME Password Manager\n" + data + + + # pad the data + padlen = 8 - (len(data) % 8) + if padlen == 0: + padlen = 8 + + data += chr(padlen) * padlen + + + # encrypt the data + self.cipher_init( + Blowfish, SHA.new(password).digest(), + "\x05\x17\x01\x7b\x0c\x03\x36\x5e", 8 + ) + + return self.cipher_encrypt(data) def import_data(self, data, password): "Imports data from a data stream into an entrystore" - plain = self.__decrypt(data, password) - entrystore = self.__parse(plain) + # decrypt data + self.cipher_init( + Blowfish, SHA.new(password).digest(), + "\x05\x17\x01\x7b\x0c\x03\x36\x5e", 8 + ) - return entrystore + plain = self.cipher_decrypt(data) + + # check for magic string + if plain[0:23] != "GNOME Password Manager\n": + raise base.PasswordError + + plain = plain[23:] + + + # check and remove padding + padchar = plain[-1] + + if plain[-ord(padchar):] != padchar * ord(padchar): + raise base.FormatError + + plain = plain[:-ord(padchar)] + + + # deserialize data + return self.__parse(plain) + diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/datahandler/netrc.py --- a/src/lib/datahandler/netrc.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/datahandler/netrc.py Sat Aug 07 15:19:36 2004 +0000 @@ -57,6 +57,7 @@ if hostname == "" or username == "" or password == "": continue + # add name and description as comments, if any if entry.name != "": data += "# " + entry.name + "\n" @@ -64,6 +65,7 @@ if entry.description != "": data += "# " + entry.description + "\n" + # export the entry itself data += "machine " + hostname + "\n" data += " login " + username + "\n" @@ -104,6 +106,7 @@ while 1: line = lexer.instream.readline() + if not line or line == '\012': lexer.whitespace = ' \t\r\n' break diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/datahandler/rvl.py --- a/src/lib/datahandler/rvl.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/datahandler/rvl.py Sat Aug 07 15:19:36 2004 +0000 @@ -103,13 +103,11 @@ try: self.check_data(data) + return gtk.TRUE except base.FormatError, base.VersionError: return gtk.FALSE - else: - return gtk.TRUE - def export_data(self, entrystore, parent = None, level = 0): "Serializes data from the entrystore into an XML stream" @@ -247,13 +245,11 @@ try: self.__parse_header(data[:12]) + return gtk.TRUE except base.FormatError: return gtk.FALSE - else: - return gtk.TRUE - def export_data(self, entrystore, password): "Serializes the entrystore into a data stream" diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/dialog.py --- a/src/lib/dialog.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/dialog.py Sat Aug 07 15:19:36 2004 +0000 @@ -189,6 +189,7 @@ ) + class FileChangedOpen(FileChanged): "Asks the user to save changes when opening a different file" @@ -394,6 +395,7 @@ raise revelation.CancelError + # entry-related dialogs class EntryEdit(Property): @@ -693,13 +695,14 @@ "Displays the dialog" while 1: - if Password.run(self) == gtk.RESPONSE_OK: + if Password.run(self) != gtk.RESPONSE_OK: + continue - if self.entry_new.get_text() != self.entry_confirm.get_text(): - Error(self, "Passwords don't match", "The password and password confirmation you entered does not match.").run() + if self.entry_new.get_text() != self.entry_confirm.get_text(): + Error(self, "Passwords don't match", "The password and password confirmation you entered does not match.").run() - else: - return self.entry_new.get_text() + else: + return self.entry_new.get_text() diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/entry.py --- a/src/lib/entry.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/entry.py Sat Aug 07 15:19:36 2004 +0000 @@ -247,6 +247,7 @@ } + class EntryError(Exception): pass @@ -389,6 +390,7 @@ if type == "usenet": type = ENTRY_ACCOUNT_GENERIC + if not ENTRYDATA.has_key(type): raise EntryTypeError @@ -440,7 +442,6 @@ widget = revelation.widget.Label(revelation.misc.escape_markup(self.value)) widget.set_selectable(gtk.TRUE) - return widget diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/io.py --- a/src/lib/io.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/io.py Sat Aug 07 15:19:36 2004 +0000 @@ -39,11 +39,9 @@ self.file = file self.password = password + self.handler = None - if handler is None: - self.handler = None - - else: + if handler is not None: self.handler = handler() @@ -69,14 +67,14 @@ self.handler = handler return handler - raise DetectError + else: + raise DetectError def load(self): "Loads data from a file into an entrystore" self.check_file() - data = file_read(self.file) if self.needs_password(): diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/misc.py --- a/src/lib/misc.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/misc.py Sat Aug 07 15:19:36 2004 +0000 @@ -117,6 +117,7 @@ gmstart = time.gmtime(start) gmend = time.gmtime(end) + # get a human-readable time period if diff >= int(365.25 * 24 * 60 * 60): period = int(diff / 365.25 / 24 / 60 / 60) unit = "year" @@ -145,8 +146,10 @@ period = diff unit = "second" + if period == 1: return str(period) + " " + unit + else: return str(period) + " " + unit + "s" diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/lib/ui.py --- a/src/lib/ui.py Fri Aug 06 13:10:02 2004 +0000 +++ b/src/lib/ui.py Sat Aug 07 15:19:36 2004 +0000 @@ -44,12 +44,13 @@ "Clears the data view" # only clear if containing an entry, or if forced - if force == gtk.TRUE or self.entry is not None: + if force == gtk.FALSE or self.entry is None: + return - self.entry = None + self.entry = None - for child in self.get_children(): - child.destroy() + for child in self.get_children(): + child.destroy() def display_entry(self, entry): @@ -191,7 +192,9 @@ revelation.widget.TreeView.set_model(self, model) - if model is not None: - for i in range(model.iter_n_children(None)): - model.set_folder_state(model.iter_nth_child(None, i), gtk.FALSE) + if model is None: + return + for i in range(model.iter_n_children(None)): + model.set_folder_state(model.iter_nth_child(None, i), gtk.FALSE) + diff -r f5321aba18db1acac614fee1b0b291de860eede3 -r a78b3bc44c12ae4b64945cfb0e31af4ca08162be src/revelation --- a/src/revelation Fri Aug 06 13:10:02 2004 +0000 +++ b/src/revelation Sat Aug 07 15:19:36 2004 +0000 @@ -388,6 +388,8 @@ dialog.destroy() break + return entrystore + except revelation.datahandler.FormatError: self.statusbar.set_status("Open failed") revelation.dialog.Error( @@ -427,9 +429,6 @@ dialog.destroy() raise - else: - return entrystore - def __file_save(self, datafile): @@ -455,15 +454,14 @@ datafile.save(self.data) + return gtk.TRUE except IOError: revelation.dialog.Error(self, "Unable to write to file", "The file '" + datafile.file + "' could not be opened for writing. Make sure that you have the proper permissions to write to it.").run() self.statusbar.set_status("Save failed") + return gtk.FALSE - else: - return gtk.TRUE - def __save_changes(self, dialog): "Asks the user if she wants to save her changes" @@ -475,12 +473,11 @@ if dialog(self).run() == gtk.TRUE: return self.file_save(self.data.file, self.data.password) + return gtk.TRUE + except revelation.CancelError: return gtk.FALSE - else: - return gtk.TRUE - # public methods @@ -639,13 +636,11 @@ file, handler = revelation.dialog.ExportFileSelector(self).run() datafile = revelation.io.DataFile(file, handler) self.__file_save(datafile) + self.statusbar.set_status("Data exported to " + datafile.file) except revelation.CancelError: self.statusbar.set_status("Export cancelled") - else: - self.statusbar.set_status("Data exported to " + datafile.file) - def file_import(self): "Imports data from a foreign file" @@ -658,15 +653,14 @@ if entrystore is None: return - except revelation.CancelError: - self.statusbar.set_status("Import cancelled") - - else: iters = self.data.import_entrystore(entrystore) self.undoqueue.add_action(revelation.data.UNDO_ACTION_IMPORT, iters) self.__file_autosave() self.statusbar.set_status("Data imported from " + datafile.file) + except revelation.CancelError: + self.statusbar.set_status("Import cancelled") + def file_lock(self): "Locks the current data file" @@ -726,13 +720,13 @@ if entrystore is None: return + self.data.replace_entrystore(entrystore) + self.statusbar.set_status("Opened file " + datafile.file) + + except revelation.CancelError: self.statusbar.set_status("Open cancelled") - else: - self.data.replace_entrystore(entrystore) - self.statusbar.set_status("Opened file " + datafile.file) - def file_revert(self): "Reverts to the saved version of the file"