B Cm̉M;3@s"dZddlZy ddlZWnek r0dZYnXyddlmZWnek rZdZYnXyddlmZ Wnek rdZ YnXyddlmZ Wnek rdZ YnXddl Z y ddl Z Wnek rddl Z YnXe j dZddZddZedkre ee j dddS) aM Synopsis: %(prog)s [-h|-b|-g|-r|-a|-d] [ picklefile ] dbfile Read the given picklefile as a series of key/value pairs and write to a new database. If the database already exists, any contents are deleted. The optional flags indicate the type of the output database: -a - open using dbm (open any supported format) -b - open as bsddb btree file -d - open as dbm.ndbm file -g - open as dbm.gnu file -h - open as bsddb hash file -r - open as bsddb recno file The default is hash. If a pickle file is named it is opened for read access. If no pickle file is named, the pickle input is read from standard input. Note that recno databases can only contain integer keys, so you can't dump a hash or btree database using db2pickle.py and reconstitute it to a recno database with %(prog)s unless your keys are integers. NcCstjttdS)N)sysstderrwrite__doc__globalsrrtdSXt|d ksXt|d krbtdSt|dkr~tj}|d }nDyt|d d }Wn(tk rtj d |d dSX|d}d}xj|D]`\}}|d kry t j }Wn"t k rtj ddSXq|dkrLy t j }Wn"t k rHtj ddSXq|dkry t j}Wn"t k rtj ddSXq|dkry tj}Wn"t k rtj ddSXq|dkry tj}Wn"t k rtj ddSXq|dkry tj}Wqt k r.tj ddSXqW|dkrjt dkrdtj dtj ddSt j }y||d}Wn4t jk rtj d|tj ddSXxt|D] }||=qWx:yt|\} } Wntk rPYnX| || <qW||d S)NZhbrdaghashZbtreeZrecnodbmanydbmgdbmrrbzUnable to open %s )z-hz--hashzbsddb module unavailable. )z-bz--btree)z-rz--recno)z-az--anydbmzdbm module unavailable. )z-gz--gdbmzdbm.gnu module unavailable. )z-dz--dbmzdbm.ndbm module unavailable. zbsddb module unavailable - zmust specify dbtype. czUnable to open %s. z&Check for format or version mismatch. )getopterrorr lenrstdinopenIOErrorrrbsddbZhashopenAttributeErrorZbtopenZrnopenr r r listkeyspickleloadEOFErrorclose) argsZoptsZpfileZdbfileZdbopenZoptargZdbkkeyvalrrrmain7s                           r%__main__r)rrr ImportErrorZdbm.ndbmZndbmr Zdbm.gnuZgnur r rrargvprogr r%__name__exitrrrrs6       [