Wiki

Case Status Kiln
Register Log In

Wiki

 
Storing Configuration Settings…
  • RSS Feed

Last modified on 1/2/2015 2:18 PM by User.

Tags:

Storing Configuration Settings in fbSettings.py

The various Python examples and recipes in this Wiki will make use of an fbSettings.py file for storing common configuration settings such as the FogBugz URL and API Token.

Storing settings in each script (not good)

Every time you use FogBugzPy, you need to enter your FogBugz URL as well as username/password or an API Token. 

For example, in A Quick Start Guide, we showed a script called example.py:

example.py

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
#This script will print a list of all overdue cases assigned to me

from fogbugz import FogBugz
from datetime import datetime, timedelta

# Fill in the following values as appropriate to your installation
S_FOGBUGZ_URL   = 'https://example.fogbugz.com/'
S_EMAIL         = 'logon@example.com'
S_PASSWORD      = 'password'

fb = FogBugz(S_FOGBUGZ_URL)
fb.logon(S_EMAIL, S_PASSWORD)

In the above script, the FogBugz URL, email, and password are all stored within each script. If this information changes, each script file needs to be updated. It also exposes sensitive authorization information to other users and version control systems.

Storing settings in a separate file (good)

A better way is to store common settings in fbSettings.py. This allows all scripts to use a common URL and token (see documentation for getting a token) that are stored in a separate file. Instead of a single example.py file, now we have fbSettings.py as well:

fbSettings.py

1:
2:
URL     = "https://example.fogbugz.com"     #path to your FogBugz URL
TOKEN   = "abc123abc123abc123abc123abc123"  #your FogBugz XML API Token

example.py

1:
2:
3:
4:
5:
6:
7:
#This script will print a list of all overdue cases assigned to me

from fogbugz import FogBugz
from datetime import datetime, timedelta
import fbSettings

fb = FogBugz(fbSettings.URL, fbSettings.TOKEN)

In the above example.py, all you needed to do to use fbSettings.py was add import fbSettings to the top of the file. From there, you can use fbSettings.URL and fbSettings.TOKEN in your code.

Note: If you use version control, we recommend excluding fbSettings.py from version control.