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

Commit

Permalink
Whitespace cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmoisey authored and evilhero committed May 27, 2015
1 parent d21cc0d commit 9a4a6b4
Show file tree
Hide file tree
Showing 37 changed files with 1,770 additions and 1,772 deletions.
55 changes: 28 additions & 27 deletions Mylar.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@
except ImportError:
import lib.argparse as argparse


def handler_sigterm(signum, frame):
mylar.SIGNAL = 'shutdown'


def main():

# Fixed paths to mylar
if hasattr(sys, 'frozen'):
mylar.FULL_PATH = os.path.abspath(sys.executable)
else:
mylar.FULL_PATH = os.path.abspath(__file__)

mylar.PROG_DIR = os.path.dirname(mylar.FULL_PATH)
mylar.ARGS = sys.argv[1:]

# From sickbeard
mylar.SYS_ENCODING = None

Expand All @@ -58,7 +60,7 @@ def main():
# for OSes that are poorly configured I'll just force UTF-8
if not mylar.SYS_ENCODING or mylar.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
mylar.SYS_ENCODING = 'UTF-8'

# Set up and gather command line arguments
parser = argparse.ArgumentParser(description='Comic Book add-on for SABnzbd+')

Expand All @@ -73,14 +75,14 @@ def main():
parser.add_argument('--pidfile', help='Create a pid file (only relevant when running as a daemon)')
parser.add_argument('--safe', action='store_true', help='redirect the startup page to point to the Manage Comics screen on startup')
#parser.add_argument('-u', '--update', action='store_true', help='force mylar to perform an update as if in GUI')

args = parser.parse_args()

if args.verbose:
mylar.VERBOSE = 2
elif args.quiet:
mylar.VERBOSE = 0

#if args.update:
# print('Attempting to update Mylar so things can work again...')
# try:
Expand All @@ -92,10 +94,10 @@ def main():
if sys.platform == 'win32':
print "Daemonize not supported under Windows, starting normally"
else:
mylar.DAEMON=True
mylar.VERBOSE=0
mylar.DAEMON = True
mylar.VERBOSE = 0

if args.pidfile :
if args.pidfile:
mylar.PIDFILE = str(args.pidfile)

# If the pidfile already exists, mylar may still be running, so exit
Expand All @@ -112,17 +114,16 @@ def main():
else:
logger.warn("Not running in daemon mode. PID file creation disabled.")


if args.datadir:
mylar.DATA_DIR = args.datadir
else:
mylar.DATA_DIR = mylar.PROG_DIR

if args.config:
mylar.CONFIG_FILE = args.config
else:
mylar.CONFIG_FILE = os.path.join(mylar.DATA_DIR, 'config.ini')

if args.safe:
mylar.SAFESTART = True
else:
Expand All @@ -136,14 +137,14 @@ def main():
# raise SystemExit('Could not create data directory: ' + mylar.DATA_DIR + '. Exiting....')

filechecker.validateAndCreateDirectory(mylar.DATA_DIR, True)

# Make sure the DATA_DIR is writeable
if not os.access(mylar.DATA_DIR, os.W_OK):
raise SystemExit('Cannot write to the data directory: ' + mylar.DATA_DIR + '. Exiting...')

# Put the database in the DATA_DIR
mylar.DB_FILE = os.path.join(mylar.DATA_DIR, 'mylar.db')

# backup the db and configs before they load.
if args.backup:
print '[AUTO-BACKUP] Backing up .db and config.ini files for safety.'
Expand Down Expand Up @@ -177,22 +178,22 @@ def main():
print '[AUTO-BACKUP] Now renaming ' + back + ' to ' + back_1
shutil.move(back, back_1)
print '[AUTO-BACKUP] Now copying db file to ' + back
shutil.copy(ogfile, back)
shutil.copy(ogfile, back)

except OSError as exception:
if exception.errno != errno.EXIST:
raise

i+=1
i += 1

mylar.CFG = ConfigObj(mylar.CONFIG_FILE, encoding='utf-8')

# Rename the main thread
threading.currentThread().name = "MAIN"

# Read config & start logging
mylar.initialize()

if mylar.DAEMON:
mylar.daemonize()

Expand All @@ -202,7 +203,7 @@ def main():
logger.info('Starting Mylar on foced port: %i' % http_port)
else:
http_port = int(mylar.HTTP_PORT)

# Check if pyOpenSSL is installed. It is required for certificate generation
# and for CherryPy.
if mylar.ENABLE_HTTPS:
Expand All @@ -225,19 +226,19 @@ def main():
'http_password': mylar.HTTP_PASSWORD,
}

# Try to start the server.
# Try to start the server.
webstart.initialize(web_config)

#logger.info('Starting Mylar on port: %i' % http_port)

if mylar.LAUNCH_BROWSER and not args.nolaunch:
mylar.launch_browser(mylar.HTTP_HOST, http_port, mylar.HTTP_ROOT)

# Start the background threads
mylar.start()

signal.signal(signal.SIGTERM, handler_sigterm)

while True:
if not mylar.SIGNAL:
try:
Expand All @@ -252,9 +253,9 @@ def main():
mylar.shutdown(restart=True)
else:
mylar.shutdown(restart=True, update=True)

mylar.SIGNAL = None

return

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion comictagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from lib.comictaggerlib.main import ctmain

if __name__ == '__main__':
ctmain()
ctmain()
34 changes: 17 additions & 17 deletions mylar/Failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def Process(self):
module = '[FAILED-DOWNLOAD]'

myDB = db.DBConnection()

if self.nzb_name and self.nzb_folder:
self._log('Failed download has been detected: ' + self.nzb_name + ' in ' + self.nzb_folder)

Expand Down Expand Up @@ -105,8 +105,8 @@ def Process(self):
if nzbiss is None:
logger.error(module + ' Unable to locate downloaded file to rename. PostProcessing aborted.')
self._log('Unable to locate downloaded file to rename. PostProcessing aborted.')
self.valreturn.append({"self.log" : self.log,
"mode" : 'stop'})
self.valreturn.append({"self.log": self.log,
"mode": 'stop'})

return self.queue.put(self.valreturn)
else:
Expand All @@ -124,9 +124,9 @@ def Process(self):
nzbiss = myDB.selectone("SELECT * from nzblog WHERE IssueID=?", [issueid]).fetchone()
if nzbiss is None:
logger.info(module + ' Cannot locate corresponding record in download history. This will be implemented soon.')
self.valreturn.append({"self.log" : self.log,
"mode" : 'stop'})
return self.queue.put(self.valreturn)
self.valreturn.append({"self.log": self.log,
"mode": 'stop'})
return self.queue.put(self.valreturn)

nzbname = nzbiss['NZBName']

Expand All @@ -145,7 +145,7 @@ def Process(self):
issuenzb = myDB.selectone("SELECT * from annuals WHERE IssueID=? AND ComicName NOT NULL", [issueid]).fetchone()
else:
issuenzb = myDB.selectone("SELECT * from issues WHERE IssueID=? AND ComicName NOT NULL", [issueid]).fetchone()

if issuenzb is not None:
logger.info(module + ' issuenzb found.')
if helpers.is_number(issueid):
Expand All @@ -165,8 +165,8 @@ def Process(self):
else:
logger.info('Failed download handling for story-arcs and one-off\'s are not supported yet. Be patient!')
self._log(' Unable to locate downloaded file to rename. PostProcessing aborted.')
self.valreturn.append({"self.log" : self.log,
"mode" : 'stop'})
self.valreturn.append({"self.log": self.log,
"mode": 'stop'})

return self.queue.put(self.valreturn)

Expand Down Expand Up @@ -208,23 +208,23 @@ def Process(self):
else:
logger.info(module + ' Stopping search here as automatic handling of failed downloads is not enabled *hint*')
self._log('Stopping search here as automatic handling of failed downloads is not enabled *hint*')
self.valreturn.append({"self.log" : self.log,
"mode" : 'stop'})
self.valreturn.append({"self.log": self.log,
"mode": 'stop'})
return self.queue.put(self.valreturn)


def failed_check(self):
#issueid = self.issueid
#comicid = self.comicid
#comicid = self.comicid

# ID = ID passed by search upon a match upon preparing to send it to client to download.
# ID is provider dependent, so the same file should be different for every provider.
module = '[FAILED_DOWNLOAD_CHECKER]'

myDB = db.DBConnection()
# Querying on NZBName alone will result in all downloads regardless of provider.
# This will make sure that the files being downloaded are different regardless of provider.
# Perhaps later improvement might be to break it down by provider so that Mylar will attempt to
# Perhaps later improvement might be to break it down by provider so that Mylar will attempt to
# download same issues on different providers (albeit it shouldn't matter, if it's broke it's broke).
logger.info('prov : ' + str(self.prov) + '[' + str(self.id) + ']')
chk_fail = myDB.selectone('SELECT * FROM failed WHERE ID=?', [self.id]).fetchone()
Expand All @@ -233,7 +233,7 @@ def failed_check(self):
return 'Good'
else:
if chk_fail['status'] == 'Good':
logger.info(module + ' result has a status of GOOD - which means it does not currently exist in the failed download list.')
logger.info(module + ' result has a status of GOOD - which means it does not currently exist in the failed download list.')
return chk_fail['status']
elif chk_fail['status'] == 'Failed':
logger.info(module + ' result has a status of FAIL which indicates it is not a good choice to download.')
Expand Down Expand Up @@ -284,4 +284,4 @@ def markFailed(self):
myDB.upsert("failed", Vals, ctrlVal)

logger.info(module + ' Successfully marked as Failed.')

Loading

0 comments on commit 9a4a6b4

Please sign in to comment.