"Fossies" - the Fresh Open Source Software Archive

Member "revelation-0.5.4/src/lib/datahandler/text.py" (4 Oct 2020, 2381 Bytes) of package /linux/privat/revelation-0.5.4.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "text.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.5.3_vs_0.5.4.

    1 #
    2 # Revelation - a password manager for GNOME 2
    3 # http://oss.codepoet.no/revelation/
    4 # $Id$
    5 #
    6 # Module for handling plain text files
    7 #
    8 #
    9 # Copyright (c) 2003-2006 Erik Grinaker
   10 #
   11 # This program is free software; you can redistribute it and/or
   12 # modify it under the terms of the GNU General Public License
   13 # as published by the Free Software Foundation; either version 2
   14 # of the License, or (at your option) any later version.
   15 #
   16 # This program is distributed in the hope that it will be useful,
   17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19 # GNU General Public License for more details.
   20 #
   21 # You should have received a copy of the GNU General Public License
   22 # along with this program; if not, write to the Free Software
   23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   24 #
   25 
   26 from . import base
   27 from revelation import entry
   28 
   29 import time
   30 
   31 
   32 class PlainText(base.DataHandler):
   33     "Data handler for plain text files"
   34 
   35     name        = "Plain text"
   36     importer    = False
   37     exporter    = True
   38     encryption  = False
   39 
   40 
   41     def export_data(self, entrystore, password = None):
   42         "Exports data to a plain text file"
   43 
   44         text = ""
   45         # fetch and sort entries
   46         iter = entrystore.iter_nth_child(None, 0)
   47 
   48         while iter is not None:
   49             e = entrystore.get_entry(iter)
   50 
   51             if type(e) == entry.FolderEntry:
   52                 text += "%s [Folder]\n" % e.name
   53                 text += "%s\n" % e.description
   54                 text += "%s\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(e.updated))
   55             else:
   56                 text += "%s [%s]\n" % ( e.name, e.typename )
   57                 text += e.description != "" and "%s\n" % e.description or ""
   58                 text += "%s\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(e.updated))
   59 
   60                 fields = [ field for field in e.fields if field.value != "" ]
   61 
   62                 if len(fields) > 0:
   63                     text += "\n"
   64                     maxlen = max([ len(field.name) for field in fields ])
   65 
   66                     for field in fields:
   67                         text += "- " + field.name + ": " + (" " * (maxlen - len(field.name))) + field.value + "\n"
   68 
   69             text += "\n\n"
   70 
   71             iter = entrystore.iter_traverse_next(iter)
   72 
   73         return text
   74