From 7228eb98bca46ed3a3296d6c4ef9d9eba03e2e54 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Sat, 29 Jan 2005 23:34:09 +0000 Subject: [PATCH] * src/ArgHandler.py: Support for opening in the command-line mode. * src/const.py.in: Add -O | --open option. svn: r3991 --- gramps2/ChangeLog | 3 ++ gramps2/src/ArgHandler.py | 85 ++++++++++++++++++++++++++++++++------- gramps2/src/const.py.in | 4 +- 3 files changed, 77 insertions(+), 15 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 6d32e1ee2..1f4dcd08a 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -3,6 +3,9 @@ Use proper response ID; (GraphVizGraphics.__init__): set up self.doc; (EmptyDoc.init): Add empty method. + * src/ArgHandler.py: Support for opening in the command-line mode. + * src/const.py.in: Add -O | --open option. + 2005-01-29 Eero Tamminen * src/plugins/StatisticsChart.py: - Added support for Don's Pie charts + color styles for it diff --git a/gramps2/src/ArgHandler.py b/gramps2/src/ArgHandler.py index 1d748b2c4..6e5637d18 100644 --- a/gramps2/src/ArgHandler.py +++ b/gramps2/src/ArgHandler.py @@ -64,27 +64,32 @@ class ArgHandler: FILE : filename to open. All following arguments will be ignored. -i, --import=FILE : filename to import. + -O, --open=FILE : filename to open. -o, --output=FILE : filename to export. -f, --format=FORMAT : format of the file preceding this option. If the filename (no flags) is specified, the interactive session is - launched using data from filename. If the filename is not a natvive (grdb) format, dialog will - be presented to set up a grdb database. + launched using data from filename. If the filename is not in a natvive + (grdb) format, dialog will be presented to set up a grdb database. + In this mode (filename, no flags), the rest of the arguments is ignored. + This is a mode suitable by default for GUI launchers, mime type handlers, + and the like If no filename or -i option is given, a new interactive session (empty - database) is launched, since no data is goven anyway. + database) is launched, since no data is given anyway. - If -i option is given, but no -o or -a options are given, and interactive - session is launched with the FILE (specified with -i). + If -O or -i option is given, but no -o or -a options are given, an + interactive session is launched with the FILE (specified with -i). - If both -i and -o or -a are given, interactive session will not be - launched. + If both input (-O or -i) and processing (-o or -a) options are given, + interactive session will not be launched. """ def __init__(self,parent,args): self.parent = parent self.args = args + self.open_gui = None self.open = None self.exports = [] self.actions = [] @@ -114,13 +119,34 @@ class ArgHandler: if leftargs: # if there were an argument without option, use it as a file to # open and return - self.open = leftargs[0] + self.open_gui = leftargs[0] print "Trying to open: %s ..." % leftargs[0] return for opt_ix in range(len(options)): o,v = options[opt_ix] - if o in ( '-i', '--import'): + if o in ( '-O', '--open'): + fname = v + ftype = GrampsMime.get_type(os.path.abspath(os.path.expanduser(fname))) + if opt_ix 1: + elif len(self.args) > 1 and not self.open: print "No data was given -- will launch interactive session." print "To use in the command-line mode,", \ "supply at least one input file to process." @@ -319,7 +375,8 @@ class ArgHandler: print "Cleaning up." # remove import db after use self.parent.db.close() - os.remove(self.imp_db_path) + if self.imports: + os.remove(self.imp_db_path) print "Exiting." os._exit(0) diff --git a/gramps2/src/const.py.in b/gramps2/src/const.py.in index e69f0653f..b79120610 100644 --- a/gramps2/src/const.py.in +++ b/gramps2/src/const.py.in @@ -160,6 +160,7 @@ unknown = _("unknown") # (longName, shortName, type , default, flags, descrip , argDescrip) popt_table = [ + ("open", 'O', str, None, 0, "Open file", "FILENAME"), ("import", 'i', str, None, 0, "Import file", "FILENAME"), ("output", 'o', str, None, 0, "Write file", "FILENAME"), ("format", 'f', str, None, 0, 'Specify format', "FORMAT"), @@ -196,6 +197,7 @@ longopts = [ "disable-sound", "enable-sound", "espeaker=", + "open=", "import=", "output=", "format=", @@ -203,7 +205,7 @@ longopts = [ "options=", ] -shortopts = "i:o:f:a:p:?" +shortopts = "O:i:o:f:a:p:?" #------------------------------------------------------------------------- #