Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a file iterator for Pidgin/Gaim
- Loading branch information
Showing
3 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import os | ||
|
||
|
||
def iterate_files(directory): | ||
for root, dirs, filenames in os.walk(directory): | ||
for filename in filenames: | ||
if _is_log_file(filename): | ||
yield os.path.join(root, filename) | ||
|
||
|
||
def _is_log_file(filename): | ||
_, extension = os.path.splitext(filename) | ||
return extension == '.html' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import unittest | ||
|
||
import mock | ||
|
||
from chat_unifier.file_iterators import pidgin | ||
|
||
|
||
class PidginFileIteratorTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.maxDiff = None | ||
|
||
def test_picks_correct_log_files(self): | ||
with mock.patch.object(os, 'walk') as mock_walk: | ||
mock_walk.return_value = [ | ||
('/logs', ('aim',), ('README.txt',)), | ||
('/logs/aim', ('LocalUser123',), ()), | ||
('/log/aim/LocalUser123', ('RemoteUser345', 'RemoteUser456'), | ||
()), | ||
('/log/aim/LocalUser123/RemoteUser345', (), | ||
('2007-02-24.020826-0500EST.html', | ||
'2007-02-25.154550-0500EST.html')), | ||
('/log/aim/LocalUser123/RemoteUser456', (), | ||
('2006-11-19.195755-0500EST.html', | ||
'2006-11-22.112333-0500EST.html')), | ||
] | ||
self.assertEqual([ | ||
'/log/aim/LocalUser123/RemoteUser345/2007-02-24.020826-0500EST.html', | ||
'/log/aim/LocalUser123/RemoteUser345/2007-02-25.154550-0500EST.html', | ||
'/log/aim/LocalUser123/RemoteUser456/2006-11-19.195755-0500EST.html', | ||
'/log/aim/LocalUser123/RemoteUser456/2006-11-22.112333-0500EST.html', | ||
], [f for f in pidgin.iterate_files('/logs')]) |