Skip to content

Commit

Permalink
Merge pull request #2 from archangelic/dev
Browse files Browse the repository at this point in the history
Add new column to torrent table
  • Loading branch information
archangelic authored Oct 20, 2016
2 parents 20853d9 + 68ef99a commit 4fa5def
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
16 changes: 13 additions & 3 deletions cistern/cistern.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import datetime
import os

import click
Expand All @@ -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'))


Expand Down Expand Up @@ -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
Expand All @@ -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'))


Expand Down Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions cistern/migrations.py
Original file line number Diff line number Diff line change
@@ -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)
)
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
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',
Expand Down

0 comments on commit 4fa5def

Please sign in to comment.