Next: , Previous: at-pr, Up: Internal utils



4.8.4 The edit-pr driver

pr-edit does the background work for edit-pr, including error-checking and refiling newly edited Problem Reports, handling file and database locks and deletion of PRs. It can be called interactively, though it has no usable editing interface.

The usage for pr-edit is:

     pr-edit   [ -l username | --lock=username ] [ -u | --unlockdb ]
               [ -L | --lockdb ] [ -U | --unlockdb ] [ -c | --check ]
               [ -C | --check-initial ] [ -s | --submit [ --show-prnum ] ]
               [ -a field | --append field=field ]
               [ -r field | --replace=field ] [ --delete-pr ]
               [ -R reason | --reason=reason ]
               [ -p process-id | --process=process-id ]
               [ -d databasename | --database=databasename ]
               [ -f filename | --filename=filename ]
               [ -V | --version ]
               [ -h | --help ] [ -v username | --user=username ]
               [ -w passwd | --passwd=passwd ]
               [ -H host | --host=host ]
               [ -P port | --port=port ]
               [ -D | --debug ] [ PR number ]

A lock is placed on a Problem Report while the PR is being edited. The lock is simply a file in the locks subdirectory of the gnats-adm directory of the database, with the name gnats-id.lock, which contains the name of the user who created the lock. user then “owns” the lock, and must remove it before the PR can be locked again, even by the same user1. If a PR is already locked when you attempt to edit it, pr-edit prints an error message giving the name of the user who is currently editing the PR.

If you do not specify PR number, pr-edit reads from standard input. You must specify PR number for the functions which affect PR locks, --lock=username and --unlock.

-L
--lockdb
Locks the database specified with the --database or -d option. No PRs may be edited, created or deleted while the database is locked. This option is generally used when editing the index file.
-U
--unlockdb
Unlocks the specified database. No check is made that the invoking user actually had locked the database in the first place; hence, it is possible for anyone to steal a database lock.
-c
--check
-C
--check-initial
The --check options are used to verify that a proposed PR's field contents are valid. The PR is read in (either from stdin or a file specified with --filename), and its fields are compared against the rules specified by the database configuration of the selected database. Warnings are given for enumerated fields whose contents do not contain one of the required values or fields that do not match required regexps. --check-initial is used to verify initial PRs, rather than proposed edits of existing PRs.
-s
--submit
Used to submit a new PR to the database. The PR is read in and verified for content; if the PR is valid as an initial PR, it is then added to the database. If the submission is successful a zero exit code is returned. Otherwise, the reason(s) for the PR being rejected are printed, and a non-zero exit code is returned.
--show-prnum
This option is used with the --submit option to display the PR number associated with the submitted PR.

The following options require a PR number to be given.

--delete-pr
Deletes the specified PR from the database. The PR must be in a closed state, and not locked. Only the user gnats (or the user name specified instead of gnats during the building of gnats) is permitted to delete PRs.
-l username
--lock=username
Locks the PR. username is associated with the lock, so the system administrator can determine who actually placed the lock on the PR. However, anyone is permitted to remove locks on a PR. If the optional --process or -p option is also given, that process-id is associated with the lock.
-u
--unlock
Unlocks the specified PR.
-a field
--append=field
-r field
--replace=field
--append and --replace are used to append or replace content of a specific field within a PR. The new field content is read in from stdin (or from the file specified with the --filename option), and either appended or replaced to the specified field. The field contents are verified for correctness before the PR is rewritten. If the edit is successful, a zero exit status is returned. If the edit failed, a non-zero exit status is returned, and the reasons for the failure are printed to stdout.
-R reason
--reason=reason
Certain PR fields are configured in the database configuration to require a short text describing the reason of every change that happens to them, See dbconfig file. If you edit a problem and change any of such fields, you must issue a short text, the reason of the change, through this option. If the option is used and no change-reason requiring field is actually changed, the option has no effect.
PR number
If only a PR number is specified with no other options, a replacement PR is read in (either from stdin or the file specified with --filename). If the PR contents are valid and correct, the existing PR is replaced with the new PR contents. If the edit is successful, a zero exit status is re turned. If the edit failed, a non-zero exit status is returned, and the reasons for the failure are printed to stdout.
-d database
--database=database
Specifies the database which is to be manipulated. If no database is specified, the default database name set when gnats was built is used (usually default). This option overrides the database specified in the GNATSDB environment variable.
-f filename
--filename=filename
For actions that require reading in a PR or field content, this specifies the name of a file to read. If --filename is not specified, the PR or field content is read in from stdin.
-h
--help
Prints the usage for pr-edit.
-V
--version
Prints the version number for pr-edit.

pr-edit can edit PRs across a network, talking to a remote gnatsd. The following options relate to network access:

-H host
--host=host
Hostname of the gnats server.
-P port
--port=port
The port that the gnats server runs on.
-v username
--username=username
Username used to log into the gnats server.
-w password
--passwd=password
Password used to log into the gnats server.
-D
--debug
Used to debug network connections.

Footnotes

[1] This approach may seem heavy-handed, but it ensures that changes are not overwritten.