The cli Module¶
Package init for the cli package.
Argument Handler¶
Module responsible for handling the command line arguments for Gramps.
- class gramps.cli.arghandler.ArgHandler(dbstate, parser, sessionmanager, errorfunc=None, gui=False)[source]¶
Bases:
objectThis class is responsible for the non GUI handling of commands. The handler is passed a parser object, sanitizes it, and can execute the actions requested working on a
DbState.- cl_action(action, options_str)[source]¶
Command-line action routine. Try to perform specified action.
- cl_export(filename, family_tree_format)[source]¶
Command-line export routine. Try to write into filename using the family_tree_format.
- cl_import(filename, family_tree_format)[source]¶
Command-line import routine. Try to import filename using the family_tree_format.
- handle_args_cli(cleanup=True)[source]¶
Depending on the given arguments, import or open data, launch session, write files, and/or perform actions.
- Param:
climan: the manager of a CLI session
- Type:
CLIManagerobject
- handle_args_gui()[source]¶
Method to handle the arguments that can be given for a GUI session.
- Returns:
the filename of the family tree that should be opened if user just passed a famtree or a filename.
no options: a family tree can be given, if so, this name is tested and returned. If a filename, it is imported in a new db and name of new db returned
an open and/or import option can have been given, if so, this is handled, and None is returned
Argument Parser¶
Module responsible for handling the command line arguments for Gramps.
- class gramps.cli.argparser.ArgParser(args)[source]¶
Bases:
objectThis class is responsible for parsing the command line arguments (if any) given to gramps, and determining if a GUI or a CLI session must be started. A filename and/or options may be specified as arguments.
The valid options are:
- -O, --open=FAMILY_TREE
Open Family Tree
- -U, --username=USERNAME
Database username
- -P, --password=PASSWORD
Database password
- -C, --create=FAMILY_TREE
Create on open if new Family Tree
- -i, --import=FILENAME
Import file
- -e, --export=FILENAME
Export file
- -r, --remove=PATTERN
Remove matching Family Tree(s)
- -f, --format=FORMAT
Specify Family Tree format
- -a, --action=ACTION
Specify action
- -p, --options=OPTIONS_STRING
Specify options
- -d, --debug=LOGGER_NAME
Enable debug logs
-l [FAMILY_TREE…] List Family Trees -L [FAMILY_TREE…] List Family Trees in Detail -t [FAMILY_TREE…] List Family Trees, tab delimited -u, –force-unlock Force unlock of Family Tree -s, –show Show config settings -c, –config=SETTINGS Set config setting(s) and start Gramps -y, –yes Don’t ask to confirm dangerous actions -q, –quiet Suppress progress indication output -v, –version Show versions -h, –help Display the help –usage Display usage information
If the filename (no options) is specified, the interactive session is launched using data from filename. In this mode (filename, no options), the rest of the arguments are 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 given anyway.
If -O or -i option is given, but no -e or -a options are given, an interactive session is launched with the
FILENAME(specified with -i).If both input (-O or -i) and processing (-e or -a) options are given, interactive session will not be launched.
When using import or export options (-i or -e), the -f option may be specified to indicate the family tree format.
Possible values for
ACTIONare: ‘report’, ‘book’ and ‘tool’.Configuration
SETTINGSmay be specified using the -c option. The settings are of the form config.setting[:value]. If used without a value, the setting is shown.If the -y option is given, the user’s acceptance of any CLI prompt is assumed. (see
cli.user.User.prompt())If the -q option is given, extra noise on sys.stderr, such as progress indicators, is suppressed.
CLI DB manager¶
Provide the management of databases from CLI. This includes opening, renaming, creating, and deleting of databases.
- class gramps.cli.clidbman.CLIDbManager(dbstate)[source]¶
Bases:
objectDatabase manager without GTK functionality, allows users to create and open databases
- ERROR(errormessage)¶
Show the error. A title for the error and an errormessage
- ICON_LOCK = 2¶
- ICON_MAP = {0: None, 1: None, 2: None, 3: None}¶
- ICON_NONE = 0¶
- ICON_OPEN = 3¶
- ICON_RECOVERY = 1¶
- IND_NAME = 0¶
- IND_PATH = 1¶
- IND_PATH_NAMEFILE = 2¶
- IND_STOCK_ID = 6¶
- IND_TVAL = 4¶
- IND_TVAL_STR = 3¶
- IND_USE_ICON_BOOL = 5¶
Returns True if the database in dirpath has an unavailable backend
- family_tree_summary(database_names=None)[source]¶
Return a list of dictionaries of the known family trees.
- get_dbdir_summary(dirpath, name)[source]¶
dirpath: full path to database name: proper name of family tree
Returns dictionary of summary item. Should include at least, if possible:
_(“Path”) _(“Family Tree”) _(“Last accessed”) _(“Database”) _(“Locked?”)
and these details:
_(“Number of people”) _(“Version”) _(“Schema version”)
- get_family_tree_path(name)[source]¶
Given a name, return None if name not existing or the path to the database if it is a known database name.
- icon_values(dirpath, active, is_open)[source]¶
If the directory path is the active path, then return values that indicate to use the icon, and which icon to use.
- import_new_db(filename, user)[source]¶
Attempt to import the provided file into a new database. A new database will only be created if an appropriate importer was found.
- Parameters:
filename – a fully-qualified path, filename, and extension to open.
user – a
cli.user.Userorgui.user.Userinstance for managing user interaction.
- Returns:
A tuple of (new_path, name) for the new database or (None, None) if no import was performed.
- print_family_tree_summaries(database_names=None)[source]¶
Prints a detailed list of the known family trees.
Gramps CLI¶
Provides the startcli function, which the main program calls for CLI execution of Gramps.
Provides also two small base classes: CLIDbLoader, CLIManager
- class gramps.cli.grampscli.CLIDbLoader(dbstate)[source]¶
Bases:
objectBase class for Db loading action inside a
DbState. Only the minimum is present needed for CLI handling- read_file(filename, username, password)[source]¶
This method takes care of changing database, and loading the data. In 3.0 we only allow reading of real databases of filetype ‘x-directory/normal’
This method should only return on success. Returning on failure makes no sense, because we cannot recover, since database has already been changed. Therefore, any errors should raise exceptions.
On success, return with the disabled signals. The post-load routine should enable signals, as well as finish up with other UI goodies.
- class gramps.cli.grampscli.CLIManager(dbstate, setloader, user)[source]¶
Bases:
objectSessionmanager for Gramps. This is in effect a reduced
ViewManagerinstance (see gui/viewmanager), suitable for CLI actions. Aim is to manage a dbstate on which to work (load, unload), and interact with the plugin session
User¶
The User class provides basic interaction with the user.
- class gramps.cli.user.User(callback=None, error=None, auto_accept=False, quiet=False, uistate=None, dbstate=None)[source]¶
Bases:
UserBaseThis class provides a means to interact with the user via CLI. It implements the interface in
gen.user.UserBase- begin_progress(title, message, steps)[source]¶
Start showing a progress indicator to the user.
- Parameters:
title (str) – the title of the progress meter
message (str) – the message associated with the progress meter
steps (int) – the total number of steps for the progress meter. a value of 0 indicates that the ending is unknown and the meter should just show activity.
- Returns:
none
- notify_db_error(error)[source]¶
Notify the user of a DB error.
- Parameters:
error (str) – the error message
- Returns:
none
These exact strings are also in gui/dialog.py – keep them in sync
- notify_db_repair(error)[source]¶
Notify the user their DB might need repair.
- Parameters:
error (str) – the error message
- Returns:
none
These exact strings are also in gui/dialog.py – keep them in sync
- notify_error(title, error='')[source]¶
Notify the user of an error.
- Parameters:
title (str) – the title of the error
error (str) – the error message
- Returns:
none
- prompt(title, message, accept_label, reject_label, parent=None, default_label=None)[source]¶
Prompt the user with a message to select an alternative.
- Parameters:
title (str) – the title of the question, e.g.: “Undo history warning”
message – the message, e.g.: “Proceeding with the tool will erase the undo history. If you think you may want to revert running this tool, please stop here and make a backup of the DB.”
accept_label (str) – what to call the positive choice, e.g.: “Proceed”
reject_label (str) – what to call the negative choice, e.g.: “Stop”
default_label (str or None) – the label of the default
- Returns:
the user’s answer to the question
- Return type:
bool