From 6b802be075940efc4fcf3315d38965d6ac22b396 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Tue, 18 Oct 2016 19:27:21 -0700 Subject: [PATCH 1/5] Create check to bypass default cistern folder --- cistern/cistern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cistern/cistern.py b/cistern/cistern.py index ee7e6eb..3543529 100755 --- a/cistern/cistern.py +++ b/cistern/cistern.py @@ -9,7 +9,7 @@ from tabulate import tabulate import transmissionrpc -cistern_folder = os.path.join(os.environ['HOME'], '.cistern') +cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern')) db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db')) From 69a367f5b2d61c434ed7d359c994aa753f9319a6 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Wed, 19 Oct 2016 12:21:39 -0700 Subject: [PATCH 2/5] Add migration script --- cistern/migrations.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 cistern/migrations.py diff --git a/cistern/migrations.py b/cistern/migrations.py new file mode 100644 index 0000000..633f6df --- /dev/null +++ b/cistern/migrations.py @@ -0,0 +1,13 @@ +import os + +from playhouse.migrate import * + +cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern')) +db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db')) +migrator = SqliteMigrator(db) + +date_added = DateTimeField(default=None) + +migrate( + migrator.add_column('torrent', 'date_added', date_added) +) From c27a1fc4c0251b896667e21a0a88fb44a403242f Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Wed, 19 Oct 2016 13:41:43 -0700 Subject: [PATCH 3/5] Move migration to a function --- cistern/migrations.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cistern/migrations.py b/cistern/migrations.py index 633f6df..7f32ed3 100644 --- a/cistern/migrations.py +++ b/cistern/migrations.py @@ -1,13 +1,15 @@ +import datetime import os from playhouse.migrate import * -cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern')) -db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db')) -migrator = SqliteMigrator(db) +def update(): + cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern')) + db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db')) + migrator = SqliteMigrator(db) -date_added = DateTimeField(default=None) + date_added = DateTimeField(default=datetime.datetime.now) -migrate( - migrator.add_column('torrent', 'date_added', date_added) -) + migrate( + migrator.add_column('torrent', 'date_added', date_added) + ) From 7f82f7ae55e0e1c448f1bfb338615b4609f45883 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Wed, 19 Oct 2016 13:46:26 -0700 Subject: [PATCH 4/5] Add date_added column to torrent --- cistern/cistern.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cistern/cistern.py b/cistern/cistern.py index 3543529..e418fb0 100755 --- a/cistern/cistern.py +++ b/cistern/cistern.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import datetime import os import click @@ -9,6 +10,8 @@ from tabulate import tabulate import transmissionrpc +import migrations + cistern_folder = os.getenv('CISTERNHOME', os.path.join(os.environ['HOME'], '.cistern')) db = SqliteDatabase(os.path.join(cistern_folder, 'cistern.db')) @@ -38,6 +41,7 @@ class Torrent(Model): url = CharField(unique=True) feed = ForeignKeyField(Feed, related_name='torrents') downloaded = BooleanField(default=False) + date_added = DateTimeField(default=datetime.datetime.now) class Meta: database = db @@ -56,6 +60,12 @@ def set_downloaded(self): elif os.path.isfile(os.path.join(cistern_folder, 'cistern.db')): db.connect() +# Check if migration is necessary +try: + t = Torrent.select().first() +except OperationalError: + migrations.update() + config = ConfigObj(os.path.join(cistern_folder, 'config')) @@ -210,10 +220,10 @@ def lister(list_type): downloaded = 'Yes' else: downloaded = 'No' - torrent_list.append([torrent.id, torrent.name, torrent.feed.name, downloaded]) + torrent_list.append([torrent.id, torrent.name, torrent.feed.name, downloaded, torrent.date_added]) tab = tabulate( torrent_list, - ['ID', 'Name', 'Feed', 'Downloaded'] + ['ID', 'Name', 'Feed', 'Downloaded', 'Date Added'] ) click.echo(tab) else: From 68ef99afe3afe871e7f5471cbc18452f66c12be0 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Wed, 19 Oct 2016 18:15:43 -0700 Subject: [PATCH 5/5] Add check for Python 3 and increment version --- setup.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index dfce75b..a10850d 100755 --- a/setup.py +++ b/setup.py @@ -1,16 +1,20 @@ #!/usr/bin/env python3 from setuptools import setup +import sys + +if not sys.version_info[0] == 3: + sys.exit("Sorry, Cistern only supports Python 3.") setup( name="cistern", - version="0.1.3", + version="0.1.4", license="MIT", url="https://github.com/archangelic/cistern", description="Command line tool for downloading torrents from RSS feeds.", author="Michael Hancock", author_email="michaelhancock89@gmail.com", download_url=( - "https://github.com/archangelic/cistern/archive/v0.1.3.tar.gz" + "https://github.com/archangelic/cistern/archive/v0.1.4.tar.gz" ), install_requires=[ 'click',