Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2b61e0

Browse files
author
Skip Montanaro
committed
* explain flags in doc strings
* reverse order of files on the command line in pickle2db.py to make it symmetrical with db2pickle.py in the two-arg case (src, then dest)
1 parent 47db165 commit e2b61e0

3 files changed

Lines changed: 37 additions & 15 deletions

File tree

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ Tools/Demos
345345

346346
- The db2pickle and pickle2db scripts can now dump/load gdbm files.
347347

348+
- The file order on the command line of the pickle2db script was reversed.
349+
It is now [ picklefile ] dbfile. This provides better symmetry with
350+
db2pickle. The file arguments to both scripts are now source followed by
351+
destination in situations where both files are given.
352+
348353
- The pydoc script will display a link to the module documentation for
349354
modules determined to be part of the core distribution. The documentation
350355
base directory defaults to http://www.python.org/doc/current/lib/ but can

Tools/scripts/db2pickle.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
Synopsis: %(prog)s [-h|-g|-b|-r|-a] dbfile [ picklefile ]
55
66
Convert the database file given on the command line to a pickle
7-
representation. The optional flags indicate the type of the database (hash,
8-
btree, recno). The default is hash. If a pickle file is named it is opened
9-
for write access (deleting any existing data). If no pickle file is named,
10-
the pickle output is written to standard output.
7+
representation. The optional flags indicate the type of the database:
8+
9+
-a - open using anydbm
10+
-b - open as bsddb btree file
11+
-d - open as dbm file
12+
-g - open as gdbm file
13+
-h - open as bsddb hash file
14+
-r - open as bsddb recno file
15+
16+
The default is hash. If a pickle file is named it is opened for write
17+
access (deleting any existing data). If no pickle file is named, the pickle
18+
output is written to standard output.
1119
1220
"""
1321

Tools/scripts/pickle2db.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
#!/usr/bin/env python
22

33
"""
4-
Synopsis: %(prog)s [-h|-b|-g|-r|-a|-d] dbfile [ picklefile ]
4+
Synopsis: %(prog)s [-h|-b|-g|-r|-a|-d] [ picklefile ] dbfile
55
66
Read the given picklefile as a series of key/value pairs and write to a new
77
database. If the database already exists, any contents are deleted. The
8-
optional flags indicate the type of the database (bsddb hash, bsddb btree,
9-
bsddb recno, anydbm, dbm). The default is hash. If a pickle file is named
10-
it is opened for read access. If no pickle file is named, the pickle input
11-
is read from standard input.
8+
optional flags indicate the type of the output database:
129
13-
Note that recno databases can only contain numeric keys, so you can't dump a
10+
-a - open using anydbm
11+
-b - open as bsddb btree file
12+
-d - open as dbm file
13+
-g - open as gdbm file
14+
-h - open as bsddb hash file
15+
-r - open as bsddb recno file
16+
17+
The default is hash. If a pickle file is named it is opened for read
18+
access. If no pickle file is named, the pickle input is read from standard
19+
input.
20+
21+
Note that recno databases can only contain integer keys, so you can't dump a
1422
hash or btree database using db2pickle.py and reconstitute it to a recno
15-
database with %(prog)s.
23+
database with %(prog)s unless your keys are integers.
24+
1625
"""
1726

1827
import getopt
@@ -56,15 +65,15 @@ def main(args):
5665
usage()
5766
return 1
5867
elif len(args) == 1:
59-
dbfile = args[0]
6068
pfile = sys.stdin
61-
else:
6269
dbfile = args[0]
70+
else:
6371
try:
64-
pfile = open(args[1], 'rb')
72+
pfile = open(args[0], 'rb')
6573
except IOError:
66-
sys.stderr.write("Unable to open %s\n" % args[1])
74+
sys.stderr.write("Unable to open %s\n" % args[0])
6775
return 1
76+
dbfile = args[1]
6877

6978
dbopen = None
7079
for opt, arg in opts:

0 commit comments

Comments
 (0)