diff --git a/cistern/cistern.py b/cistern/cistern.py index ee7e6eb..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,7 +10,9 @@ from tabulate import tabulate import transmissionrpc -cistern_folder = os.path.join(os.environ['HOME'], '.cistern') +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: diff --git a/cistern/migrations.py b/cistern/migrations.py new file mode 100644 index 0000000..7f32ed3 --- /dev/null +++ b/cistern/migrations.py @@ -0,0 +1,15 @@ +import datetime +import os + +from playhouse.migrate import * + +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=datetime.datetime.now) + + migrate( + migrator.add_column('torrent', 'date_added', date_added) + ) 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',