Exemplo n.º 1
0
    def read(self, startup=False):
        self.config_vals()
        setattr(self, 'EXTRA_NEWZNABS', self.get_extra_newznabs())
        setattr(self, 'EXTRA_TORZNABS', self.get_extra_torznabs())
        if any(
            [self.CONFIG_VERSION == 0, self.CONFIG_VERSION < self.newconfig]):
            try:
                shutil.move(self._config_file,
                            os.path.join(mylar.DATA_DIR, 'config.ini.backup'))
            except:
                print('Unable to make proper backup of config file in %s' %
                      os.path.join(mylar.DATA_DIR, 'config.ini.backup'))
            if self.newconfig == 8:
                print('Attempting to update configuration..')
                #torznab multiple entries merged into extra_torznabs value
                self.config_update()
            setattr(self, 'CONFIG_VERSION', str(self.newconfig))
            config.set('General', 'CONFIG_VERSION', str(self.newconfig))
            print('Updating config to newest version : %s' % self.newconfig)
            self.writeconfig()
        else:
            self.provider_sequence()

        if startup is True:
            if self.LOG_DIR is None:
                self.LOG_DIR = os.path.join(mylar.DATA_DIR, 'logs')

            if not os.path.exists(self.LOG_DIR):
                try:
                    os.makedirs(self.LOG_DIR)
                except OSError:
                    if not mylar.QUIET:
                        self.LOG_DIR = None
                        print(
                            'Unable to create the log directory. Logging to screen only.'
                        )

            # Start the logger, silence console logging if we need to
            if logger.LOG_LANG.startswith('en'):
                logger.initLogger(console=not mylar.QUIET,
                                  log_dir=self.LOG_DIR,
                                  max_logsize=self.MAX_LOGSIZE,
                                  max_logfiles=self.MAX_LOGFILES,
                                  loglevel=mylar.LOG_LEVEL)
            else:
                if self.LOG_LEVEL != mylar.LOG_LEVEL:
                    print(
                        'Logging level over-ridden by startup value. Changing from %s to %s'
                        % (self.LOG_LEVEL, mylar.LOG_LEVEL))
                logger.mylar_log.initLogger(loglevel=mylar.LOG_LEVEL,
                                            log_dir=self.LOG_DIR,
                                            max_logsize=self.MAX_LOGSIZE,
                                            max_logfiles=self.MAX_LOGFILES)

        self.configure()
        return self
Exemplo n.º 2
0
    def read(self, startup=False):
        self.config_vals()
        setattr(self, 'EXTRA_NEWZNABS', self.get_extra_newznabs())
        setattr(self, 'EXTRA_TORZNABS', self.get_extra_torznabs())
        if any([self.CONFIG_VERSION == 0, self.CONFIG_VERSION < self.newconfig]):
            try:
                shutil.move(self._config_file, os.path.join(mylar.DATA_DIR, 'config.ini.backup'))
            except:
                print('Unable to make proper backup of config file in %s' % os.path.join(mylar.DATA_DIR, 'config.ini.backup'))
            if self.newconfig == 8:
                print('Attempting to update configuration..')
                #torznab multiple entries merged into extra_torznabs value
                self.config_update()
            setattr(self, 'CONFIG_VERSION', str(self.newconfig))
            config.set('General', 'CONFIG_VERSION', str(self.newconfig))
            print('Updating config to newest version : %s' % self.newconfig)
            self.writeconfig()
        else:
            self.provider_sequence()

        if startup is True:
            if self.LOG_DIR is None:
                self.LOG_DIR = os.path.join(mylar.DATA_DIR, 'logs')

            if not os.path.exists(self.LOG_DIR):
                try:
                    os.makedirs(self.LOG_DIR)
                except OSError:
                    if not mylar.QUIET:
                        self.LOG_DIR = None
                        print('Unable to create the log directory. Logging to screen only.')

            # Start the logger, silence console logging if we need to
            if logger.LOG_LANG.startswith('en'):
                logger.initLogger(console=not mylar.QUIET, log_dir=self.LOG_DIR, max_logsize=self.MAX_LOGSIZE, max_logfiles=self.MAX_LOGFILES, loglevel=mylar.LOG_LEVEL)
            else:
                if self.LOG_LEVEL != mylar.LOG_LEVEL:
                    print('Logging level over-ridden by startup value. Changing from %s to %s' % (self.LOG_LEVEL, mylar.LOG_LEVEL))
                logger.mylar_log.initLogger(loglevel=mylar.LOG_LEVEL, log_dir=self.LOG_DIR, max_logsize=self.MAX_LOGSIZE, max_logfiles=self.MAX_LOGFILES)

        self.configure()
        return self
Exemplo n.º 3
0
Arquivo: Mylar.py Projeto: 2mny/mylar
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

    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'

    # Set up and gather command line arguments
    parser = argparse.ArgumentParser(description='Automated Comic Book Downloader')

    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')
    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')
    parser.add_argument('-w', '--noweekly', action='store_true', help='Turn off weekly pull list check on startup (quicker boot sequence)')
    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)')
    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 = True
    if args.quiet:
        mylar.QUIET = True

    # Do an intial setup of the logger.
    logger.initLogger(console=not mylar.QUIET, log_dir=False, init=True, verbose=mylar.VERBOSE)

    #if args.update:
    #    print('Attempting to update Mylar so things can work again...')
    #    try:
    #        versioncheck.update()
    #    except Exception, e:
    #        sys.exit('Mylar failed to update.')

    if args.daemon:
        if sys.platform == 'win32':
            print "Daemonize not supported under Windows, starting normally"
        else:
            mylar.DAEMON = True

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

        # 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:
            mylar.CREATEPID = True
            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:
            logger.warn("Not running in daemon mode. PID file creation disabled.")
Exemplo n.º 4
0
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

    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'

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

    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')
    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'
    )
    parser.add_argument(
        '-w',
        '--noweekly',
        action='store_true',
        help=
        'Turn off weekly pull list check on startup (quicker boot sequence)')
    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)')
    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 = True
    if args.quiet:
        mylar.QUIET = True

    # Do an intial setup of the logger.
    logger.initLogger(console=not mylar.QUIET,
                      log_dir=False,
                      verbose=mylar.VERBOSE)

    #if args.update:
    #    print('Attempting to update Mylar so things can work again...')
    #    try:
    #        versioncheck.update()
    #    except Exception, e:
    #        sys.exit('Mylar failed to update.')

    if args.daemon:
        if sys.platform == 'win32':
            print "Daemonize not supported under Windows, starting normally"
        else:
            mylar.DAEMON = True

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

        # 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:
            mylar.CREATEPID = True
            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:
            logger.warn(
                "Not running in daemon mode. PID file creation disabled.")
Exemplo n.º 5
0
def initialize(config_file):
    with INIT_LOCK:

        global CONFIG, _INITIALIZED, QUIET, CONFIG_FILE, CURRENT_VERSION, LATEST_VERSION, COMMITS_BEHIND, INSTALL_TYPE, IMPORTLOCK, PULLBYFILE, INKDROPS_32P, \
               DONATEBUTTON, CURRENT_WEEKNUMBER, CURRENT_YEAR, UMASK, USER_AGENT, SNATCHED_QUEUE, NZB_QUEUE, PULLNEW, COMICSORT, WANTED_TAB_OFF, CV_HEADERS, \
               IMPORTBUTTON, IMPORT_FILES, IMPORT_TOTALFILES, IMPORT_CID_COUNT, IMPORT_PARSED_COUNT, IMPORT_FAILURE_COUNT, CHECKENABLED, CVURL, DEMURL, WWTURL, TPSEURL, \
               USE_SABNZBD, USE_NZBGET, USE_BLACKHOLE, USE_RTORRENT, USE_UTORRENT, USE_QBITTORRENT, USE_DELUGE, USE_TRANSMISSION, USE_WATCHDIR, SAB_PARAMS, \
               PROG_DIR, DATA_DIR, CMTAGGER_PATH, DOWNLOAD_APIKEY, LOCAL_IP, STATIC_COMICRN_VERSION, STATIC_APC_VERSION, KEYS_32P, AUTHKEY_32P, FEED_32P, FEEDINFO_32P, \
               MONITOR_STATUS, SEARCH_STATUS, RSS_STATUS, WEEKLY_STATUS, VERSION_STATUS, UPDATER_STATUS, DBUPDATE_INTERVAL, \
               SCHED_RSS_LAST, SCHED_WEEKLY_LAST, SCHED_MONITOR_LAST, SCHED_SEARCH_LAST, SCHED_VERSION_LAST, SCHED_DBUPDATE_LAST

        cc = mylar.config.Config(config_file)
        CONFIG = cc.read()

        assert CONFIG is not None

        if _INITIALIZED:
            return False

        #set up the default values here if they're wrong.
        #cc.configure()

        # Start the logger, silence console logging if we need to
        logger.initLogger(console=not QUIET, log_dir=CONFIG.LOG_DIR, verbose=VERBOSE) #logger.mylar_log.initLogger(verbose=VERBOSE)

        #try to get the local IP using socket. Get this on every startup so it's at least current for existing session.
        import socket
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.connect(('8.8.8.8', 80))
            LOCAL_IP = s.getsockname()[0]
            s.close()
            logger.info('Successfully discovered local IP and locking it in as : ' + str(LOCAL_IP))
        except:
            logger.warn('Unable to determine local IP - this might cause problems when downloading (maybe use host_return in the config.ini)')
            LOCAL_IP = CONFIG.HTTP_HOST


        # verbatim back the logger being used since it's now started.
        if LOGTYPE == 'clog':
            logprog = 'Concurrent Rotational Log Handler'
        else:
            logprog = 'Rotational Log Handler (default)'

        logger.fdebug('Logger set to use : ' + logprog)
        if LOGTYPE == 'log' and OS_DETECT == 'Windows':
            logger.fdebug('ConcurrentLogHandler package not installed. Using builtin log handler for Rotational logs (default)')
            logger.fdebug('[Windows Users] If you are experiencing log file locking and want this auto-enabled, you need to install Python Extensions for Windows ( http://sourceforge.net/projects/pywin32/ )')

        logger.info('Config GIT Branch: %s' % CONFIG.GIT_BRANCH)

        # Get the currently installed version - returns None, 'win32' or the git hash
        # Also sets INSTALL_TYPE variable to 'win', 'git' or 'source'
        CURRENT_VERSION, CONFIG.GIT_BRANCH = versioncheck.getVersion()
        #versioncheck.getVersion()
        #config_write()

        if CURRENT_VERSION is not None:
            hash = CURRENT_VERSION[:7]
        else:
            hash = "unknown"

        if CONFIG.GIT_BRANCH == 'master':
            vers = 'M'
        elif CONFIG.GIT_BRANCH == 'development':
           vers = 'D'
        else:
           vers = 'NONE'

        USER_AGENT = 'Mylar/' +str(hash) +'(' +vers +') +http://www.github.com/evilhero/mylar/'

        CV_HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'}

        # set the current week for the pull-list
        todaydate = datetime.datetime.today()
        CURRENT_WEEKNUMBER = todaydate.strftime("%U")
        CURRENT_YEAR = todaydate.strftime("%Y")

        # Initialize the database
        logger.info('Checking to see if the database has all tables....')
        try:
            dbcheck()
        except Exception, e:
            logger.error('Cannot connect to the database: %s' % e)

        # Check for new versions (autoupdate)
        if CONFIG.CHECK_GITHUB_ON_STARTUP:
            try:
                LATEST_VERSION = versioncheck.checkGithub()
            except:
                LATEST_VERSION = CURRENT_VERSION
        else:
            LATEST_VERSION = CURRENT_VERSION
#
        if CONFIG.AUTO_UPDATE:
            if CURRENT_VERSION != LATEST_VERSION and INSTALL_TYPE != 'win' and COMMITS_BEHIND > 0:
                logger.info('Auto-updating has been enabled. Attempting to auto-update.')
#                SIGNAL = 'update'

        #check for syno_fix here
        if CONFIG.SYNO_FIX:
            parsepath = os.path.join(DATA_DIR, 'bs4', 'builder', '_lxml.py')
            if os.path.isfile(parsepath):
                print ("found bs4...renaming appropriate file.")
                src = os.path.join(parsepath)
                dst = os.path.join(DATA_DIR, 'bs4', 'builder', 'lxml.py')
                try:
                    shutil.move(src, dst)
                except (OSError, IOError):
                    logger.error('Unable to rename file...shutdown Mylar and go to ' + src.encode('utf-8') + ' and rename the _lxml.py file to lxml.py')
                    logger.error('NOT doing this will result in errors when adding / refreshing a series')
            else:
                logger.info('Synology Parsing Fix already implemented. No changes required at this time.')

        #set the default URL for ComicVine API here.
        CVURL = 'https://comicvine.gamespot.com/api/'

        #set default URL for Public trackers (just in case it changes more frequently)
        WWTURL = 'https://worldwidetorrents.me/'
        DEMURL = 'https://www.demonoid.pw/'
        TPSEURL = 'https://torrentproject.se/'

        if CONFIG.LOCMOVE:
            helpers.updateComicLocation()


        #Ordering comics here
        logger.info('Remapping the sorting to allow for new additions.')
        COMICSORT = helpers.ComicSort(sequence='startup')

        # Store the original umask
        UMASK = os.umask(0)
        os.umask(UMASK)

        _INITIALIZED = True
        return True