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 to True, 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 server
Returns: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 or tuple()) – 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 to True if the file is replacing an existing file.
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
close()[source]

Close the connection by logging out.

detach(pagepath, filename, save=True)[source]

Grab a file attached to a wiki page.

Parameters:
  • pagepath (str) – Wiki page that contains attached file.
  • filename (str) – Name of the file to read. The name had better match an actual attached file!
  • save (bool, optional) – If set to False, no file will be saved, but the data will still be returned.
Returns:

The raw data read from the file.

Return type:

str

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.

set(pagepath, text, comment=None)[source]

Inputs text into the wiki input text box.

Parameters:
  • pagepath (str) – Wiki page to update.
  • text (str) – The wiki text.
  • comment (str, optional) – A comment on the change.

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. Normally sys.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
class TracRemote.util.SimpleIndexHTMLParser[source]

Parse the Trac TitleIndex page.

This parser should be capable of handling Trac 1.0-style Index pages as well as older versions.

class TracRemote.util.SimpleWikiHTMLParser(search='token')[source]

Handle simple forms in Trac documents. The form is searched for certain embedded values.

search_value

The embedded value found in the form. Initially set to None.

Type:str