* src/ArgHandler.py (parse_args): Use mime type to identify gramps

XML data.
* doc/gramps.1.in: Update man page.
* doc/gramps-manual/C/cmdline.xml: Update manual.

* src/PeopleModel.py: provide a work around for the python 2.3 bug
unicode sorting problem with locale.strcoll. For a nul termination
during sorting, strip it off after sorting. Only used for
python2.3, since this bug was fixed in python 2.4.


svn: r5019
This commit is contained in:
Alex Roitman 2005-08-04 23:54:18 +00:00
parent b6e123ed06
commit 02f7142364
4 changed files with 72 additions and 75 deletions

View File

@ -13,12 +13,16 @@
* src/po/template.po: Update for upcoming 2.0.6. * src/po/template.po: Update for upcoming 2.0.6.
* src/Report.py (parse_report_options_frame): Fallback to trivial * src/Report.py (parse_report_options_frame): Fallback to trivial
filter on filter failure. filter on filter failure.
* src/ArgHandler.py (parse_args): Use mime type to identify gramps
XML data.
* doc/gramps.1.in: Update man page.
* doc/gramps-manual/C/cmdline.xml: Update manual.
2005-08-04 Don Allingham <don@gramps-project.org> 2005-08-04 Don Allingham <don@gramps-project.org>
* src/PeopleModel.py: provide a work around for the python 2.3 bug unicode * src/PeopleModel.py: provide a work around for the python 2.3 bug
sorting problem with locale.strcoll. For a nul termination during sorting, unicode sorting problem with locale.strcoll. For a nul termination
strip it off after sorting. Only used for python2.3, since this bug was during sorting, strip it off after sorting. Only used for
fixed in python 2.4. python2.3, since this bug was fixed in python 2.4.
2005-08-03 Don Allingham <don@gramps-project.org> 2005-08-03 Don Allingham <don@gramps-project.org>
* src/NavWebPage.py: use new ProgressMeter, add ability to * src/NavWebPage.py: use new ProgressMeter, add ability to

View File

@ -70,7 +70,7 @@
<varlistentry><term>gramps-xml</term> <varlistentry><term>gramps-xml</term>
<listitem><para> &app; XML database. This format is available <listitem><para> &app; XML database. This format is available
for opening, import, and export. When not specified, it can be for opening, import, and export. When not specified, it can be
guessed if the filename represents a directory. guessed if the filename ends with .gramps
</para></listitem></varlistentry> </para></listitem></varlistentry>
<varlistentry><term>gedcom</term> <varlistentry><term>gedcom</term>
@ -82,13 +82,13 @@
<varlistentry><term>gramps-pkg</term> <varlistentry><term>gramps-pkg</term>
<listitem><para> &app; package. This format is available <listitem><para> &app; package. This format is available
for import and export. When not specified, it can be for import and export. When not specified, it can be
guessed if the filename ends with .tgz guessed if the filename ends with .gpkg
</para></listitem></varlistentry> </para></listitem></varlistentry>
<varlistentry><term>geneweb</term> <varlistentry><term>geneweb</term>
<listitem><para> GeneWen file This format is available <listitem><para> GeneWen file This format is available
for import and export. When not specified, it can be for import and export. When not specified, it can be
guessed if the filename ends with gw guessed if the filename ends with .gw
</para></listitem></varlistentry> </para></listitem></varlistentry>
<varlistentry><term>wft</term> <varlistentry><term>wft</term>
@ -134,12 +134,7 @@
<command>--format=<replaceable>format</replaceable></command> <command>--format=<replaceable>format</replaceable></command>
option, immediately following the <filename>filename</filename>. option, immediately following the <filename>filename</filename>.
If not specified, the guess will be attempted based on If not specified, the guess will be attempted based on
the <filename>filename</filename>. For gramps-xml the <filename>filename</filename>.
format, the <filename>filename</filename> is actually the
name of directory under which the gramps database resides. For
grdb and gedcom,
the <filename>filename</filename> is the name of the
corresponding file.
</para> </para>
<tip><para>Only grdb, gramps-xml, <tip><para>Only grdb, gramps-xml,
@ -163,12 +158,7 @@
<command>--format=<replaceable>format</replaceable></command> <command>--format=<replaceable>format</replaceable></command>
option, immediately following the <filename>filename</filename>. option, immediately following the <filename>filename</filename>.
If not specified, the guess will be attempted based on If not specified, the guess will be attempted based on
the <filename>filename</filename>. For gramps-xml the <filename>filename</filename>.
format, the <filename>filename</filename> is actually the
name of directory under which the gramps database resides. For
grdb, gedcom, gramps-pkg, and geneweb,
the <filename>filename</filename> is the name of the
corresponding file.
</para> </para>
<tip><para>More than one file can be imported in one command. <tip><para>More than one file can be imported in one command.
@ -195,10 +185,10 @@
option. The format can be specified with the <command>-f</command> option. The format can be specified with the <command>-f</command>
option immediately following the <filename>filename</filename>. option immediately following the <filename>filename</filename>.
If not specified, the guess will be attempted based on If not specified, the guess will be attempted based on
the <filename>filename</filename>. For gramps-xml the <filename>filename</filename>. For iso format,
and iso formats, the <filename>filename</filename> the <filename>filename</filename>
is actually the name of directory the gramps database will be written is actually the name of directory the gramps database will be written
into. For grdb, gedcom, wft, geneweb, into. For grdb, gramps-xml, gedcom, wft, geneweb,
and gramps-pkg, the <filename>filename</filename> and gramps-pkg, the <filename>filename</filename>
is the name of the resulting file. is the name of the resulting file.
</para> </para>
@ -411,8 +401,8 @@
<listitem> <listitem>
<para><command>gramps <para><command>gramps
-i<filename>file1.ged</filename> -i<filename>file1.ged</filename>
-i <filename>file2.tgz</filename> -i <filename>file2.gpkg</filename>
-i <filename>~/db3</filename> -i <filename>~/db3.gramps</filename>
-i <filename>file4.wft</filename> -i <filename>file4.wft</filename>
-a <filename>check</filename></command> -a <filename>check</filename></command>
</para> </listitem></varlistentry> </para> </listitem></varlistentry>
@ -424,10 +414,10 @@
<para><command>gramps <para><command>gramps
-i <filename>file1.ged</filename> -i <filename>file1.ged</filename>
-f <replaceable>gedcom</replaceable> -f <replaceable>gedcom</replaceable>
-i <filename>file2.tgz</filename> -i <filename>file2.gpkg</filename>
-f <replaceable>gramps-pkg</replaceable> -f <replaceable>gramps-pkg</replaceable>
-i <filename>~/db3</filename> -i <filename>~/db3.gramps</filename>
-f <replaceable>gramps</replaceable> -f <replaceable>gramps-xml</replaceable>
-i <filename>file4.wft</filename> -i <filename>file4.wft</filename>
-f <replaceable>wft</replaceable> -f <replaceable>wft</replaceable>
-a <replaceable>check</replaceable></command> -a <replaceable>check</replaceable></command>
@ -441,7 +431,7 @@
<listitem> <listitem>
<para><command>gramps <para><command>gramps
-i <filename>file1.ged</filename> -i <filename>file1.ged</filename>
-i <filename>file2.tgz</filename> -i <filename>file2.gpkg</filename>
-o <filename>~/new-package</filename> -o <filename>~/new-package</filename>
-f <replaceable>gramps-pkg</replaceable></command> -f <replaceable>gramps-pkg</replaceable></command>
</para></listitem> </para></listitem>
@ -454,7 +444,7 @@
<listitem> <listitem>
<para><command>gramps <para><command>gramps
-i <filename>file1.ged</filename> -i <filename>file1.ged</filename>
-i <filename>file2.tgz</filename> -i <filename>file2.dpkg</filename>
-o <filename>~/new-package</filename> -o <filename>~/new-package</filename>
-f <replaceable>gramps-pkg</replaceable> -f <replaceable>gramps-pkg</replaceable>
&gt;<filename>outfile</filename> &gt;<filename>outfile</filename>
@ -468,8 +458,8 @@
<listitem> <listitem>
<para><command>gramps <para><command>gramps
-i <filename>file1.ged</filename> -i <filename>file1.ged</filename>
-i <filename>file2.tgz</filename> -i <filename>file2.gpkg</filename>
-i <filename>~/db3</filename> -i <filename>~/db3.gramps</filename>
</command> </command>
</para> </listitem> </para> </listitem>
</varlistentry> </varlistentry>

View File

@ -1,4 +1,4 @@
.TH gramps 1 "@VERSION@" "May 2005" "@VERSION@" .TH gramps 1 "@VERSION@" "August 2005" "@VERSION@"
.SH NAME .SH NAME
gramps \- Genealogical Research and Analysis Management Programming System. gramps \- Genealogical Research and Analysis Management Programming System.
@ -59,8 +59,8 @@ the format of that file is guessed according to its extension.
Formats Formats
available for opening are \fBgrdb\fR (guessed if \fIFILE\fR ends with available for opening are \fBgrdb\fR (guessed if \fIFILE\fR ends with
\fB.grdb\fR), \fBgramps\-xml\fR (guessed if \fIFILE\fR is a \fB.grdb\fR), \fBgramps\-xml\fR (guessed if \fIFILE\fR ends with
directory), and \fBgedcom\fR (guessed if \fIFILE\fR ends with \fB.ged\fR). \fB.gramps\fR), and \fBgedcom\fR (guessed if \fIFILE\fR ends with \fB.ged\fR).
.br .br
Formats Formats
@ -80,10 +80,6 @@ Open \fIFILE\fR.
Only \fBgrdb\fR, \fBgramps\-xml\fR, and \fBgedcom\fR formats can be Only \fBgrdb\fR, \fBgramps\-xml\fR, and \fBgedcom\fR formats can be
opened directly. For other formats, you will need to use the import option opened directly. For other formats, you will need to use the import option
which will set up the empty database and then import data into it. which will set up the empty database and then import data into it.
For \fBgramps\-xml\fR format, the \fIFILE\fR
is actually the name of directory under which the gramps database resides.
For \fBgrdb\fR and \fBgedcom\fR, the \fIFILE\fR is the name of
the corresponding file.
.br .br
Only a single file can be opened. If you need to combine data from several Only a single file can be opened. If you need to combine data from several
@ -91,11 +87,7 @@ sources, you will need to use the import option.
.TP .TP
.BI \-i,\-\^\-import= " FILE" .BI \-i,\-\^\-import= " FILE"
Import data from \fIFILE\fR. For \fBgramps\-xml\fR format, the \fIFILE\fR Import data from \fIFILE\fR.
is actually the name of directory under which the gramps database resides.
For \fBgrdb\fR, \fBgedcom\fR, \fBgramps\-pkg\fR, and \fBgeneweb\fR,
the \fIFILE\fR is
the name of the corresponding file.
.br .br
When more than one input file is given, each has to be preceded by \fB\-i\fR When more than one input file is given, each has to be preceded by \fB\-i\fR
@ -106,9 +98,9 @@ gramps IDs in the resulting database.
.TP .TP
.BI \-o,\-\^\-output= " FILE" .BI \-o,\-\^\-output= " FILE"
Export data into \fIFILE\fR. For \fBgramps\-xml\fR and \fBiso\fR formats, the Export data into \fIFILE\fR. For \fBiso\fR format, the \fIFILE\fR is actually
\fIFILE\fR is actually the name of directory the gramps database will be the name of directory the gramps database will be written into.
written into. For \fBgrdb\fR, \fBgedcom\fR, \fBwft\fR, \fBgramps\-pkg\fR, For \fBgrdb\fR, \fBgramps\-xml\fR, \fBgedcom\fR, \fBwft\fR, \fBgramps\-pkg\fR,
and \fBgeneweb\fR, the \fIFILE\fR is the name of the resulting file. and \fBgeneweb\fR, the \fIFILE\fR is the name of the resulting file.
.br .br
@ -205,16 +197,16 @@ of \fIstdout\fR and \fIstderr\fR to save messages and errors in files.
.SH EXAMPLES .SH EXAMPLES
.TP .TP
To import four databases (whose formats can be determined from their names) and then check the resulting database for errors, one may type: To import four databases (whose formats can be determined from their names) and then check the resulting database for errors, one may type:
\fBgramps\fR \fB\-i\fR \fIfile1.ged\fR \fB\-i\fR \fIfile2.tgz\fR \fB\-i\fR \fI~/db3\fR \fB\-i\fR \fIfile4.wft\fR \fB\-a\fR \fIcheck\fR \fBgramps\fR \fB\-i\fR \fIfile1.ged\fR \fB\-i\fR \fIfile2.tgz\fR \fB\-i\fR \fI~/db3.gramps\fR \fB\-i\fR \fIfile4.wft\fR \fB\-a\fR \fIcheck\fR
.TP .TP
To explicitly specify the formats in the above example, append filenames with appropriate \fB\-f\fR options: To explicitly specify the formats in the above example, append filenames with appropriate \fB\-f\fR options:
\fBgramps\fR \fB\-i\fR \fIfile1.ged\fR \fB\-f\fR \fIgedcom\fR \fB\-i\fR \fIfile2.tgz\fR \fB\-f\fR \fIgramps-pkg\fR \fB\-i\fR \fI~/db3\fR \fB\-f\fR \fIgramps\fR \fB\-i\fR \fIfile4.wft\fR \fB\-f\fR \fIwft\fR \fB\-a\fR \fIcheck\fR \fBgramps\fR \fB\-i\fR \fIfile1.ged\fR \fB\-f\fR \fIgedcom\fR \fB\-i\fR \fIfile2.tgz\fR \fB\-f\fR \fIgramps-pkg\fR \fB\-i\fR \fI~/db3.gramps\fR \fB\-f\fR \fIgramps-xml\fR \fB\-i\fR \fIfile4.wft\fR \fB\-f\fR \fIwft\fR \fB\-a\fR \fIcheck\fR
.TP .TP
To record the database resulting from all imports, supply \fB\-o\fR flag (use \fB\-f\fR if the filename does not allow gramps to guess the format): To record the database resulting from all imports, supply \fB\-o\fR flag (use \fB\-f\fR if the filename does not allow gramps to guess the format):
\fBgramps\fR \fB\-i\fR \fIfile1.ged\fR \fB\-i\fR \fIfile2.tgz\fR \fB\-o\fR \fI~/new-package\fR \fB\-f\fR \fIgramps-pkg\fR \fBgramps\fR \fB\-i\fR \fIfile1.ged\fR \fB\-i\fR \fIfile2.tgz\fR \fB\-o\fR \fI~/new-package\fR \fB\-f\fR \fIgramps-pkg\fR
.TP .TP
To import three databases and start interactive gramps session with the result: To import three databases and start interactive gramps session with the result:
\fBgramps\fR \fB\-i\fR \fIfile1.ged\fR \fB\-i\fR \fIfile2.tgz\fR \fB\-i\fR \fI~/db3\fR \fBgramps\fR \fB\-i\fR \fIfile1.ged\fR \fB\-i\fR \fIfile2.tgz\fR \fB\-i\fR \fI~/db3.gramps\fR
.TP .TP
Finally, to start normal interactive session type: Finally, to start normal interactive session type:
\fBgramps\fR \fBgramps\fR

View File

@ -127,7 +127,8 @@ class ArgHandler:
o,v = options[opt_ix] o,v = options[opt_ix]
if o in ( '-O', '--open'): if o in ( '-O', '--open'):
fname = v fname = v
ftype = GrampsMime.get_type(os.path.abspath(os.path.expanduser(fname))) ftype = GrampsMime.get_type(
os.path.abspath(os.path.expanduser(fname)))
if opt_ix<len(options)-1 \ if opt_ix<len(options)-1 \
and options[opt_ix+1][0] in ( '-f', '--format'): and options[opt_ix+1][0] in ( '-f', '--format'):
format = options[opt_ix+1][1] format = options[opt_ix+1][1]
@ -137,7 +138,7 @@ class ArgHandler:
continue continue
elif ftype == const.app_gedcom: elif ftype == const.app_gedcom:
format = 'gedcom' format = 'gedcom'
elif ftype == "x-directory/normal": elif ftype == const.app_gramps_xml:
format = 'gramps-xml' format = 'gramps-xml'
elif ftype == const.app_gramps: elif ftype == const.app_gramps:
format = 'grdb' format = 'grdb'
@ -148,11 +149,16 @@ class ArgHandler:
self.open = (fname,format) self.open = (fname,format)
elif o in ( '-i', '--import'): elif o in ( '-i', '--import'):
fname = v fname = v
ftype = GrampsMime.get_type(os.path.abspath(os.path.expanduser(fname))) ftype = GrampsMime.get_type(
os.path.abspath(os.path.expanduser(fname)))
if opt_ix<len(options)-1 \ if opt_ix<len(options)-1 \
and options[opt_ix+1][0] in ( '-f', '--format'): and options[opt_ix+1][0] in ( '-f', '--format'):
format = options[opt_ix+1][1] format = options[opt_ix+1][1]
if format not in ('gedcom','gramps-xml','gramps-pkg','grdb','geneweb'): if format not in ('gedcom',
'gramps-xml',
'gramps-pkg',
'grdb',
'geneweb'):
print "Invalid format: %s" % format print "Invalid format: %s" % format
print "Ignoring input file: %s" % fname print "Ignoring input file: %s" % fname
continue continue
@ -160,7 +166,7 @@ class ArgHandler:
format = 'gedcom' format = 'gedcom'
elif ftype == const.app_gramps_package: elif ftype == const.app_gramps_package:
format = 'gramps-pkg' format = 'gramps-pkg'
elif ftype == "x-directory/normal": elif ftype == const.app_gramps_xml:
format = 'gramps-xml' format = 'gramps-xml'
elif ftype == const.app_gramps: elif ftype == const.app_gramps:
format = 'grdb' format = 'grdb'
@ -176,7 +182,13 @@ class ArgHandler:
if opt_ix<len(options)-1 \ if opt_ix<len(options)-1 \
and options[opt_ix+1][0] in ( '-f', '--format'): and options[opt_ix+1][0] in ( '-f', '--format'):
outformat = options[opt_ix+1][1] outformat = options[opt_ix+1][1]
if outformat not in ('gedcom','gramps-xml','gramps-pkg','grdb','iso','wft','geneweb'): if outformat not in ('gedcom',
'gramps-xml',
'gramps-pkg',
'grdb',
'iso',
'wft',
'geneweb'):
print "Invalid format: %s" % outformat print "Invalid format: %s" % outformat
print "Ignoring output file: %s" % outfname print "Ignoring output file: %s" % outfname
continue continue
@ -188,14 +200,7 @@ class ArgHandler:
outformat = 'wft' outformat = 'wft'
elif outfname[-2:].upper() == "GW": elif outfname[-2:].upper() == "GW":
outformat = 'geneweb' outformat = 'geneweb'
elif not os.path.isfile(outfname): elif outfname[-6:].upper() == "GRAMPS":
if not os.path.isdir(outfname):
try:
os.makedirs(outfname,0700)
except:
print "Cannot create directory %s" % outfname
print "Ignoring output file: %s" % outfname
continue
outformat = 'gramps-xml' outformat = 'gramps-xml'
elif fname[-3:].upper() == "GRDB": elif fname[-3:].upper() == "GRDB":
format = 'grdb' format = 'grdb'
@ -286,7 +291,8 @@ class ArgHandler:
if not prompter.chooser(): if not prompter.chooser():
QuestionDialog.ErrorDialog( QuestionDialog.ErrorDialog(
_("New GRAMPS database was not set up"), _("New GRAMPS database was not set up"),
_('GRAMPS cannot open non-native data without setting up new GRAMPS database.')) _('GRAMPS cannot open non-native data '
'without setting up new GRAMPS database.'))
print "Cannot continue without native database. Exiting..." print "Cannot continue without native database. Exiting..."
os._exit(1) os._exit(1)
elif filetype == const.app_gramps_package: elif filetype == const.app_gramps_package:
@ -297,7 +303,9 @@ class ArgHandler:
print "Unknown file type: %s" % filetype print "Unknown file type: %s" % filetype
QuestionDialog.ErrorDialog( QuestionDialog.ErrorDialog(
_("Could not open file: %s") % filename, _("Could not open file: %s") % filename,
_('File type "%s" is unknown to GRAMPS.\n\nValid types are: GRAMPS database, GRAMPS XML, GRAMPS package, and GEDCOM.') % filetype) _('File type "%s" is unknown to GRAMPS.\n\n'
'Valid types are: GRAMPS database, GRAMPS XML, '
'GRAMPS package, and GEDCOM.') % filetype)
print "Exiting..." print "Exiting..."
os._exit(1) os._exit(1)
if success: if success:
@ -339,11 +347,13 @@ class ArgHandler:
os._exit(1) os._exit(1)
if self.imports: if self.imports:
self.parent.cl = bool(self.exports or self.actions or self.parent.cl) self.parent.cl = bool(self.exports or
self.actions or self.parent.cl)
# Create dir for imported database(s) # Create dir for imported database(s)
self.impdir_path = os.path.expanduser("~/.gramps/import" ) self.impdir_path = os.path.expanduser("~/.gramps/import" )
self.imp_db_path = os.path.expanduser("~/.gramps/import/import_db.grdb" ) self.imp_db_path = os.path.expanduser(
"~/.gramps/import/import_db.grdb" )
if not os.path.isdir(self.impdir_path): if not os.path.isdir(self.impdir_path):
try: try:
os.mkdir(self.impdir_path,0700) os.mkdir(self.impdir_path,0700)
@ -432,8 +442,7 @@ class ArgHandler:
os._exit(1) os._exit(1)
elif format == 'gramps-xml': elif format == 'gramps-xml':
try: try:
dbname = os.path.join(filename,const.xmlFile) ReadXML.importData(self.parent.db,filename,None,self.parent.cl)
ReadXML.importData(self.parent.db,dbname,None,self.parent.cl)
except: except:
print "Error importing %s" % filename print "Error importing %s" % filename
os._exit(1) os._exit(1)
@ -452,7 +461,8 @@ class ArgHandler:
try: try:
os.mkdir(tmpdir_path,0700) os.mkdir(tmpdir_path,0700)
except: except:
print "Could not create temporary directory %s" % tmpdir_path print "Could not create temporary directory %s" \
% tmpdir_path
os._exit(1) os._exit(1)
elif not os.access(tmpdir_path,os.W_OK): elif not os.access(tmpdir_path,os.W_OK):
print "Temporary directory %s is not writable" % tmpdir_path print "Temporary directory %s is not writable" % tmpdir_path
@ -510,12 +520,11 @@ class ArgHandler:
os._exit(1) os._exit(1)
elif format == 'gramps-xml': elif format == 'gramps-xml':
filename = os.path.normpath(os.path.abspath(filename)) filename = os.path.normpath(os.path.abspath(filename))
dbname = os.path.join(filename,const.xmlFile)
if filename: if filename:
try: try:
import WriteXML import WriteXML
g = WriteXML.XmlWriter(self.parent.db,None,1,1) g = WriteXML.XmlWriter(self.parent.db,None,1,1)
ret = g.write(dbname) ret = g.write(filename)
except: except:
print "Error exporting %s" % filename print "Error exporting %s" % filename
os._exit(1) os._exit(1)
@ -546,7 +555,8 @@ class ArgHandler:
elif format == 'geneweb': elif format == 'geneweb':
import WriteGeneWeb import WriteGeneWeb
try: try:
writer = WriteGeneWeb.GeneWebWriter(self.parent.db,None,1,filename) writer = WriteGeneWeb.GeneWebWriter(self.parent.db,
None,1,filename)
ret = writer.export_data() ret = writer.export_data()
except: except:
print "Error exporting %s" % filename print "Error exporting %s" % filename
@ -599,7 +609,8 @@ class ArgHandler:
options_class = item[3] options_class = item[3]
if category in (const.CATEGORY_BOOK,const.CATEGORY_CODE, if category in (const.CATEGORY_BOOK,const.CATEGORY_CODE,
const.CATEGORY_WEB): const.CATEGORY_WEB):
options_class(self.parent.db,name,category,options_str_dict) options_class(self.parent.db,name,
category,options_str_dict)
else: else:
Report.cl_report(self.parent.db,name,category, Report.cl_report(self.parent.db,name,category,
report_class,options_class,options_str_dict) report_class,options_class,options_str_dict)