2012-09-13 15:27:34 +00:00
#!/usr/bin/env python
# This file is part of Mylar.
#
# Mylar is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mylar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mylar. If not, see <http://www.gnu.org/licenses/>.
import os , sys , locale
2015-01-25 02:26:22 +00:00
import errno
import shutil
2012-09-13 15:27:34 +00:00
import time
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
import threading
2014-10-23 08:06:38 +00:00
import signal
2012-09-13 15:27:34 +00:00
2016-08-23 06:01:41 +00:00
sys . path . insert ( 1 , os . path . join ( os . path . dirname ( __file__ ) , ' lib ' ) )
2012-09-13 15:27:34 +00:00
import mylar
2018-03-09 19:08:25 +00:00
from mylar import webstart , logger , filechecker , versioncheck , maintenance
2012-09-13 15:27:34 +00:00
2016-08-23 06:01:41 +00:00
import argparse
2014-10-23 08:06:38 +00:00
2016-01-27 08:57:27 +00:00
if ( sys . platform == ' win32 ' and sys . executable . split ( ' \\ ' ) [ - 1 ] == ' pythonw.exe ' ) :
sys . stdout = open ( os . devnull , " w " )
sys . stderr = open ( os . devnull , " w " )
2015-05-22 08:32:51 +00:00
2014-10-23 08:06:38 +00:00
def handler_sigterm ( signum , frame ) :
mylar . SIGNAL = ' shutdown '
2012-09-13 15:27:34 +00:00
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
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__ )
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
mylar . PROG_DIR = os . path . dirname ( mylar . FULL_PATH )
mylar . ARGS = sys . argv [ 1 : ]
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
# From sickbeard
mylar . SYS_ENCODING = None
try :
locale . setlocale ( locale . LC_ALL , " " )
mylar . SYS_ENCODING = locale . getpreferredencoding ( )
except ( locale . Error , IOError ) :
pass
# 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 '
2015-05-22 08:32:51 +00:00
2018-04-08 18:21:01 +00:00
if not logger . LOG_LANG . startswith ( ' en ' ) :
print ' language detected as non-English ( %s ). Forcing specific logging module - errors WILL NOT be captured in the logs ' % logger . LOG_LANG
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
else :
2018-04-08 18:21:01 +00:00
print ' log language set to %s ' % logger . LOG_LANG
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
2012-09-13 15:27:34 +00:00
# Set up and gather command line arguments
IMP:New scheduler tab (Manage / Activity) where you can see job current run status', next runtime, and prev runtimes as well as force/pause a job, FIX: Disabling
torrents will now properly hide torrent information, IMP: Specified daemon port for deluge as an on-screen tip for more detail, IMP: Added 100,200,ALL as viewable
watchlist views, FIX: When viewing pullist and annual integration enabled, if annual was present would incorrectly link to invalid annual series instead of the
actual series itself, IMP: Added more detail error messages to metatagging errors and better handling of stranded files during cleanup, IMP: Improved some handling for weekly pull-list one-off's and refactored the
nzb/oneoff post-processing into a seperate function for future callables, Moved all the main url locations for public torrent sites to the init module so that it
can be cascaded down for use in other modules instead as a global, IMP: Added a 'deep_search_32p' variable in the config.ini for specific usage with 32p, where
if there is more than one result will dig deeper into each result to try and figure out if there are series matches, as opposed to the default where it will only use ref32p
table if available or just the first hit in a multiple series search results and ignore the remainder, FIX:Fixed some unknown characters appearing in the pullist due
to unicode-related conversion problems, FIX: fixed some special cases of file parsing errors due to Volume label being named different than expected, FIX: Added a
3s pause between experimental searches to try and not hit their frequency limitation, IMP: Weekly Pullist One-off's will now show status of Snatched/Downloaded as
required, FIX: Fixed some deluge parameter problems when using auto-snatch torrent script/option, IMP: Changed the downlocation in the auto-snatch option to an
env variable instead of being passed to avoid unicode-related problems, FIX: Fixed some magnet-related issues for torrents when using a watchdir + TPSE, FIX: Added
more verbose error message for rtorrent connection issues, FIX: Could not connect to rtorrent client if no username/password were provided, IMP: Set the db updater to run
every 5 minutes on the watchlist, automatically refreshing the oldest updated series each time that is more than 5 hours old (force db update from the activity/job schedulers page will run the db updater
against the entire watchlist in sequence), IMP: Attempt to handle long paths in windows (ie. > 256c) by prepending the unicode windows api character to the import
a directory path (windows only), IMP: When manual metatagging a series, will update the series after all the metatagging has been completed as opposed to after each
issue, IMP: Will now display available inkdrops on Config/Search Providers tab when using 32P (future will utilize/indicate inkdrop threshold when downloading)
2017-09-10 15:50:08 +00:00
parser = argparse . ArgumentParser ( description = ' Automated Comic Book Downloader ' )
2018-03-09 19:08:25 +00:00
subparsers = parser . add_subparsers ( title = ' Subcommands ' , dest = ' maintenance ' )
parser_maintenance = subparsers . add_parser ( ' maintenance ' , help = ' Enter maintenance mode (no GUI). Additional commands are available (maintenance --help) ' )
2012-09-13 15:27:34 +00:00
2018-03-09 19:08:25 +00:00
#main parser
2012-09-13 15:27:34 +00:00
parser . add_argument ( ' -v ' , ' --verbose ' , action = ' store_true ' , help = ' Increase console logging verbosity ' )
parser . add_argument ( ' -q ' , ' --quiet ' , action = ' store_true ' , help = ' Turn off console logging ' )
parser . add_argument ( ' -d ' , ' --daemon ' , action = ' store_true ' , help = ' Run as a daemon ' )
parser . add_argument ( ' -p ' , ' --port ' , type = int , help = ' Force mylar to run on a specified port ' )
2015-01-25 02:26:22 +00:00
parser . add_argument ( ' -b ' , ' --backup ' , action = ' store_true ' , help = ' Will automatically backup & keep the last 2 copies of the .db & ini files prior to startup ' )
IMP: Added ALT_PULL=2 method for weeklypull management. Will now update against an external site and pull down already populated ComicID/IssueID's for the series that exist on the pullist. Alternate Search Names aren't needed with this option to match on pullist, as well as CV API Hits are also not used since it is all populated. Also allows for future viewing of pullists (up to 4 weeks in advance), FIX: Alternate search names now will be searched against when doing manual post-processing, FIX: When manually post-processing, if series volume wasn't specified would fail to match against v1 (by default), IMP:(#1309) Https_chain option now allowed within config.ini, IMP: 32P pack support on a per series basis (will search individual torrents first before packs), IMP: When pack is snatched, will mark all issues within pack that are not in a Downloaded status as Snatched within Mylar (annuals currently don't work), IMP: Removed unnecessary config spamming on startup when verbose mode was enabled, IMP: Allow for searching on 32p against series+publisher for some titles that distinguish between series by different publisher, IMP: Better series matching when trying to find series matches on 32P, FIX: When metatagging, if volume label is not provided within Mylar would default to None (now will be v1), IMP:(#1304) Attempt at better file parsing when utf-8 filenames are being parsed, FIX: Proper handling of Infinity issue number when file-checking, FIX: When adding series and annuals were enabled, if annual was a new release, would not be shown on the annual subset table for the given series (and subsequently wouldn't be auto-marked as Wanted), FIX:(#1306) Correct handling of the imported value when doing an import and moving files was selected (would previously error out during moving for some imports), FIX: When cbz files were being imported and were attempted to being auto-imported, would fail due to improper handling of the imported variable, FIX: Manage issues will now default the dropdown to the correct selected option, FIX: Manage Comics - fixed dropdown options for multiple selection of series - delete/pause/resume, IMP: Added 'delete stragglers' option to Story Arcs when deleting an arc to ensure that all traces of the arc are removed from the db, FIX: Manual/group metatagging would not tag properly if the START_YEAR_AS_VOLUME option was enabled, FIX: (#1313) NzbHydra wouldn't set the nzbid properly when using Failed Download handling/Retrying
2016-07-10 22:28:14 +00:00
parser . add_argument ( ' -w ' , ' --noweekly ' , action = ' store_true ' , help = ' Turn off weekly pull list check on startup (quicker boot sequence) ' )
2012-09-13 15:27:34 +00:00
parser . add_argument ( ' --datadir ' , help = ' Specify a directory where to store your data files ' )
parser . add_argument ( ' --config ' , help = ' Specify a config file to use ' )
parser . add_argument ( ' --nolaunch ' , action = ' store_true ' , help = ' Prevent browser from launching on startup ' )
parser . add_argument ( ' --pidfile ' , help = ' Create a pid file (only relevant when running as a daemon) ' )
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
parser . add_argument ( ' --safe ' , action = ' store_true ' , help = ' redirect the startup page to point to the Manage Comics screen on startup ' )
2018-03-09 19:08:25 +00:00
parser_maintenance . add_argument ( ' -xj ' , ' --exportjson ' , action = ' store ' , help = ' Export existing mylar.db to json file ' )
parser_maintenance . add_argument ( ' -id ' , ' --importdatabase ' , action = ' store ' , help = ' Import a mylar.db into current db ' )
parser_maintenance . add_argument ( ' -ij ' , ' --importjson ' , action = ' store ' , help = ' Import a specified json file containing just { " ComicID " : " XXXXX " } into current db ' )
parser_maintenance . add_argument ( ' -st ' , ' --importstatus ' , action = ' store_true ' , help = ' Provide current maintenance status ' )
parser_maintenance . add_argument ( ' -u ' , ' --update ' , action = ' store_true ' , help = ' force mylar to perform an update as if in GUI ' )
2018-06-09 17:57:12 +00:00
parser_maintenance . add_argument ( ' -fs ' , ' --fixslashes ' , action = ' store_true ' , help = ' remove double-slashes from within paths in db ' )
2018-03-09 19:08:25 +00:00
#parser_maintenance.add_argument('-it', '--importtext', action='store', help='Import a specified text file into current db')
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
args = parser . parse_args ( )
2018-03-09 19:08:25 +00:00
if args . maintenance :
2018-06-09 17:57:12 +00:00
if all ( [ args . exportjson is None , args . importdatabase is None , args . importjson is None , args . importstatus is False , args . update is False , args . fixslashes is False ] ) :
2018-03-09 19:08:25 +00:00
print ' Expecting subcommand with the maintenance positional argumeent '
sys . exit ( )
mylar . MAINTENANCE = True
else :
mylar . MAINTENANCE = False
2012-09-13 15:27:34 +00:00
if args . verbose :
2018-04-08 18:21:01 +00:00
print ' Verbose/Debugging mode enabled... '
mylar . LOG_LEVEL = 2
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
elif args . quiet :
FIX: included version of comictagger should now work with both Windows and *nix based OS' again, IMP: Global Copy/Move option available when performing post-processing, IMP: Added a verbose file-checking option (FOLDER_SCAN_LOG_VERBOSE) - when enabled will log as it currently does during manual post-processing/file-checking runs, when disabled it will not spam the log nearly as much resulting in more readable log files, IMP: Added Verbose debug logging both via startup option(-v), as well as toggle button in Log GUI (from headphones), as well as per-page loading of log file(s) in GUI, FIX: When doing manual post-processing on issues that were in story arcs, will now indicate X story-arc issues were post-processed for better visibility, FIX: Fixed an issue with deleting from the nzblog table when story arc issues were post-processed, IMP: Added WEEKFOLDER_LOC to the config.ini to allow for specification of where the weekly download directories will default to (as opposed to off of ComicLocation root), IMP: Better handling of some special character references in series titles when looking for series on the auto-wanted list, IMP: 32P will now auto-disable provider if logon returns invalid credentials, FIX: When using alt_pull on weekly pull list, xA0 unicode character caused error, FIX: If title had invalid character in filename that was replaced with a character that already existed in the title, would not scan in during file-checking, FIX: When searching for a series (weeklypull-list/add a series), if the title contained 'and' or '&' would return really mixed up results, FIX: When Post-Processing, if filename being processed had special characters (ie. comma) and was different than nzbname, in some cases would fail to find/move issues, IMP: Utilize internal comictagger to convert from cbr/cbz, IMP: Added more checks when post-processing to ensure files are handled correctly, IMP: Added meta-tag reading when importing series/issues - if previously tagged with CT, will reverse look-up the provided IssueID to reference the correct ComicID, IMP: If scanned directory during import contins cvinfo file, use that and force the ComicID to entire directory when importing a series, IMP: Manual meta-tagging issues will no longer create temporary directories and/or create files in the Comic Location root causing problems for some users, FIX: Annuals weren't properly sorted upon loading of comic details page for some series, IMP: Added some extra checks when validating/creating directories, FIX: Fixed a problem when displaying some covers of .cbz files on the comic details page
2016-01-26 07:49:56 +00:00
mylar . QUIET = True
2018-04-08 18:21:01 +00:00
print ' Quiet logging mode enabled... '
mylar . LOG_LEVEL = 0
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
else :
2018-04-08 18:21:01 +00:00
mylar . LOG_LEVEL = 1
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
if args . daemon :
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
if sys . platform == ' win32 ' :
print " Daemonize not supported under Windows, starting normally "
else :
2015-05-22 08:32:51 +00:00
mylar . DAEMON = True
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
2015-05-22 08:32:51 +00:00
if args . pidfile :
2014-06-04 20:31:26 +00:00
mylar . PIDFILE = str ( args . pidfile )
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
# If the pidfile already exists, mylar may still be running, so exit
if os . path . exists ( mylar . PIDFILE ) :
sys . exit ( " PID file ' " + mylar . PIDFILE + " ' already exists. Exiting. " )
# The pidfile is only useful in daemon mode, make sure we can write the file properly
if mylar . DAEMON :
2014-06-04 20:31:26 +00:00
mylar . CREATEPID = True
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
try :
file ( mylar . PIDFILE , ' w ' ) . write ( " pid \n " )
except IOError , e :
raise SystemExit ( " Unable to write PID file: %s [ %d ] " % ( e . strerror , e . errno ) )
else :
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
print ( " Not running in daemon mode. PID file creation disabled. " )
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
2012-09-13 15:27:34 +00:00
if args . datadir :
mylar . DATA_DIR = args . datadir
else :
mylar . DATA_DIR = mylar . PROG_DIR
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
if args . config :
mylar . CONFIG_FILE = args . config
else :
mylar . CONFIG_FILE = os . path . join ( mylar . DATA_DIR , ' config.ini ' )
2015-05-22 08:32:51 +00:00
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
if args . safe :
mylar . SAFESTART = True
else :
mylar . SAFESTART = False
IMP: Added ALT_PULL=2 method for weeklypull management. Will now update against an external site and pull down already populated ComicID/IssueID's for the series that exist on the pullist. Alternate Search Names aren't needed with this option to match on pullist, as well as CV API Hits are also not used since it is all populated. Also allows for future viewing of pullists (up to 4 weeks in advance), FIX: Alternate search names now will be searched against when doing manual post-processing, FIX: When manually post-processing, if series volume wasn't specified would fail to match against v1 (by default), IMP:(#1309) Https_chain option now allowed within config.ini, IMP: 32P pack support on a per series basis (will search individual torrents first before packs), IMP: When pack is snatched, will mark all issues within pack that are not in a Downloaded status as Snatched within Mylar (annuals currently don't work), IMP: Removed unnecessary config spamming on startup when verbose mode was enabled, IMP: Allow for searching on 32p against series+publisher for some titles that distinguish between series by different publisher, IMP: Better series matching when trying to find series matches on 32P, FIX: When metatagging, if volume label is not provided within Mylar would default to None (now will be v1), IMP:(#1304) Attempt at better file parsing when utf-8 filenames are being parsed, FIX: Proper handling of Infinity issue number when file-checking, FIX: When adding series and annuals were enabled, if annual was a new release, would not be shown on the annual subset table for the given series (and subsequently wouldn't be auto-marked as Wanted), FIX:(#1306) Correct handling of the imported value when doing an import and moving files was selected (would previously error out during moving for some imports), FIX: When cbz files were being imported and were attempted to being auto-imported, would fail due to improper handling of the imported variable, FIX: Manage issues will now default the dropdown to the correct selected option, FIX: Manage Comics - fixed dropdown options for multiple selection of series - delete/pause/resume, IMP: Added 'delete stragglers' option to Story Arcs when deleting an arc to ensure that all traces of the arc are removed from the db, FIX: Manual/group metatagging would not tag properly if the START_YEAR_AS_VOLUME option was enabled, FIX: (#1313) NzbHydra wouldn't set the nzbid properly when using Failed Download handling/Retrying
2016-07-10 22:28:14 +00:00
if args . noweekly :
mylar . NOWEEKLY = True
else :
mylar . NOWEEKLY = False
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
# Put the database in the DATA_DIR
mylar . DB_FILE = os . path . join ( mylar . DATA_DIR , ' mylar.db ' )
# Read config and start logging
if mylar . MAINTENANCE is False :
print ( ' Initializing startup sequence.... ' )
#try:
mylar . initialize ( mylar . CONFIG_FILE )
#except Exception as e:
# print e
# raise SystemExit('FATAL ERROR')
2018-03-09 19:08:25 +00:00
if mylar . MAINTENANCE is False :
filechecker . validateAndCreateDirectory ( mylar . DATA_DIR , True )
2013-04-22 03:43:57 +00:00
2018-03-09 19:08:25 +00:00
# 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... ' )
2015-05-22 08:32:51 +00:00
2015-01-25 02:26:22 +00:00
# backup the db and configs before they load.
if args . backup :
print ' [AUTO-BACKUP] Backing up .db and config.ini files for safety. '
backupdir = os . path . join ( mylar . DATA_DIR , ' backup ' )
try :
os . makedirs ( backupdir )
print ' [AUTO-BACKUP] Directory does not exist for backup - creating : ' + backupdir
except OSError as exception :
if exception . errno != errno . EEXIST :
print ' [AUTO-BACKUP] Directory already exists. '
raise
i = 0
while ( i < 2 ) :
if i == 0 :
ogfile = mylar . DB_FILE
back = os . path . join ( backupdir , ' mylar.db ' )
back_1 = os . path . join ( backupdir , ' mylar.db.1 ' )
else :
2018-06-06 17:51:49 +00:00
ogfile = mylar . CONFIG_FILE
2015-01-25 02:26:22 +00:00
back = os . path . join ( backupdir , ' config.ini ' )
back_1 = os . path . join ( backupdir , ' config.ini.1 ' )
try :
print ' [AUTO-BACKUP] Now Backing up mylar.db file '
if os . path . isfile ( back_1 ) :
print ' [AUTO-BACKUP] ' + back_1 + ' exists. Deleting and keeping new. '
os . remove ( back_1 )
if os . path . isfile ( back ) :
print ' [AUTO-BACKUP] Now renaming ' + back + ' to ' + back_1
shutil . move ( back , back_1 )
print ' [AUTO-BACKUP] Now copying db file to ' + back
2015-05-22 08:32:51 +00:00
shutil . copy ( ogfile , back )
2015-01-25 02:26:22 +00:00
except OSError as exception :
if exception . errno != errno . EXIST :
raise
2015-05-22 08:32:51 +00:00
i + = 1
2015-01-25 02:26:22 +00:00
IMP: Ability to now specify search provider order (regardless of torrents or nzb) within the config.ini, IMP: (#667) Changed the db module to try to accomodate db locking errors and lowering the amount of actual write transactions that were committed along with a new scheduler system, IMP: Changed sabnzbd directory to post-processing, and included subdirs for sabnzbd & nzbget ComicRN scripts, IMP: NZBGet Post-Processing ComicRN.py script (updated for use with nzbget v11.0+)added & updated in post-processing/nzbget directory (thnx ministoat), FIX: If Issue Location was None, and status was Downloaded would cause error in GUI and break series, IMP: (#689) Minimum # of seeders added (will work with KAT), IMP: (#680) Added Boxcar 2 IO Notifications, IMP: Added PushBullet Notifications, IMP: Cleaned up some notification messages so it's not so cluttered, IMP: Added Clickable series link in History tab, IMP: Added Post-Processed as a status to History tab to show manually post-processed items, IMP: Removed log level dropdown from Logs page & added 'ThreadName' as a column, IMP: Added Force Check Availability & View Future Pull-list to Upcoming sub-tabs, IMP: Added '--safe' option to startup options which will redirect directly to Manage Comics screen incase things are broken, FIX: Added proper month conversions for manual post-processing when doing comparitive issue analysis for matches, FIX: (#613) Allow for negative issue numbers in post-processing when renaming and issue padding is enabled, FIX: File Permissions on post-processing would stop post-processing if couldn't change, now will just log the error and continue, IMP: Added Scheduler (from sickbeard) to allow for threadnaming and better scheduling, IMP: Filenames in the format of ' () ' will now get scanned in, IMP: During manual post-processing will now stop looking for matches upon a successful match, IMP: A Refresh/Weeklypull series check will now just scan in issue data, instead of series info,etc, IMP: Removed some legacy GCD code that is no longer in use, IMP: Exception/traceback handling will now be logged, FIX: Unable to grab torrents from KAT due to content-encoding detection failing, IMP: Added universal date-time conversion to allow for non-english based dates to be properly compared when checking search results against publication dates, FIX: Annuals will now get proper notification (prior was leaving out the word 'annual' from notification/logs), IMP: Improved future pull-list detection and increased retension (now ~5 months), IMP: Will now mark new issues as Wanted on a Refresh Series if autowant upcoming is enabled (was reverting to a status of None previously), IMP: Cannot change status to Downloaded if current status is Skipped or Wanted, FIX: (#704) UnSkipped will now work (X in options column on comic details page), IMP: future_check will check upcoming future issues (future pull-list) that have no series data yet (ie. #1's) and auto-add them to watchlist when the data is available and auto-want accordingly, IMP: (#706) Downloading issues to local machine (via comicdetails screen) with special characters in filename now will work, IMP: improved comparison checks during weekly pull list and improved speed abit since only refreshing issue data now instead of entire series, Other Referenced issues: (#670)(#690) and some others....
2014-05-25 18:32:11 +00:00
# Rename the main thread
threading . currentThread ( ) . name = " MAIN "
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
if mylar . DAEMON :
mylar . daemonize ( )
2018-06-09 17:57:12 +00:00
if mylar . MAINTENANCE is True and any ( [ args . exportjson , args . importjson , args . update is True , args . importstatus is True , args . fixslashes is True ] ) :
2018-03-09 19:08:25 +00:00
loggermode = ' [MAINTENANCE-MODE] '
if args . importstatus : #mylar.MAINTENANCE is True:
cs = maintenance . Maintenance ( ' status ' )
cstat = cs . check_status ( )
else :
logger . info ( ' %s Initializing maintenance mode ' % loggermode )
if args . update is True :
logger . info ( ' %s Attempting to update Mylar so things can work again... ' % loggermode )
try :
mylar . shutdown ( restart = True , update = True , maintenance = True )
except Exception as e :
sys . exit ( ' %s Mylar failed to update: %s ' % ( loggermode , e ) )
elif args . importdatabase :
#for attempted db import.
maintenance_path = args . importdatabase
logger . info ( ' %s db path accepted as %s ' % ( loggermode , maintenance_path ) )
di = maintenance . Maintenance ( ' database-import ' , file = maintenance_path )
d = di . database_import ( )
elif args . importjson :
#for attempted file re-import (json format)
maintenance_path = args . importjson
logger . info ( ' %s file indicated as being in json format - path accepted as %s ' % ( loggermode , maintenance_path ) )
ij = maintenance . Maintenance ( ' json-import ' , file = maintenance_path )
j = ij . json_import ( )
#elif args.importtext:
# #for attempted file re-import (list format)
# maintenance_path = args.importtext
# logger.info('%s file indicated as being in list format - path accepted as %s' % (loggermode, maintenance_path))
# it = maintenance.Maintenance('list-import', file=maintenance_path)
# t = it.list_import()
elif args . exportjson :
#for export of db comicid's in json format
maintenance_path = args . exportjson
logger . info ( ' %s file indicated as being written to json format - destination accepted as %s ' % ( loggermode , maintenance_path ) )
ej = maintenance . Maintenance ( ' json-export ' , output = maintenance_path )
j = ej . json_export ( )
2018-06-09 17:57:12 +00:00
elif args . fixslashes :
#for running the fix slashes on the db manually
logger . info ( ' %s method indicated as fix slashes ' % loggermode )
fs = maintenance . Maintenance ( ' fixslashes ' )
j = fs . fix_slashes ( )
2018-03-09 19:08:25 +00:00
else :
logger . info ( ' %s Not a valid command: %s ' % ( loggermode , maintenance_info ) )
sys . exit ( )
logger . info ( ' %s Exiting Maintenance mode ' % ( loggermode ) )
#possible option to restart automatically after maintenance has completed...
sys . exit ( )
2012-09-13 15:27:34 +00:00
# Force the http port if neccessary
if args . port :
http_port = args . port
2017-10-25 18:33:56 +00:00
logger . info ( ' Starting Mylar on forced port: %i ' % http_port )
2012-09-13 15:27:34 +00:00
else :
2017-10-25 18:33:56 +00:00
http_port = int ( mylar . CONFIG . HTTP_PORT )
2015-05-22 08:32:51 +00:00
2015-01-25 02:26:22 +00:00
# Check if pyOpenSSL is installed. It is required for certificate generation
# and for CherryPy.
2017-10-25 18:33:56 +00:00
if mylar . CONFIG . ENABLE_HTTPS :
2015-01-25 02:26:22 +00:00
try :
import OpenSSL
except ImportError :
logger . warn ( " The pyOpenSSL module is missing. Install this " \
" module to enable HTTPS. HTTPS will be disabled. " )
2017-10-25 18:33:56 +00:00
mylar . CONFIG . ENABLE_HTTPS = False
2015-01-25 02:26:22 +00:00
# Try to start the server. Will exit here is address is already in use.
web_config = {
' http_port ' : http_port ,
2017-10-25 18:33:56 +00:00
' http_host ' : mylar . CONFIG . HTTP_HOST ,
' http_root ' : mylar . CONFIG . HTTP_ROOT ,
' enable_https ' : mylar . CONFIG . ENABLE_HTTPS ,
' https_cert ' : mylar . CONFIG . HTTPS_CERT ,
' https_key ' : mylar . CONFIG . HTTPS_KEY ,
' https_chain ' : mylar . CONFIG . HTTPS_CHAIN ,
' http_username ' : mylar . CONFIG . HTTP_USERNAME ,
' http_password ' : mylar . CONFIG . HTTP_PASSWORD ,
2018-01-15 03:28:42 +00:00
' authentication ' : mylar . CONFIG . AUTHENTICATION ,
' login_timeout ' : mylar . CONFIG . LOGIN_TIMEOUT ,
2017-10-31 16:57:26 +00:00
' opds_enable ' : mylar . CONFIG . OPDS_ENABLE ,
' opds_authentication ' : mylar . CONFIG . OPDS_AUTHENTICATION ,
' opds_username ' : mylar . CONFIG . OPDS_USERNAME ,
' opds_password ' : mylar . CONFIG . OPDS_PASSWORD ,
2015-01-25 02:26:22 +00:00
}
2015-05-22 08:32:51 +00:00
# Try to start the server.
2015-01-25 02:26:22 +00:00
webstart . initialize ( web_config )
2015-05-22 08:32:51 +00:00
2018-04-16 17:59:17 +00:00
#check for version here after web server initialized so it doesn't try to repeatidly hit github
#for version info if it's already running
versioncheck . versionload ( )
2015-05-22 08:32:51 +00:00
2017-10-25 18:33:56 +00:00
if mylar . CONFIG . LAUNCH_BROWSER and not args . nolaunch :
mylar . launch_browser ( mylar . CONFIG . HTTP_HOST , http_port , mylar . CONFIG . HTTP_ROOT )
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
# Start the background threads
mylar . start ( )
2014-10-23 08:06:38 +00:00
signal . signal ( signal . SIGTERM , handler_sigterm )
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
while True :
if not mylar . SIGNAL :
2014-06-04 20:31:26 +00:00
try :
time . sleep ( 1 )
except KeyboardInterrupt :
mylar . SIGNAL = ' shutdown '
2012-09-13 15:27:34 +00:00
else :
logger . info ( ' Received signal: ' + mylar . SIGNAL )
if mylar . SIGNAL == ' shutdown ' :
mylar . shutdown ( )
elif mylar . SIGNAL == ' restart ' :
mylar . shutdown ( restart = True )
else :
mylar . shutdown ( restart = True , update = True )
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
mylar . SIGNAL = None
2015-05-22 08:32:51 +00:00
2012-09-13 15:27:34 +00:00
return
if __name__ == " __main__ " :
main ( )