diff --git a/PyOpenWorm/bittorrent.py b/PyOpenWorm/bittorrent.py index 78d16b7f8..cdaca3604 100644 --- a/PyOpenWorm/bittorrent.py +++ b/PyOpenWorm/bittorrent.py @@ -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) diff --git a/PyOpenWorm/command.py b/PyOpenWorm/command.py index 5d22d68dd..d179ae5bc 100644 --- a/PyOpenWorm/command.py +++ b/PyOpenWorm/command.py @@ -1154,7 +1154,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')) diff --git a/setup.py b/setup.py index 70ab7c347..b51f475ca 100644 --- a/setup.py +++ b/setup.py @@ -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 []) diff --git a/tests/BitTorrentTest.py b/tests/BitTorrentTest.py index 03ae6b6ab..4e0b680db 100644 --- a/tests/BitTorrentTest.py +++ b/tests/BitTorrentTest.py @@ -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' \ No newline at end of file + # watch the progress with - 'watch python3 torrent_cli.py'