Skip to content

Commit

Permalink
Updating to pass in DataSource object to directory loaders
Browse files Browse the repository at this point in the history
Issue: #439
  • Loading branch information
mwatts15 committed Aug 4, 2019
1 parent daed47c commit 20eb379
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
14 changes: 5 additions & 9 deletions PyOpenWorm/bittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,12 @@ def download_torrent(torrent_name):

class BitTorrentDataSourceDirLoader(DataSourceDirLoader):
def load(self, *data_source):
with connect('.pow/pow.conf') as conn:
ctx = Context(ident='http://openworm.org/data', conf=conn.conf).stored
for d in data_source:
datasource = ctx(DataSource)(ident=URIRef(d)).load()
for g in datasource:
x = list(g.torrent_file_name())
downloaded_torrent_name = download_torrent(x[0])
print('downloaded torrent', downloaded_torrent_name)
for d in data_source:
x = list(d.torrent_file_name())
downloaded_torrent_name = download_torrent(x[0])
print('downloaded torrent', downloaded_torrent_name)



os.system("torrent_cli.py start &")
os.system("torrent_cli.py add "+ downloaded_torrent_name)

Expand Down
3 changes: 2 additions & 1 deletion PyOpenWorm/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,8 @@ def _load_data_source_directories(self):
# loaded something before.

# XXX persist the dict
lclasses = [POWDirDataSourceDirLoader()]
lclasses = [POWDirDataSourceDirLoader(),
BitTorrentDataSourceDirLoader()]
dsd = _DSD(dict(), pth_join(self.powdir, 'data_source_data'), lclasses)
try:
dindex = open(pth_join(self.powdir, 'data_source_directories'))
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def excludes(base):
'zodb==4.1.0',
'torrent-client',
'google-api-python-client',
'google_auth_oauthlib',
'oauth2client==3.0.0',
] + (['zodbpickle==1.0'] if PY2 else [])
+ (['Sphinx<1.8.4'] if PY2 else [])
Expand Down
26 changes: 23 additions & 3 deletions tests/BitTorrentTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,35 @@
from PyOpenWorm import connect
from PyOpenWorm.datasource import DataTranslator
from PyOpenWorm.context import Context
import transaction


class TestBitTorrentDataSourceDirLoader(_DataTest):
def setUp(self):
super(TestBitTorrentDataSourceDirLoader, self).setUp()
with transaction.manager:
# Create data sources
ctx = Context(ident='http://example.org/context', conf=self.connection.conf)
ctx(LFDS)(
ident='http://example.org/lfds',
file_name='Merged_Nuclei_Stained_Worm.zip',
torrent_file_name='d9da5ce947c6f1c127dfcdc2ede63320.torrent'
)
ctx.save_context()


class TestBitTorrentDataSourceDirLoader(unittest.TestCase):
def test_torrent_download1(self):
ctx = Context(ident="http://example.org/context", conf=self.connection.conf)
self.assertFalse(os.path.exists("d9da5ce947c6f1c127dfcdc2ede63320.torrent"), False)
self.assertFalse(os.path.exists("Merged_Nuclei_Stained_Worm.zip"), False)

content = BitTorrentDataSourceDirLoader("./")
ident = 'http://openworm.org/entities/ConnectomeCSVDataSource/Mark_Arnab_3000_connections'
content_path = content.load(ident)

for m in ctx.stored(LFDS)().load():
content_path = content.load(m)

self.assertTrue(os.path.exists("d9da5ce947c6f1c127dfcdc2ede63320.torrent"), True)
self.assertTrue(os.path.exists("Merged_Nuclei_Stained_Worm.zip"), True)
# Merged_Nuclei_Stained_Worm.zip will appear but its contents take a while to download
# watch the progress with - 'watch python3 torrent_cli.py'
# watch the progress with - 'watch python3 torrent_cli.py'

0 comments on commit 20eb379

Please sign in to comment.