API

General API for working with the Student Robotics tools.

Bill of Materials

Modules for working with bills of materials.

Routines for extracting BOMs from schematics.

class sr.tools.bom.bom.BoardBom(db, fname, name)[source]

Bases: sr.tools.bom.bom.Bom

BOM object. Groups parts with the same asset code into PartGroups. Dictionary keys are asset codes.

Parameters:
  • db – A parts DB instance.
  • fname – The schematic to load from.
  • name – The name to give the schematic.
class sr.tools.bom.bom.Bom[source]

Bases: dict

A bill of materials.

get_price()[source]

Get total price of all the items.

Returns:The total price.
Return type:decimal.Decimal
stockcheck()[source]

Check that all items in the schematic are in stock. Returns list of things that aren’t in stock.

Returns:An iterator containing pairs of STOCK_UNKNOWN, STOCK_OUT, STOCK_OK and the part.
Return type:iterator of tuples
class sr.tools.bom.bom.MultiBoardBom(db)[source]

Bases: sr.tools.bom.bom.Bom

A bill of materials with multiple boards.

Parameters:db – A parts DB instance.
add_boards(board, num)[source]

Add boards to the collection.

Parameters:
  • board (BoardCom) – The board to add.
  • num (int) – The number of times to add it.
load_boards_args(args, allow_multipliers=True)[source]

Load the BOM from board arguments, which is a list of arguments where each item is a string either starting with a ‘-’ and then a number, meaning it is a multiplier, or just a string which contains the schematic.

Parameters:
  • args – The board arguments.
  • allow_multipliers (bool) – Whether or not to allow multipliers in the board arguments.
prime_cache()[source]

Ensures that the webpage cache is filled in the quickest time possible by making many requests in parallel.

class sr.tools.bom.bom.PartGroup(part, name='', designators=[])[source]

Bases: list

A set of parts. One might call this a “BOM line”.

Parameters:
  • part – The part.
  • name (str) – The name of the group.
  • designators (list) – A list of designators
get_price()[source]

Returns the price of the group.

Returns:The price.
Return type:decimal.Decimal
order_num()[source]

Get the number of parts to order from a distributor.

For example, if we need 5002 components from a 5000 component reel, this will return 2.

Returns:The number of parts to order.
Return type:int
stockcheck()[source]

Check the distributor has enough parts in stock.

Returns:None if the result cannot be determined, True if the distributor has enough parts, otherwise False.
Return type:None or bool

Routines for grabbing a page, with caching.

sr.tools.bom.cachedfetch.grab_url_cached(url)[source]

Download a possibly cached URL.

Returns:The contents of the page.

Routines for scraping data about parts from digikey.

class sr.tools.bom.digikey.Item(partNumber)[source]

Bases: sr.tools.bom.distpart.DistItem

Represents a Digikey item.

Parameters:partNumber – The number of the part.
get_info()[source]

Return a dictionary of the info.

Superclass for distributor items.

class sr.tools.bom.distpart.DistItem(part_number)[source]

Bases: object

A distributor item.

Parameters:part_number – The part number of the item.
print_info()[source]

Print all information about the part.

exception sr.tools.bom.distpart.NonExistentPart[source]

Bases: Exception

The part does not exist.

exception sr.tools.bom.distpart.UnsupportedFormat[source]

Bases: Exception

The page returned by the distributor was of an unsupported format

Routines for scraping data about parts from Farnell.

class sr.tools.bom.farnell.Item(part_number)[source]

Bases: sr.tools.bom.distpart.DistItem

A Farnell item.

Parameters:part_number – The number of the part.
class sr.tools.bom.geda.GSchem(fname)[source]

Bases: dict

Reads in gEDA file.

Parameters:fname (str) – The filename of the schematic.
class sr.tools.bom.geda.PCB(fname)[source]

Bases: object

Read in a gEDA PCB file.

Parameters:fname (str) – The filename of the PCB file.
get_image(res)[source]

Get an image of the PCB.

Returns:The contents of the image.
get_xy()[source]

Get XY file for the PCB.

Returns:The XY file contents.
sr.tools.bom.geda.file_is_geda_pcb(f)[source]

Return true if the file is a gEDA PCB file.

Routines for scraping data about parts from Mouser.

class sr.tools.bom.mouser.Item(part_number)[source]

Bases: sr.tools.bom.distpart.DistItem

An item sold by Mouser.

Parameters:part_number – The number of the part.

Student Robotics parts database access library.

class sr.tools.bom.parts_db.Db(file)[source]

Bases: dict

A parts database.

Parameters:file (file-like) – A file-like object to read the parts DB from.
class sr.tools.bom.parts_db.Part(d)[source]

Bases: dict

Represents a part.

Parameters:d (dict) – A part dictionary from the database.
get_dist_units()[source]

Number of components per distributor unit.

get_increments()[source]

Get the increments.

get_min_order()[source]

Get the minimum order.

get_price(num)[source]

Get the unit price when buying num distributor units.

get_url()[source]

Get the URL.

stockcheck()[source]

Return how many of the product are in stock.

sr.tools.bom.parts_db.get_db()[source]

Get the parts DB that is embedded with this library.

Routines for scraping data about parts from RS.

class sr.tools.bom.rs.Item(part_number)[source]

Bases: sr.tools.bom.distpart.DistItem

An item sold by RS.

Parameters:part_number – The number of the part.

Routines for extracting information from schematics.

sr.tools.bom.schem.open_schem(fname)[source]

Open a schematics file.

Returns:The parsed schematic as an object.
Raises:ValueError – If the file is not a gschem file.
sr.tools.bom.schem.schem_type(fname)[source]

Get the type of file.

Returns:GSCHEM or UNKNOWN
class sr.tools.bom.threadpool.ThreadPool(num_threads)[source]

Bases: object

Pool of threads consuming tasks from a queue.

add_task(func, *args, **kargs)[source]

Add a task to the queue.

wait_completion()[source]

Wait for completion of all the tasks in the queue.

class sr.tools.bom.threadpool.Worker(tasks)[source]

Bases: threading.Thread

Thread executing tasks from a given tasks queue.

run()[source]

Run the worker thread.

Budget

Library for accessing the budget files.

class sr.tools.budget.AddedItem(a)[source]

Bases: object

An item that has been added to the budget.

class sr.tools.budget.BudgetConfig(root)[source]

Bases: object

A class representing a budget config.

Parameters:root (str) – The root path to the budget.
class sr.tools.budget.BudgetItem(name, fname, conf)[source]

Bases: object

A budget item.

Parameters:
  • name (str) – The name of the item.
  • fname (str) – The filename of the item.
  • conf – The configuration.
class sr.tools.budget.BudgetTree(name)[source]

Bases: object

Container for the BudgetItems and BudgetTrees below a certain point.

Parameters:name (str) – The name of the tree.
add_child(child)[source]

Add a child to the tree.

Parameters:child (BudgetTree or BudgetItem.) – The child to add.
Raises:ValueError – If the child is not a valid type.
draw(fd=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, space=' ', prefix='')[source]

Draw a text-representation of the tree.

Parameters:
  • fd – Where to print the result.
  • space – The string representing a space.
  • prefix – The prefix for each line in the tree.
path(path)[source]

Get the object at the given path relative to this one.

Returns:The object at the path.
Raises:InvalidPath – If the path is invalid.
total()[source]

Sum all children.

Returns:The total cost of all the children.
Return type:decimal.Decimal
walk()[source]

Walk through all the BudgetItems of the this tree.

Returns:An iterator over the items in the tree.
class sr.tools.budget.ChangedItem(a, b)[source]

Bases: object

An item in the budget that has been changed.

exception sr.tools.budget.InvalidPath[source]

Bases: Exception

An exception representing an invalid budget path.

exception sr.tools.budget.NoBudgetConfig[source]

Bases: Exception

An exception representing that no config file for the budget has been found.

exception sr.tools.budget.NotBudgetRepo[source]

Bases: Exception

An exception raised if the repo is not a budget.

class sr.tools.budget.RemovedItem(a)[source]

Bases: object

An item that has been removed from the budget.

class sr.tools.budget.TmpBudgetExport(root, rev)[source]

Bases: object

A class for temporarily exporting a budget.

Parameters:
  • root – The root path to the budget.
  • rev – The revision to export.
sr.tools.budget.changes_to_tree(changes)[source]

Convert a list of changes into a tree.

Parameters:changes – A list of changes in the budget.
Raises:ValueError – If the list of changes contains non-change objects.
Returns:A new budget tree.
Return type:BudgetTree
sr.tools.budget.dec_ceil(d)[source]

Get the ceiling of a decimal.

sr.tools.budget.dec_floor(d)[source]

Get the floor of a decimal.

sr.tools.budget.dict_constructor(loader, node)[source]

Constructor for libyaml to use ordered dicts instead of dicts.

sr.tools.budget.diff_trees(a, b)[source]

Get the difference betwen two budget trees.

Returns:A sorted list of changes containing either AddedItem, RemovedItem or ChangedItem objects.
Return type:list of AddedItem, RemovedItem and ChangedItem
sr.tools.budget.find_root(path=None)[source]

Find the root directory of the budget repository.

Checks that the repository is budget.git too.

Parameters:path – if provided is a path within the budget.git repository (defaults to working directory)
sr.tools.budget.load_budget(root)[source]

Load the budget from a budget root.

Parameters:root – The root path to the budget.
sr.tools.budget.load_budget_rev(root, rev)[source]

Load a specific revision of the budget.

Parameters:
  • root (str) – The root of the budget.
  • rev (str) – The revision to get.
sr.tools.budget.num_constructor(loader, node)[source]

Constructor for libyaml to translate numeric literals to Decimals.

sr.tools.budget.py_translate_to_decimals(s)[source]

Translate any literal floats in the given source into decimals.

Configuration

Configuration for the tools.

class sr.tools.config.Config[source]

Bases: dict

Configuration reader for the tools.

get_password(*args, **kw)[source]

Get the user’s password.

Return the first non-None argument. If all of the arguments are None, and the user has enabled the use of the keyring, attempts to look-up password in the keyring. If that fails, resort to prompting the user for their password.

For keyring lookups, a username is required. If the caller does not want to use the username specified by the config files for this, then the desired username can be fed in through the ‘user’ keyword argument. This argument is ignored if its value is None.

get_user(*args)[source]

Get the username.

Return the first non-None argument. If all arguments are None, get the username from the config. If the config doesn’t provide the username, prompt the user for it.

update_from_file(fname)[source]

Update the config from the given YAML file

Parameters:fname (str) – The filename of the YAML file.
Raises:IOError – If the YAML file cannot be read.

Environment

A set of utilities that provide cross-platform support for a few basic features.

sr.tools.environment.get_cache_dir(*components)[source]

Return the cache directory for a particular component of the tools.

If the environment variable SR_CACHE_DIR is set, that takes precedence as the root of the cache directory.

This function will endeavour to create the cache directory for you.

Parameters:components (str) – Used to separate out different parts of cache. Generally these are combined with the platform path separator path.
Returns:The path to the cache directory.
Return type:str
sr.tools.environment.get_config_filename()[source]

Get the filename for the configuration file.

Returns:The filename to the config.
Return type:str
sr.tools.environment.get_terminal_size()[source]

Get the size of the terminal window the user is working in.

The code for this is based on: https://gist.github.com/jtriley/1108174 .

Returns:A tuple containing the width and height as its elements respectively.
Return type:(width, height) tuple
sr.tools.environment.open_editor(filename, fallback_editor='vim')[source]

Open the user-defined text editor on a particular file name and block until it exists.

Parameters:
  • filename (str) – The file to edit.
  • fallback_editor (str) – The editor binary to fallback on if a suitable one cannot be determined.

Inventory

Modules for working with the Student Robotics inventory system.

A set of functions for dealing with asset codes in the inventory.

Asset codes are constructed from part numbers and user numbers.

sr.tools.inventory.assetcode.code_to_num(asset_code)[source]

Convert an alphanumeric asset code to a user/part number combo.

Parameters:asset_code (str) – The asset code to convert.
Returns:A tuple consisting of the user and part number.
Return type:pair of ints
sr.tools.inventory.assetcode.is_valid(asset_code)[source]

Check if an asset code is valid.

Parameters:asset_code (str) – The asset code to check.
Returns:True if valid, else False.
Return type:bool
sr.tools.inventory.assetcode.normalise(asset_code)[source]

Normalise the given asset code to one that is compatible with the inventory API. Generally this just involves removing the ‘sr’ from the front and making the result all in uppercase.

Parameters:asset_code (str) – The asset code to normalise.
Returns:A normalised part code.
Return type:str
sr.tools.inventory.assetcode.num_to_code(user_number, part_number)[source]

Convert a user/part number combo to an alphanumeric asset code.

Parameters:
  • int (part_number) – The user number.
  • int – The part number.
Returns:

An asset code string.

Return type:

str

A set of classes and functions for working with The Inventory.

exception sr.tools.inventory.inventory.InvalidFileError(path, comment)[source]

Bases: ValueError

Raised when an invalid file is found in the inventory.

Parameters:path – The path to the file, relative to the inventory. Also accessible as the path attribute of this class.
class sr.tools.inventory.inventory.Inventory(root_path)[source]

Bases: object

An inventory.

Parameters:root_path (str) – The root path to the inventory.
asset_codes

Get all the asset codes.

Returns:An iteration over the codes.
current_user_number

Get the user ID of the currently configured Git user.

Returns:The current user number.
Raises:KeyError – If the user doesn’t exist.
static get_current_git_user()[source]

Get the currently configured Git user.

Returns:A tuple containing the name and email address.
Return type:tuple
get_next_asset_code(user_number)[source]

Get the next available asset code.

Parameters:user_number (int) – The user number for the asset code.
Returns:The new asset code.
query(query_str)[source]

Run a query on the inventory.

Parameters:query_str (str) – The query to run on the inventory.
Returns:Any items found from the query.
Return type:list of Item
Raises:pyparsing.ParseError – If the query could not be parsed.
class sr.tools.inventory.inventory.Item(path, parent=None)[source]

Bases: object

An item in the inventory.

Parameters:
  • path (str) – The path to the item.
  • parent – The item parent.
class sr.tools.inventory.inventory.ItemGroup(path, parent=None)[source]

Bases: sr.tools.inventory.inventory.ItemTree

A group of items in the inventory.

Parameters:
  • path (str) – The path to the item group.
  • parent – The parent item or tree.
ignore_fnames = ('info',)
class sr.tools.inventory.inventory.ItemTree(path, parent=None)[source]

Bases: object

A tree of items in the inventory.

Parameters:
  • path (str) – The path to the tree.
  • parent – The parent item or tree.
ignore_fnames = ()
resolve(path)[source]

Resolve the given path into an object.

Parameters:path (str) – The path to resolve.
Returns:The resolved items or self.
special_fnames = {'info': "group 'info' files may only exist within directories which are themselves assets"}
walk()[source]

Walk through the item tree, yielding the children.

Returns:An iteration of children.
exception sr.tools.inventory.inventory.NotAnInventoryError(directory)[source]

Bases: OSError

Raised when an inventory object is created for a directory that is not an inventory.

Parameters:directory – The directory that is not an inventory. Also accessible as the directory attribute of this class.
sr.tools.inventory.inventory.cached_yaml_load(path)[source]

Load a pickled YAML file from cache.

Parameters:path (str) – The path to load.
Returns:The loaded YAML file, possibly from cache.
Return type:dict
sr.tools.inventory.inventory.find_top_level_dir(start_dir=None)[source]

Find the top level of the inventory repo.

Parameters:start_dir (str) – The working to start the search from. If this is None, the current working directory is used.
Returns:The top level directory or None.
Return type:str or None
sr.tools.inventory.inventory.get_inventory(directory=None)[source]

Get an Inventory object for a directory.

Parameters:directory (str) – The directory to find the inventory from. If this is left as None, the current working directory is used.
Returns:An instance of an Inventory object pointing to the inventory in the directory specified.
Return type:Inventory
Raises:OSError – If the directory is not an inventory.
sr.tools.inventory.inventory.should_ignore(path)[source]

Check if the path should be ignored. A path that is deamed ignore-worthy starts with ‘.’ or ends with ‘~’.

Parameters:path (str) – The path to check.
Returns:True if the path should be ignored, else False.
Return type:bool

Module for calculation and verifying the checksum of a number using the Luhn algorithm.

Validation can be done with is_valid() which validates that the calculated checksum is 0. A valid number can be made by calculating the check digit and appending it.

>>> is_valid('7894')
False
>>> checksum('7894')
6
>>> calc_check_digit('7894')
'9'
>>> is_valid('78949')
True

An alternative alphabet can be provided to use the Luhn mod N algorithm. The default alphabet is ‘0123456789’.

>>> is_valid('1234', alphabet='0123456789abcdef')
False
>>> checksum('1234', alphabet='0123456789abcdef')
14
sr.tools.inventory.luhn.calc_check_digit(number, alphabet='0123456789')[source]

With the provided number, calculate the extra digit that should be appended to make it pass the Luhn checksum.

Parameters:
  • number (str) – The number to calculate the check digit of.
  • alphabet (str) – The alphabet of digits.
Returns:

The check digit of the number.

Return type:

int

sr.tools.inventory.luhn.checksum(number, alphabet='0123456789')[source]

Calculate the Luhn checksum over the provided number. Valid numbers should have a checksum of 0.

Parameters:
  • number (str) – The number to calculate the checksum of.
  • alphabet (str) – The alphabet of digits.
Returns:

The checksum of the number.

Return type:

int

sr.tools.inventory.luhn.is_valid(number, alphabet='0123456789')[source]

Checks to see if the number provided passes the Luhn checksum.

Parameters:
  • number (str) – The number to validate.
  • alphabet (str) – The alphabet of digits.
Returns:

True if the number is valid.

Return type:

bool

class sr.tools.inventory.query_ast.ASTNode[source]

Bases: object

An abstract syntax tree node.

sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.And(left, right)[source]

Bases: sr.tools.inventory.query_ast.NonTerminal

An AST node representing an ‘and’.

Parameters:
  • left – The left side of the operation.
  • right – The right side of the operation.
match(inv_nodes)[source]

Check whether the inventory nodes match the operation defined in this AST node.

Returns:A list of matching nodes.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Assy(assy)[source]

Bases: sr.tools.inventory.query_ast.Terminal

An AST node representing an ‘assy’ check.

Parameters:assy (A string representation of a bool ('true', '1', etc)) – Whether or not the asset has an assembly.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Code(*codes)[source]

Bases: sr.tools.inventory.query_ast.Terminal

An AST node representing a ‘code’ check.

Parameters:codes (list of str) – A list of valid codes.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Condition(*conditions)[source]

Bases: sr.tools.inventory.query_ast.Terminal

An AST node representing a ‘condition’ check operation.

Parameters:conditions (list of strs) – A list of conditions that should be matched.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Function(func_name, node)[source]

Bases: sr.tools.inventory.query_ast.NonTerminal

An AST node representing a function.

Params str func_name:
 The name of the function.
Params node:The node to run the functions on.
match(inv_nodes)[source]

Check whether the inventory nodes match the operation defined in this AST node.

Returns:A list of matching nodes.
classmethod register(name)[source]
classmethod registered_names()[source]
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Labelled(labelled)[source]

Bases: sr.tools.inventory.query_ast.Terminal

An AST node representing a ‘labelled’ check.

Parameters:labelled (A string representation of a bool ('true', '1', etc)) – Whether or not the asset is labelled.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.NonTerminal[source]

Bases: sr.tools.inventory.query_ast.ASTNode

A non-terminal AST node.

match(inv_nodes)[source]

Check whether the inventory nodes match the operation defined in this AST node.

Returns:A list of matching nodes.
class sr.tools.inventory.query_ast.Not(node)[source]

Bases: sr.tools.inventory.query_ast.NonTerminal

An AST node representing a ‘not’ operation.

Parameters:node – The node to be not-ed.
match(inv_nodes)[source]

Check whether the inventory nodes match the operation defined in this AST node.

Returns:A list of matching nodes.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Or(left, right)[source]

Bases: sr.tools.inventory.query_ast.NonTerminal

An AST node representing an ‘or’ operation.

Parameters:
  • left – The left side of the operation.
  • right – The right side of the operation.
match(inv_nodes)[source]

Check whether the inventory nodes match the operation defined in this AST node.

Returns:A list of matching nodes.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Path(*paths)[source]

Bases: sr.tools.inventory.query_ast.Terminal

An AST node representing a ‘path’ check.

Parameters:paths (list of str) – A list of paths that are deamed valid.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Serial(*serials)[source]

Bases: sr.tools.inventory.query_ast.Terminal

An AST node representing a ‘serial’ check.

Parameters:serials (str) – A list of valid serials.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Terminal[source]

Bases: sr.tools.inventory.query_ast.ASTNode

A terminal AST node.

match(inv_nodes)[source]

Check whether the inventory nodes match the operation definied in this AST node.

Returns:A list of matching nodes.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
class sr.tools.inventory.query_ast.TriState(key, desired_val)[source]

Bases: sr.tools.inventory.query_ast.Terminal

An AST node representing a ‘tri’ check.

Parameters:
  • key (str) – The key to check.
  • desired_val (str) – One of ‘unset’, ‘true’, ‘false’.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
sexpr()[source]

Get a string symbolic expression of the node.

class sr.tools.inventory.query_ast.Type(*types)[source]

Bases: sr.tools.inventory.query_ast.Terminal

An AST node representing a ‘type’ check.

Parameters:types – A list of types that should be checked.
match_single(inv_node)[source]

Check whether the inventory node matches the operation definied in this AST node.

Returns:True or False depending on whether the node match.
sexpr()[source]

Get a string symbolic expression of the node.

sr.tools.inventory.query_parser.generate_in_expr(prop, val_type)[source]

Generate an ‘in’ expression.

sr.tools.inventory.query_parser.search_tree(query)[source]

Create a search tree for a query string.

Parameters:query (str) – The query string to generate the search tree for.
Returns:A new search tree.

Spending

Library for accessing the spending files.

exception sr.tools.spending.LedgerNotFound[source]

Bases: Exception

An exception that occurs if ‘ledger’ cannot be found.

exception sr.tools.spending.NotSpendingRepo[source]

Bases: Exception

An exception that occurs if the repo is not a spending clone.

class sr.tools.spending.Transaction(name, date, fname)[source]

Bases: object

A spending transaction.

Parameters:
  • name (str) – The name of the transaction.
  • date – The date of the transaction.
  • fname (str) – The filename of the transation.
sr.tools.spending.account_to_budget_line(account)[source]

Convert an account name to a budget line name.

Parameters:account (str) – The account to convert.
Returns:The budget line.
sr.tools.spending.budget_line_to_account(line)[source]

Convert a budget line to an account name.

Parameters:line (str) – The line to convert.
Returns:The account.
sr.tools.spending.find_root(path=None)[source]

Find the root directory of the spending repository.

Checks that the repository is spending.git too.

Parameters:path – if provided, is a path within the spending.git repository (defaults to working directory)
sr.tools.spending.group_trans_by_budget_line(trans)[source]

Group transactions by the budget line.

Parameters:trans – The transactions to group.
Returns:A dictionary mapping budget line to a list of transactions.
sr.tools.spending.load_budget_spends(root)[source]

Load budget spending data.

Parameters:root (str) – The root of the spending data.
Returns:A list of budget lines.
sr.tools.spending.load_budget_with_spending(root)[source]

Load the budget with spending data.

Parameters:root (str) – The root path of the spending data.
Returns:The budget with spending data.
Return type:budget.Budget
sr.tools.spending.load_transactions(root)[source]

Load transactions from a directory.

Parameters:root (str) – The path to the root of the spending directory.

Team Git Repositories

class sr.tools.teamgit.Repo(path, server='studentrobotics.org')[source]

Bases: object

Representing a repository on the IDE.

Parameters:
  • path (str) – The path to the repository.
  • server (str) – The server that the repository is on.
get_modtime()[source]

Get the time of the last commit.

Returns:The time as a single number.
Return type:int
class sr.tools.teamgit.Team(identifier, server='studentrobotics.org', reporoot='/var/www/html/ide/repos')[source]

Bases: object

Representing a team in the IDE.

Parameters:
  • identifier (str) – The identifier of the team.
  • server (str) – The server that the team resides in.
  • reporoot (str) – The root of the repositories on that server.
sr.tools.teamgit.list_teams(reporoot='/var/www/html/ide/repos', server='studentrobotics.org')[source]

Get a list of teams from the IDE.

Parameters:
  • reporoot (str) – The root directory for repositories.
  • server (str) – The server with the IDE.
Returns:

A list of teams.

Return type:

list of str

sr.tools.teamgit.remote_cmd(cmd, server='studentrobotics.org')[source]

Run a remote SSH command on a server.

Parameters:
  • cmd (str) – The command to run on the server.
  • server (str) – The server to run the command on.
Returns:

The stdout and stderr responses, or None for each.

Return type:

(str or None, str or None)

Trac

class sr.tools.trac.Ticket(num, proxy)[source]

Bases: object

A ticket that may have dependencies.

Parameters:
  • num (int) – The ticket number.
  • proxy – The XMLRPC proxy object.
cleanup(dry_run=False, msg='Synchronise dependency summaries with dependencies (automated edit)')[source]

Clean-up the ticket’s description.

Parameters:
  • dry_run (bool) – Whether or not to actually commit the changes.
  • msg (str) – The message to be shown in Trac.
Returns:

Whether or not a change has occurred.

Return type:

bool

refresh()[source]

Refresh with data from trac.

url
class sr.tools.trac.TracProxy(user=None, password=None, server=None, port=None, anon=False)[source]

Bases: xmlrpc.client.ServerProxy

An XML-RPC proxy for SR Trac.

Parameters:
  • user – The username. By default this is looked up in the config or the user is prompted for it.
  • password – The password to use. If left as its default value of None, it may be looked up in the keyring, or the user may be prompted for it.
  • server – The server hostname. Defaults to that found in the config.
  • port – The HTTPS port of the server. Defaults to that found in the config.
  • anon – Whether to use trac anonymously.
exception sr.tools.trac.WrongServer[source]

Bases: Exception

The RPC server specified isn’t a trac instance.