Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
pep8 and remove zdaemon confs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmeneghello committed Feb 11, 2015
1 parent c87ca7a commit bbc67c4
Show file tree
Hide file tree
Showing 35 changed files with 344 additions and 305 deletions.
8 changes: 5 additions & 3 deletions api.py
@@ -1,4 +1,5 @@
import json

import regex
import bottle
from bottle import request, response
Expand All @@ -8,9 +9,10 @@
import pynab.api
import config


app = application = bottle.Bottle()

#bottle.debug(True)
# bottle.debug(True)

@app.get('/scripts/:path#.+#')
def serve_static(path):
Expand Down Expand Up @@ -61,7 +63,7 @@ def api():
@app.get('/')
@app.get('/index.html')
def index():
if config.api.get('webui'): # disabled by default ? not really useful for a single user install
if config.api.get('webui'): # disabled by default ? not really useful for a single user install
raise bottle.static_file('index.html', root='./webui/dist')


Expand Down Expand Up @@ -118,7 +120,7 @@ def get_link(route=''):

def main():
bottle.run(app=app, host=config.api.get('api_host', '0.0.0.0'), port=config.api.get('api_port', 8080))


if __name__ == '__main__':
log_init('api')
Expand Down
14 changes: 7 additions & 7 deletions config_sample.py
Expand Up @@ -55,7 +55,7 @@
# result_default: default number if none is specified
# make sure there's no quotes around it
'result_default': 20,

# api_host: ip or hostname to bind the api
# usually '0.0.0.0'
'api_host': '0.0.0.0',
Expand Down Expand Up @@ -161,7 +161,7 @@
# since they'll take forever to index and possibly choke the server
# this is the upper limit
# 'max_process_size': 30*1024*1024*1024, # 30gb
'max_process_size': 10*1024*1024*1024,
'max_process_size': 10 * 1024 * 1024 * 1024,

# max_process_anyway: try to process huge releases anyway
# you can attempt to index massive releases anyway
Expand All @@ -174,7 +174,7 @@
# anything smaller than this in a group will be deleted
# layout is minimum size and then a list of groups to check, ie.
# 'min_size': {
# 104857600: ['alt.binaries.hdtv', 'alt.binaries.hdtv.x264'],
# 104857600: ['alt.binaries.hdtv', 'alt.binaries.hdtv.x264'],
# 314572800: ['alt.binaries.mooveee']
# },
'min_size': {},
Expand Down Expand Up @@ -258,12 +258,12 @@
# process requests: query the pre table to
# try and discover names from request ids
'process_requests': True,

# fetch_blacklist_duration: the number of days between tvrage/imdb API attempts
# so if we can't find a match for some movie, wait 7 days before trying that movie again
# there's really no benefit to setting this low - anywhere from a week to several months is fine
'fetch_blacklist_duration': 7,

# regex update settings
# ---------------------

Expand Down Expand Up @@ -292,8 +292,8 @@

# max_log_size: maximum size of logfiles before they get rotated
# number, in bytes (this is 50mb)
'max_log_size': 50*1024*1024,
'max_log_size': 50 * 1024 * 1024,

# enable/disable color logging to console
'colors': True,
}
Expand Down
8 changes: 5 additions & 3 deletions install.py
Expand Up @@ -8,7 +8,8 @@
print('-----------------')
print()
print('Please ensure that you have copied and renamed config_sample.py to config.py before proceeding.')
print('You need to put in your details, too. If you are migrating from Newznab, check out scripts/convert_from_newznab.py first.')
print(
'You need to put in your details, too. If you are migrating from Newznab, check out scripts/convert_from_newznab.py first.')
print()
print('This script is destructive. Ensure that the database credentials and settings are correct.')
print('The supplied database really should be empty, but it\'ll just drop anything it wants to overwrite.')
Expand All @@ -31,6 +32,7 @@

from alembic.config import Config
from alembic import command

alembic_cfg = Config("alembic.ini")
command.stamp(alembic_cfg, "head")

Expand Down Expand Up @@ -64,7 +66,7 @@
print('Copying TV data into db...')
with open('db/initial/tvshows.json', encoding='utf-8', errors='ignore') as f:
data = json.load(f)
chunks = [data[x:x+500] for x in range(0, len(data), 500)]
chunks = [data[x:x + 500] for x in range(0, len(data), 500)]
try:
for chunk in chunks:
engine.execute(TvShow.__table__.insert(), chunk)
Expand All @@ -75,7 +77,7 @@
print('Copying movie data into db...')
with open('db/initial/movies.json', encoding='utf-8', errors='ignore') as f:
data = json.load(f)
chunks = [data[x:x+500] for x in range(0, len(data), 500)]
chunks = [data[x:x + 500] for x in range(0, len(data), 500)]
try:
for chunk in chunks:
engine.execute(Movie.__table__.insert(), chunk)
Expand Down
12 changes: 6 additions & 6 deletions postprocess.py
Expand Up @@ -3,11 +3,10 @@
import traceback
import datetime

import psycopg2.extensions
import pytz

from pynab import log, log_init
from pynab.db import db_session, Release, engine, Blacklist, Group, MetaBlack, NZB, NFO, SFV
from pynab.db import db_session, Release, Blacklist, Group, MetaBlack, NZB, NFO, SFV
import pynab.groups
import pynab.binaries
import pynab.releases
Expand Down Expand Up @@ -136,7 +135,7 @@ def main():
field = 'search_name' if blacklist.field == 'subject' else blacklist.field

# filter by:
# group_name should match the blacklist's
# group_name should match the blacklist's
# <field> should match the blacklist's regex
# <field> is determined by blacklist's field (usually subject/name)
# date (optimisation)
Expand Down Expand Up @@ -181,15 +180,15 @@ def main():

# delete any orphan nzbs
log.info('postprocess: deleting orphan nzbs...')
db.query(NZB.id).filter(NZB.release==None).delete(synchronize_session='fetch')
db.query(NZB.id).filter(NZB.release == None).delete(synchronize_session='fetch')

# delete any orphan nfos
log.info('postprocess: deleting orphan nfos...')
db.query(NFO.id).filter(NFO.release==None).delete(synchronize_session='fetch')
db.query(NFO.id).filter(NFO.release == None).delete(synchronize_session='fetch')

# delete any orphan sfvs
log.info('postprocess: deleting orphan sfvs...')
db.query(SFV.id).filter(SFV.release==None).delete(synchronize_session='fetch')
db.query(SFV.id).filter(SFV.release == None).delete(synchronize_session='fetch')

db.commit()

Expand All @@ -209,5 +208,6 @@ def main():
log.info('sleeping for {:d} seconds...'.format(postprocess_wait))
time.sleep(postprocess_wait)


if __name__ == '__main__':
main()
14 changes: 9 additions & 5 deletions prebot.py
Expand Up @@ -14,24 +14,27 @@
# Thanks to Joel Rosdahl <joel@rosdahl.net> for this script
# Taken from https://bitbucket.org/jaraco/irc/src

import irc.bot
import irc.strings
import string
import random
import pynab.pre

import irc.bot
import irc.strings
from docopt import docopt

import pynab.pre
from pynab import log_init, log


class TestBot(irc.bot.SingleServerIRCBot):
def __init__(self, channel, nickname, server, port=6667):
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
self.channel = channel

def on_nicknameinuse(self, c, e):
c.nick(c.get_nickname() + "_")

def on_welcome(self, c, e):
c.join(self.channel)
c.join(self.channel)

def on_pubmsg(self, c, e):
a = e.arguments[0]
Expand All @@ -45,6 +48,7 @@ def main():
bot = TestBot(channel, nickname, "irc.synirc.net", 6667)
bot.start()


if __name__ == '__main__':
arguments = docopt(__doc__, version=pynab.__version__)
if arguments['start']:
Expand Down
1 change: 0 additions & 1 deletion pubsub.py
Expand Up @@ -16,7 +16,6 @@
from docopt import docopt

import pynab.xmpp

from pynab import log_init


Expand Down
29 changes: 18 additions & 11 deletions pynab.py
Expand Up @@ -12,11 +12,12 @@
"""

import config
from subprocess import Popen, call
from docopt import docopt
import os

from docopt import docopt

import config
import pynab.util
from pynab.db import db_session, User, Group

Expand All @@ -40,7 +41,8 @@ def postprocess():
if monitor == 'supervisor':
call('supervisorctl start pynab:postproc', shell=True)
elif monitor == 'windows':
Popen('start "Pynab Post-Process (close to quit)" python postprocess.py', stdout=None, stderr=None, stdin=None, shell=True)
Popen('start "Pynab Post-Process (close to quit)" python postprocess.py', stdout=None, stderr=None, stdin=None,
shell=True)


def api():
Expand All @@ -54,21 +56,24 @@ def pubsub():
if monitor == 'supervisor':
call('supervisorctl start pynab:pubsub', shell=True)
elif monitor == 'windows':
Popen('start "Pynab PubSub (close to quit)" python pubsub.py start', stdout=None, stderr=None, stdin=None, shell=True)
Popen('start "Pynab PubSub (close to quit)" python pubsub.py start', stdout=None, stderr=None, stdin=None,
shell=True)


def prebot():
if monitor == 'supervisor':
call('supervisorctl start pynab:prebot', shell=True)
elif monitor == 'windows':
Popen('start "Pynab prebot (close to quit)" python prebot.py start', stdout=None, stderr=None, stdin=None, shell=True)
Popen('start "Pynab prebot (close to quit)" python prebot.py start', stdout=None, stderr=None, stdin=None,
shell=True)


def stats():
if monitor == 'supervisor':
call('supervisorctl start pynab:stats', shell=True)
elif monitor == 'windows':
Popen('start "Pynab stats (close to quit)" python scripts/stats.py start', stdout=None, stderr=None, stdin=None, shell=True)
Popen('start "Pynab stats (close to quit)" python scripts/stats.py start', stdout=None, stderr=None, stdin=None,
shell=True)


def stop():
Expand All @@ -87,13 +92,14 @@ def update():

def create_user(email):
import pynab.users

key = pynab.users.create(email)
print('user created. key: {}'.format(key))


def delete_user(email):
with db_session() as db:
deleted = db.query(User).filter(User.email==email).delete()
deleted = db.query(User).filter(User.email == email).delete()
if deleted:
db.commit()
print('user deleted.')
Expand All @@ -103,7 +109,7 @@ def delete_user(email):

def enable_group(group):
with db_session() as db:
group = db.query(Group).filter(Group.name==group).first()
group = db.query(Group).filter(Group.name == group).first()
if group:
group.active = True
db.add(group)
Expand All @@ -115,7 +121,7 @@ def enable_group(group):

def disable_group(group):
with db_session() as db:
group = db.query(Group).filter(Group.name==group).first()
group = db.query(Group).filter(Group.name == group).first()
if group:
group.active = False
db.add(group)
Expand All @@ -127,7 +133,7 @@ def disable_group(group):

def reset_group(group):
with db_session() as db:
group = db.query(Group).filter(Group.name==group).first()
group = db.query(Group).filter(Group.name == group).first()
if group:
group.first = 0
group.last = 0
Expand All @@ -140,6 +146,7 @@ def reset_group(group):

def checkconfig():
from pynab import check_config

check_config()
print('Config appears ok!')

Expand Down Expand Up @@ -205,5 +212,5 @@ def update_regex():
update_regex()
elif arguments['checkconfig']:
checkconfig()

exit(0)
18 changes: 11 additions & 7 deletions pynab/__init__.py
Expand Up @@ -6,12 +6,14 @@
__version__ = '1.4.0'

import logging
import config
import logging.handlers
import os
import colorlog
import sys

import colorlog

import config


def check_config():
config = __import__('config')
Expand Down Expand Up @@ -44,7 +46,9 @@ def log_init(log_name, format='%(asctime)s %(levelname)s %(message)s'):
global log

logging_file = os.path.join(logging_dir, log_name + '.log')
handler = logging.handlers.RotatingFileHandler(logging_file, maxBytes=config.log.get('max_log_size', 50*1024*1024), backupCount=5, encoding='utf-8')
handler = logging.handlers.RotatingFileHandler(logging_file,
maxBytes=config.log.get('max_log_size', 50 * 1024 * 1024),
backupCount=5, encoding='utf-8')
handler.setFormatter(logging.Formatter(format, '%Y-%m-%d %H:%M:%S'))
log.handlers = []
log.addHandler(handler)
Expand Down Expand Up @@ -85,10 +89,10 @@ def log_init(log_name, format='%(asctime)s %(levelname)s %(message)s'):
'%Y-%m-%d %H:%M:%S',
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red',
}
)
Expand Down

0 comments on commit bbc67c4

Please sign in to comment.