TracRemote API¶
TracRemote¶
This package provides a mechanism to manipulate remote Trac instances similar to trac-admin.
TracRemote.connection¶
Contains a class for establishing and using connections to Trac servers.
-
class
TracRemote.connection.
Connection
(url=None, passfile=None, realm=None, debug=False)[source]¶ A representation of the connection to Trac.
Parameters: - url (
str
) – The base URL of the Trac server. - passfile (
str
, optional) – A file containing username and password. Overrides ~/.netrc. - realm (
str
, optional) – If the Trac instance uses basic or digest authentication, set this to the authentication realm. - debug (
bool
, optional) – If set toTrue
, print more information.
-
_readPassword
(passfile)[source]¶ Read the password file & return the username & password.
Parameters: passfile ( str
) – File containing Trac username and password.Returns: A tuple containing the username and password. Return type: tuple()
-
_readPasswordNetrc
(url)[source]¶ Read the Trac username and password from a .netrc file.
Parameters: url ( str
) – URL of the Trac serverReturns: A tuple containing the username and password. If there is no .netrc file, or if the Trac server is not present, returns None
.Return type: tuple()
-
attach
(pagepath, filename, description=None, replace=False)[source]¶ Attaches a file to a wiki page.
Parameters: - pagepath (
str
) – Wiki page to attach to. - filename (
str
ortuple()
) – Name of the file to attach. If a tuple is passed, the first item should be the name of the file, & the second item should be the data that the file should contain. - description (
str
, optional) – If supplied, this description will be added as a comment on the attachment. - replace (
bool
, optional) – Set this toTrue
if the file is replacing an existing file.
- pagepath (
-
attachments
(pagepath)[source]¶ Return a list of files attached to a particular page.
Parameters: pagepath ( str
) – Wiki page to attach to.Returns: A dictionary where the keys are file names and the values are sub-dictionaries that contain the size and mtime of the file. If there are no attachments, the dictionary will be empty. Return type: dict
-
detach
(pagepath, filename, save=True)[source]¶ Grab a file attached to a wiki page.
Parameters: Returns: The raw data read from the file.
Return type:
-
get
(pagepath)[source]¶ Requests a wiki page in text format.
Parameters: pagepath ( str
) – Wiki page to grab.Returns: The text of the wiki page. Note that in some cases, the text of the page may contain UTF-8 characters, so a further conversion to unicode may be warranted. The text may also contain Windows (CRLF) line endings. Return type: str
-
index
()[source]¶ Get and parse the TitleIndex page.
Returns: index – A list of all Trac wiki pages. Return type: list
-
logout
()¶ Close the connection by logging out.
- url (
TracRemote.main¶
Contains entry point for command-line scripts.
-
TracRemote.main.
dispatch
(options)[source]¶ Determine function to run, given arguments.
Parameters: options ( argparse.Namespace
) – Parsed options.Returns: Any output from the commands. Return type: str
-
TracRemote.main.
main
()[source]¶ Main entry point for the trac-remote script.
Returns: An integer suitable for passing to sys.exit()
.Return type: int
-
TracRemote.main.
main_args
(args=None)[source]¶ Parse the command-line arguments passed to
main()
.Parameters: args ( list
, optional) – Set the command-line arguments for testing purposes. Normallysys.argv
will be parsed.Returns: An object containing the parsed arguments. Return type: argparse.Namespace
-
TracRemote.main.
validate_args
(options)[source]¶ Validate the arguments to the various sub-commands.
Parameters: options ( argparse.Namespace
) – Parsed options.Returns: True
if the arguments are valid.Return type: bool
TracRemote.util¶
Utility functions and classes for internal use by the TracRemote package.
-
TracRemote.util.
CRLF
(text)[source]¶ Convert Unix line endings to CRLF, which is required by the POST data mime-types application/x-www-form-urlencoded and multipart/form-data.
Parameters: text ( str
) – Text to convert.Returns: Input text converted to CRLF line endings. Any initial blank lines are also removed. Return type: str
-
class
TracRemote.util.
SimpleAttachmentHTMLParser
[source]¶ Parse an attachment list page.
-
mtimere
¶ Regular Expression for extracting modification times.
Type: Regular Expression
-