Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc committed Jun 6, 2008
1 parent dcb62c9 commit eb1c714
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 77 deletions.
147 changes: 78 additions & 69 deletions fortune.wpr
Expand Up @@ -21,7 +21,7 @@ proj.file-type = 'normal'
guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'windows': [{'name': 'VsP9AM1ogLRvgyGcPNIomhVGfK'\
'cv9m8S',
'size-state': '',
'size-state': 'maximized',
'type': 'dock',
'view': {'area': 'tall',
'current_pages': [1,
Expand Down Expand Up @@ -92,9 +92,9 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'fMatchCase': False,
'fOmitBinary': True,
'fRegexFlags': 46,
'fReplaceText': u'make_fortune_data_file',
'fReplaceText': u'fortune_file',
'fReverse': False,
'fSearchText': u'makeFortuneDataFile',
'fSearchText': u'fortune_file',
'fStartPos': 0,
'fStyle': 'text',
'fWholeWords': False,
Expand Down Expand Up @@ -362,54 +362,13 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
19),
'current-loc': loc('fortune/__init__.py'),
'editor-states': {loc('fortune/__init__.py'): {'attrib-starts': [],
'first-line': 201,
'first-line': 0,
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0}},
'has-focus': False},
{'bookmarks': ([[loc('../../../../ctr3.py'),
{'attrib-starts': [('init_logging',
43)],
'first-line': 40,
'sel-line': 45,
'sel-line-start': 1273,
'selection_end': 1290,
'selection_start': 1290},
1200582943.181272],
(loc('../grizzled/grizzled/db/__init__.py'),
{'attrib-starts': [],
'first-line': 200,
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
1208198623.163512),
(loc('../grizzled/grizzled/file/__init__.py'),
{'attrib-starts': [],
'first-line': 40,
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
1208198641.055481),
(loc('../grizzled/grizzled/config.py'),
{'attrib-starts': [],
'first-line': 160,
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
1208198647.6414609),
(loc('../grizzled/grizzled/file/includer.py'),
{'attrib-starts': [],
'first-line': 80,
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
1208200808.3614011),
(loc('../grizzled/grizzled/db/__init__.py'),
{'bookmarks': ([(loc('../grizzled/grizzled/db/__init__.py'),
{'attrib-starts': [],
'first-line': 57,
'sel-line': 0,
Expand Down Expand Up @@ -464,7 +423,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'selection_end': 3419,
'selection_start': 3419},
1208295584.032558),
[loc('unknown:<untitled> #1'),
[loc('unknown:<untitled> #238'),
{'attrib-starts': [],
'first-line': 0,
'sel-line': 0,
Expand Down Expand Up @@ -531,23 +490,65 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'selection_end': 7209,
'selection_start': 7209},
1208381027.3971729),
(loc('fortune/__init__.py'),
{'attrib-starts': [],
'first-line': 0,
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
1209425546.786469),
(loc('fortune/__init__.py'),
{'attrib-starts': [],
'first-line': 0,
'sel-line': 6,
'sel-line-start': 83,
'selection_end': 85,
'selection_start': 83},
1212237382.0654449),
(loc('fortune/__init__.py'),
{'attrib-starts': [],
'first-line': 118,
'sel-line': 147,
'sel-line-start': 5424,
'selection_end': 5424,
'selection_start': 5424},
1212237386.542619),
(loc('fortune/__init__.py'),
{'attrib-starts': [('get_random_fortune',
148)],
'first-line': 118,
'sel-line': 157,
'sel-line-start': 5668,
'selection_end': 5680,
'selection_start': 5680},
1212237449.688982),
(loc('fortune/__init__.py'),
{'attrib-starts': [('make_fortune_data_file',
197)],
'first-line': 159,
'sel-line': 212,
'sel-line-start': 7120,
'selection_end': 7136,
'selection_start': 7131},
1212237464.185307),
[loc('fortune/__init__.py'),
{'attrib-starts': [('makeFortuneDataFile',
196)],
'first-line': 200,
{'attrib-starts': [('make_fortune_data_file',
197)],
'first-line': 159,
'sel-line': 212,
'sel-line-start': 7194,
'selection_end': 7209,
'selection_start': 7209},
1209425546.786469]],
'sel-line-start': 7120,
'selection_end': 7136,
'selection_start': 7131},
1212237501.3030331]],
19),
'current-loc': loc('fortune/__init__.py'),
'editor-states': {loc('fortune/__init__.py'): {'attrib-starts': [],
'first-line': 0,
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0}},
'first-line': 204,
'sel-line': 36,
'sel-line-start': 1030,
'selection_end': 1030,
'selection_start': 1030}},
'has-focus': False}),
'open_files': [u'fortune/__init__.py']},
'split_percents': {0: 0.5},
Expand All @@ -560,8 +561,8 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'user_data': {}},
'window-alloc': (0,
25,
1670,
972)},
1251,
919)},
{'name': 'nz8sdCZFY1fM2ZHHgdqsqa9sPhFohhIY',
'size-state': '',
'type': 'panel-tall',
Expand All @@ -584,7 +585,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
'user_data': {}},
'window-alloc': (259,
496,
1389,
1011,
116)}]}
guimgr.recent-documents = [loc('fortune/__init__.py')]
guimgr.visual-state = {loc('fortune/__init__.py'): {'attrib-starts': [],
Expand All @@ -593,42 +594,49 @@ guimgr.visual-state = {loc('fortune/__init__.py'): {'attrib-starts': [],
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
loc('unknown:<untitled> #7'): {'attrib-starts': [],
loc('unknown:<untitled> #237'): {'attrib-starts': [],
'first-line': 0,
'history': {},
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
loc('unknown:<untitled> #244'): {'attrib-starts': [],
'first-line': 0,
'history': {},
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
loc('unknown:<untitled> #5'): {'attrib-starts': [],
loc('unknown:<untitled> #239'): {'attrib-starts': [],
'first-line': 0,
'history': {},
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
loc('unknown:<untitled> #4'): {'attrib-starts': [],
loc('unknown:<untitled> #242'): {'attrib-starts': [],
'first-line': 0,
'history': {},
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
loc('unknown:<untitled> #2'): {'attrib-starts': [],
loc('unknown:<untitled> #241'): {'attrib-starts': [],
'first-line': 0,
'history': {},
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
loc('unknown:<untitled> #3'): {'attrib-starts': [],
loc('unknown:<untitled> #240'): {'attrib-starts': [],
'first-line': 0,
'history': {},
'sel-line': 0,
'sel-line-start': 0,
'selection_end': 0,
'selection_start': 0},
loc('unknown:<untitled> #6'): {'attrib-starts': [],
loc('unknown:<untitled> #243'): {'attrib-starts': [],
'first-line': 0,
'history': {},
'sel-line': 0,
Expand All @@ -639,5 +647,6 @@ proj.env-vars = {None: ('default',
[''])}
proj.revision-control = 1
proj.revision-control-system = u'svn'
search.search-history = [u'getRandomFortune',
search.search-history = [u'fortune_file',
u'getRandomFortune',
u'argParser']
16 changes: 8 additions & 8 deletions fortune/__init__.py
Expand Up @@ -158,11 +158,11 @@ def get_random_fortune(fortune_file):
:rtype: str
:return: the random fortune
"""
fortuneIndexFile = fortune_file + '.dat'
if not os.path.exists(fortuneIndexFile):
raise ValueError, 'Can\'t find file "%s"' % fortuneIndexFile
fortune_index_file = fortune_file + '.dat'
if not os.path.exists(fortune_index_file):
raise ValueError, 'Can\'t find file "%s"' % fortune_index_file

fortuneIndex = open(fortuneIndexFile)
fortuneIndex = open(fortune_index_file)
data = pickle.load(fortuneIndex)
fortuneIndex.close()
randomRecord = random.randint(0, len(data) - 1)
Expand Down Expand Up @@ -205,19 +205,19 @@ def make_fortune_data_file(fortune_file, quiet=False):
quiet : bool
If ``True``, don't display progress messages
"""
fortuneIndexFile = fortune_file + '.dat'
fortune_index_file = fortune_file + '.dat'
if not quiet:
print 'Updating "%s" from "%s"...' % (fortuneIndexFile, fortune_file)
print 'Updating "%s" from "%s"...' % (fortune_index_file, fortune_file)

data = []
shortest = sys.maxint
longest = 0
for start, length, fortune in _readFortunes(open(fortune_file, 'rU')):
for start, length, fortune in _read_fortunes(open(fortune_file, 'rU')):
data += [(start, length)]
shortest = min(shortest, length)
longest = max(longest, length)

fortuneIndex = open(fortuneIndexFile, 'wb')
fortuneIndex = open(fortune_index_file, 'wb')
pickle.dump(data, fortuneIndex, _PICKLE_PROTOCOL)
fortuneIndex.close()

Expand Down

0 comments on commit eb1c714

Please sign in to comment.