Merge lp:~jdstrand/pasaffe/pasaffe into lp:~mdeslaur/pasaffe/trunk

Proposed by Jamie Strandboge
Status: Merged
Merged at revision: 144
Proposed branch: lp:~jdstrand/pasaffe/pasaffe
Merge into: lp:~mdeslaur/pasaffe/trunk
Diff against target: 117 lines (+102/-0)
2 files modified
NEWS (+2/-0)
bin/pasaffe-dump-db (+100/-0)
To merge this branch: bzr merge lp:~jdstrand/pasaffe/pasaffe
Reviewer Review Type Date Requested Status
Marc Deslauriers Pending
Review via email: mp+73085@code.launchpad.net

Description of the change

Add pasaffe-dump-db

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-08-25 20:50:48 +0000
3+++ NEWS 2011-08-26 18:03:23 +0000
4@@ -4,6 +4,8 @@
5 0.8 (UNRELEASED):
6
7 * Enhancements:
8+ - add pasaffe-dump-db to dump contents of DB to stdout in a human readable
9+ format
10
11 * Bug fixes:
12 - Only update right pane after editing an entry if it's still the one
13
14=== added file 'bin/pasaffe-dump-db'
15--- bin/pasaffe-dump-db 1970-01-01 00:00:00 +0000
16+++ bin/pasaffe-dump-db 2011-08-26 18:03:23 +0000
17@@ -0,0 +1,100 @@
18+#!/usr/bin/python
19+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
20+### BEGIN LICENSE
21+# Copyright (C) 2011 Jamie Strandboge <jamie@canonical.com>
22+# Based on work by Marc Deslauriers <marc.deslauriers@canonical.com>
23+#
24+# This program is free software: you can redistribute it and/or modify it
25+# under the terms of the GNU General Public License version 3, as published
26+# by the Free Software Foundation.
27+#
28+# This program is distributed in the hope that it will be useful, but
29+# WITHOUT ANY WARRANTY; without even the implied warranties of
30+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
31+# PURPOSE. See the GNU General Public License for more details.
32+#
33+# You should have received a copy of the GNU General Public License along
34+# with this program. If not, see <http://www.gnu.org/licenses/>.
35+### END LICENSE
36+
37+import getpass
38+import sys
39+import os
40+import struct
41+import time
42+from optparse import OptionParser
43+
44+import gettext
45+from gettext import gettext as _
46+gettext.textdomain('pasaffe')
47+
48+# Add project root directory (enable symlink and trunk execution)
49+PROJECT_ROOT_DIRECTORY = os.path.abspath(
50+ os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
51+
52+python_path = []
53+if os.path.abspath(__file__).startswith('/opt'):
54+ syspath = sys.path[:] # copy to avoid infinite loop in pending objects
55+ for path in syspath:
56+ opt_path = path.replace('/usr', '/opt/extras.ubuntu.com/pasaffe')
57+ python_path.insert(0, opt_path)
58+ sys.path.insert(0, opt_path)
59+if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'pasaffe'))
60+ and PROJECT_ROOT_DIRECTORY not in sys.path):
61+ python_path.insert(0, PROJECT_ROOT_DIRECTORY)
62+ sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
63+if python_path:
64+ os.putenv('PYTHONPATH', "%s:%s" % (os.getenv('PYTHONPATH', ''), ':'.join(python_path))) # for subprocesses
65+
66+from pasaffe_lib import readdb
67+
68+parser = OptionParser()
69+parser.add_option("-f", "--file", dest="filename",
70+ help="specify alternate GPass database file", metavar="FILE")
71+
72+(options, args) = parser.parse_args()
73+
74+if os.environ.has_key('XDG_DATA_HOME'):
75+ db_filename = os.path.join(os.environ['XDG_DATA_HOME'], 'pasaffe/pasaffe.psafe3')
76+else:
77+ db_filename = os.path.join(os.environ['HOME'], '.local/share/pasaffe/pasaffe.psafe3')
78+
79+if options.filename != None:
80+ db_filename = options.filename
81+
82+if not os.path.exists(db_filename):
83+ print "\n\nERROR: Could not locate database file!"
84+ sys.exit(1)
85+
86+print "WARNING: this will display all password entries."
87+
88+count = 0
89+max_tries = 3
90+while count < max_tries:
91+ count += 1
92+ master = getpass.getpass("Password> ")
93+ try:
94+ passfile = readdb.PassSafeFile(db_filename, master)
95+ break
96+ except ValueError:
97+ print "Sorry, try again."
98+
99+ if count >= max_tries:
100+ print "%d incorrect password attempts" % (count)
101+ sys.exit(1)
102+
103+record_dict = { 'Entry' : 3,
104+ 'Username' : 4,
105+ 'Notes' : 5,
106+ 'Password' : 6,
107+ 'URL' : 13
108+ }
109+
110+for record in sorted(passfile.records, key=lambda entry: entry[3].lower()):
111+ # specify order of labels and values
112+ for label in ['Entry', 'Username', 'Password', 'URL', 'Notes']:
113+ record_type = record_dict[label]
114+ if record.has_key(record_type) and record[record_type] != "":
115+ print "%s: %s" % (label, record[record_type])
116+ print ""
117+

Subscribers

People subscribed via source and target branches