Ticket #7560: jamu-exit-codes.patch

File jamu-exit-codes.patch, 15.6 KB (added by james@…, 14 years ago)

Patch for jamu.py to use integer exit codes, not booleans

  • mythplugins/mythvideo/mythvideo/scripts/jamu.py

     
    397397        import xml
    398398except Exception:
    399399        print '''The python module xml must be installed.'''
    400         sys.exit(False)
     400        sys.exit(1)
    401401if xml.__version__ < u'41660':
    402402        print '''
    403403\n! Warning - The module xml (v41660 or greater) must be installed. Your version is different (v%s) than what Jamu was tested with. Jamu may not work on your installation.\nIt is recommended that you upgrade.\n''' % xml.__version__
     
    408408except Exception:
    409409        print '''
    410410The module MySQLdb (v1.2.2 or greater) must be installed.'''
    411         sys.exit(False)
     411        sys.exit(1)
    412412if MySQLdb.__version__ < u'1.2.2':
    413413        print '''
    414414\n! Warning - The module MySQLdb (v1.2.2 or greater) must be installed. Your version is different (v%s) than what Jamu was tested with. Jamu may not work on your installation.\nIt is recommended that you upgrade.\n''' % MySQLdb.__version__
     
    462462The modules tvdb_api.py (v1.0.0 or greater), tvdb_ui.py, tvdb_exceptions.py and cache.py must be
    463463in the same directory as ttvdb.py. They should have been included with the distribution of ttvdb.py.
    464464'''
    465         sys.exit(False)
     465        sys.exit(1)
    466466
    467467imdb_lib = True
    468468try:                    # Check if the installation is equiped to directly search IMDB for movies
     
    471471        sys.stderr.write("\n! Error: To search for movies movies the IMDbPy library must be installed."\
    472472                "Check your installation's repository or check the following link."\
    473473                "from (http://imdbpy.sourceforge.net/?page=download)\n")
    474         sys.exit(False)
     474        sys.exit(1)
    475475
    476476if imdb_lib:
    477477        if imdb.__version__ < "3.8":
    478478                sys.stderr.write("\n! Error: You version the IMDbPy library (%s) is too old. You must use version 3.8 of higher." % imdb.__version__)
    479479                sys.stderr.write("Check your installation's repository or check the following link."\
    480480                        "from (http://imdbpy.sourceforge.net/?page=download)\n")
    481                 sys.exit(False)
     481                sys.exit(1)
    482482
    483483
    484484def isValidPosixFilename(name, NAME_MAX=255):
     
    642642                                        sys.stderr.write(u"\n! Error: The local Storage group (%s) directory (%s) does not exist or there is a permissions restriction\n" % (key, directory))
    643643                                        storagegroup_ok = False
    644644                if not storagegroup_ok:
    645                         sys.exit(False)
     645                        sys.exit(1)
    646646# end getStorageGroups
    647647
    648648# Start of code used to access themoviedb.com api
     
    13611361                        sys.stderr.write(
    13621362                                "\n! Error: The specified user configuration file (%s) is not a file\n" % useroptions
    13631363                        )
    1364                         sys.exit(False)
     1364                        sys.exit(1)
    13651365                cfg = ConfigParser.SafeConfigParser()
    13661366                cfg.read(useroptions)
    13671367                for section in cfg.sections():
     
    14001400                                        tmp =cfg.get(section, option).split(',')
    14011401                                        if len(tmp)%2 and len(cfg.get(section, option)) != 0:
    14021402                                                sys.stderr.write(u"\n! Error: For (%s) 'ep_name_massage' values must be in pairs\n" % option)
    1403                                                 sys.exit(False)
     1403                                                sys.exit(1)
    14041404                                        tmp_array=[]
    14051405                                        i=0
    14061406                                        while i != len(tmp):
     
    14721472################### Used to create the example configuration file "jamu-example-conf"
    14731473#               for key in keys:        # Used to create the example configuration file "jamu-example-conf"
    14741474#                       print "#%s: %s" % (key, self.config[key])
    1475 #               sys.exit(True)
     1475#               sys.exit(0)
    14761476##################
    14771477
    14781478                for key in keys:
     
    15131513                        localip = gethostbyname(localhostname) # Get the local hosts IP address
    15141514                except:
    15151515                        sys.stderr.write("\n! Error: There is no valid address-to-host mapping for the host (%s)\nThe Jamu Janitor (-MJ) option cannot be used while this issue remains un-resolved.\n" % localhostname)
    1516                         sys.exit(False)
     1516                        sys.exit(1)
    15171517
    15181518                # Get all curently mounted NFS shares
    15191519                tmp_mounts = callCommandLine("mount -l | grep '//'").split('\n')
     
    15661566                # Make sure Jamu is being run on a MythTV backend
    15671567                if not mythdb.getSetting('BackendServerIP', hostname = localhostname):
    15681568                        sys.stderr.write(u"\n! Error: Jamu must be run on a MythTV backend. Local host (%s) is not a MythTV backend.\n" % localhostname)
    1569                         sys.exit(False)
     1569                        sys.exit(1)
    15701570
    15711571                global dir_dict
    15721572                for key in dir_dict.keys():
     
    16251625                                self.config[key] = storagegroups[u'mythvideo']
    16261626                        if not len(self.config[key]):
    16271627                                sys.stderr.write(u"\n! Error: There must be a directory for Videos and each graphic type. The (%s) directory is missing.\n" % (key))
    1628                                 sys.exit(False)
     1628                                sys.exit(1)
    16291629
    16301630                # Make sure that the directory sets for Videos and other graphics directories are RW able
    16311631                accessable = True
     
    16361636                                        accessable = False
    16371637
    16381638                if not accessable:
    1639                         sys.exit(False)
     1639                        sys.exit(1)
    16401640
    16411641                # Check if any Video files are on a NFS shares
    16421642                if not self.config['mythtvNFS']:        # Maybe the NFS check is to be skipped
    16431643                        if self._checkNFS(self.config['mythvideo'], self.config['video_file_exts']):
    16441644                                sys.stderr.write(u"\n! Error: Your video files reside on a NFS mount.\nIn the case where you have more than one MythTV backend using the same directories to store either video files\nor graphics any Jamu's option (-M) can adversly effect your MythTV database by mistakenly adding videos\nfor other backends or with the Janitor (-J) option mistakenly remove graphics files.\n\nIf you only have one backend or do not mix the Video or graphic file directories between backends and still want to use\nJamu add the options (N) to your option string e.g. (-MJN), which will skip this check.\n\n")
    1645                                 sys.exit(False)
     1645                                sys.exit(1)
    16461646        # end _getMythtvDirectories
    16471647
    16481648
     
    17361736                if self.config['mythtvmeta']:
    17371737                        if mythdb == None or mythvideo == None:
    17381738                                sys.stderr.write(u"\n! Error: The MythTV python interface is not installed or Cannot connect to MythTV Backend. MythTV meta data cannot be updated\n\n")
    1739                                 sys.exit(False)
     1739                                sys.exit(1)
    17401740                        try:
    17411741                                import Image
    17421742                                self.config['image_library'] = Image
     
    17461746
    17471747In Debian/Ubuntu it is packaged as 'python-imaging'.
    17481748http://www.pythonware.com/products/pil/\n""")
    1749                                 sys.exit(False)
     1749                                sys.exit(1)
    17501750
    17511751                if not _can_int(self.config['min_poster_size']):
    17521752                        sys.stderr.write(u"\n! Error: The poster minimum value must be an integer (%s)\n" % self.config['min_poster_size'])
    1753                         sys.exit(False)
     1753                        sys.exit(1)
    17541754                else:
    17551755                        self.config['min_poster_size'] = int(self.config['min_poster_size'])
    17561756
    17571757                if self.config['maximum'] != None:
    17581758                        if _can_int(self.config['maximum']) == False:
    17591759                                sys.stderr.write(u"\n! Error: Maximum option is not an integer (%s)\n" % self.config['maximum'])
    1760                                 sys.exit(False)
     1760                                sys.exit(1)
    17611761
    17621762                if self.config['mythtvdir']:
    17631763                        if mythdb == None or mythvideo == None:
    17641764                                sys.stderr.write(u"\n! Error: MythTV python interface is not available\n")
    1765                                 sys.exit(False)
     1765                                sys.exit(1)
    17661766                if self.config['mythtvdir'] or self.config['mythtvmeta']:
    17671767                        self._addMythtvUserFileTypes() # add user filetypes from the "videotypes" table
    17681768                        self._getMythtvDirectories()
    17691769                if self.config['mythtvjanitor']: # Check for graphic directory conflicts with other plugins
    17701770                        if self._JanitorConflicts():
    1771                                 sys.exit(False)
     1771                                sys.exit(1)
    17721772                        if not self.config['mythtvNFS']:
    17731773                                global graphicsDirectories, image_extensions
    17741774                                dirs = []
     
    17791779                                # Check if any Graphics files are on NFS shares
    17801780                                if self._checkNFS(dirs, image_extensions):
    17811781                                        sys.stderr.write(u"\n! Error: Your metadata graphics reside on a NFS mount.\nIn the case where you have more than one MythTV backend using the same directories to store your graphics\nthe Jamu's Janitor option (-MJ) will be destructive removing graphics used by the other backend(s).\n\nIf you only have one backend or do not mix the graphics directories between backends and still want to use\nJamu's Janitor use the options (-MJN) which will skip this check.\n\n")
    1782                                         sys.exit(False)
     1782                                        sys.exit(1)
    17831783
    17841784                if self.config['posterresize'] != False or self.config['fanartresize'] != False:
    17851785                        if _useImageMagick("-version"):
    17861786                                sys.stderr.write(u"\n! Error: ImageMagick is not installed, graphics cannot be resized. posterresize(%s), fanartresize(%s)\n" % (str(self.config['posterresize']), str(self.config['fanartresize'])))
    1787                                 sys.exit(False)
     1787                                sys.exit(1)
    17881788
    17891789                if self.config['mythtvmeta'] and len(args) == 0:
    17901790                        args=['']
    17911791
    17921792                if len(args) == 0:
    17931793                        sys.stderr.write(u"\n! Error: At least a video directory, SID or season name must be supplied\n")
    1794                         sys.exit(False)
     1794                        sys.exit(1)
    17951795
    17961796                if os.path.isfile(args[0]) or os.path.isdir(args[0]) or args[0][-1:] == '*':
    17971797                        self.config['video_dir'] = []
     
    18121812                                if len(args) > 3:
    18131813                                        sys.stderr.write("\n! Error: Too many arguments (%d), maximum is three.\n" % len(args))
    18141814                                        print "! args:", args
    1815                                         sys.exit(False)
     1815                                        sys.exit(1)
    18161816                                if len(args) == 3 and _can_int(args[1]) and _can_int(args[2]):
    18171817                                        self.config['season_num'] = args[1]
    18181818                                        self.config['episode_num'] = args[2]
    18191819                                elif len(args) == 3:
    18201820                                        sys.stderr.write(u"\n! Error: Season name(%s), season number(%s), episode number (%s) combination is invalid\n" % (args[0], args[1], args[2]))
    1821                                         sys.exit(False)
     1821                                        sys.exit(1)
    18221822                                elif len(args) == 2 and _can_int(args[1]):
    18231823                                        self.config['season_num'] = args[1]
    18241824                                else:
     
    18461846                                for lang in valid_languages: valid_langs+= lang+', '
    18471847                                valid_langs=valid_langs[:-2]
    18481848                                sys.stderr.write(u"\n! Error: Specified language(%s) must match one of the following languages supported by thetvdb.com wiki:\n (%s)\n" % (self.config['local_language'], valid_langs))
    1849                                 sys.exit(False)
     1849                                sys.exit(1)
    18501850                global UI_search_language
    18511851                UI_search_language = self.config['local_language']
    18521852
     
    26722672                        sys.stderr.write(
    26732673                                u'\n! Error: There must be at least "season and episode numbers" or "episode name" to request a filename\n'
    26742674                        )
    2675                         sys.exit(False)
     2675                        sys.exit(1)
    26762676
    26772677                # Special logic must be used if the (-MG) guessing option has been requested
    26782678                if not self.config['sid'] and self.config['mythtv_guess']:
     
    26942694                        sys.stderr.write(
    26952695                                u'\n! Error: The episode was not found for series(%s), Episode name(%s)\n' % (series_name, episode_name)
    26962696                        )
    2697                         sys.exit(False)
     2697                        sys.exit(1)
    26982698
    26992699                sid=self.config['sid']
    27002700
     
    29912991
    29922992                if len(validFiles) == 0:
    29932993                        sys.stderr.write(u"\n! Error: No valid video files found\n")
    2994                         sys.exit(False)
     2994                        sys.exit(1)
    29952995
    29962996                path_flag = self.config['metadatadir']
    29972997                for cfile in validFiles:
     
    34453445                        tmp_files=tmp_array[0].replace(u'file://', u'')
    34463446                        if not os.path.isfile(tmp_files):
    34473447                                sys.stderr.write(u'\n! Error: The graphic file does not exist (%s)\n' % tmp_files)
    3448                                 sys.exit(False)
     3448                                sys.exit(1)
    34493449
    34503450                        # Fix file extentions in all caps or 4 character JPEG extentions
    34513451                        fileExtension = (_getExtention(tmp_files)).lower()
     
    41114111                                        # Destinations must all be directories
    41124112                                        if not os.path.isdir(file_dir):
    41134113                                                sys.stderr.write(u"\n! Error: Destinations must all be directories.\nThis destination is not a directory (%s)\n" % (file_dir,))
    4114                                                 sys.exit(False)
     4114                                                sys.exit(1)
    41154115                                        else:
    41164116                                                tmp_dir = file_dir
    41174117                                                for directory in self.config['mythvideo']:
     
    41204120                                                                break
    41214121                                                else:
    41224122                                                        sys.stderr.write(u"\n! Error: Destinations must all be a mythvideo directory or subdirectory.\nThis destination (%s) is not one of the Mythvideo directories(%s)\n" % (file_dir, self.config['mythvideo'], ))
    4123                                                         sys.exit(False)
     4123                                                        sys.exit(1)
    41244124                                # Verify that a target file is really a video file.
    41254125                                if file_dir[-1:] != '*': # Skip wildcard file name targets
    41264126                                        if os.access(file_dir, os.F_OK | os.R_OK | os.W_OK):    # Confirm that the file actually exists
     
    41314131                                                                        break
    41324132                                                        else:
    41334133                                                                sys.stderr.write(u"\n! Error: Target files must be video files(%s).\nSupported video file extentions(%s)\n" % (file_dir, self.config['video_file_exts'],))
    4134                                                                 sys.exit(False)
     4134                                                                sys.exit(1)
    41354135                                        count+=1
    41364136
    41374137                # Stats counters
     
    43264326
    43274327                if not len(directories):
    43284328                        sys.stderr.write(u"\n! Error: There must be a video directory specified in MythTv\n")
    4329                         sys.exit(False)
     4329                        sys.exit(1)
    43304330
    43314331                allFiles = self._findFiles(directories, self.config['recursive'] , verbose = self.config['debug_enabled'])
    43324332                validFiles = self._processNames(allFiles, verbose = self.config['debug_enabled'], movies=True)
     
    46814681                except MySQLdb.Error, e:
    46824682                        logger.error(u"SELECT intid FROM videometadata WHERE inetref = 99999999 and category = %d failed: %d: %s" % (category_id, e.args[0], e.args[1]))
    46834683                        c.close()
    4684                         sys.exit(False)
     4684                        sys.exit(1)
    46854685                intids=[]
    46864686                while True:
    46874687                        row = c.fetchone()
     
    53815381                                validFiles = self._moveVideoFiles(self.config['video_dir'])
    53825382                        else:
    53835383                                sys.stderr.write(u"\n! Error: When specifying target (file or directory) to move to a destination (directory) they must always be in pairs (target and destination directory).\nYou specified an uneven number of variables (%d) for target and destination pairs.\nVariable count (%s)\n" % (len(self.config['video_dir']), self.config['video_dir']))
    5384                                 sys.exit(False)
     5384                                sys.exit(1)
    53855385
    53865386                # Check if only missing inetref video's should be processed
    53875387                if self.config['mythtv_inetref']:
    53885388                        validFiles = self._findMissingInetref()
    53895389                        if validFiles == None:
    53905390                                sys.stderr.write(u"\n! Warning: There were no missing interef video files found.\n\n")
    5391                                 sys.exit(True)
     5391                                sys.exit(0)
    53925392                        elif not len(validFiles):
    53935393                                sys.stderr.write(u"\n! Warning: There were no missing interef video files found.\n\n")
    5394                                 sys.exit(True)
     5394                                sys.exit(0)
    53955395
    53965396                # Verify that the proper fields are present
    53975397                db_version = mythdb.getSetting('DBSchemaVer')
     
    53995399                for field in ['season', 'episode', 'coverfile', 'screenshot', 'banner', 'fanart']:
    54005400                        if not field in field_names:
    54015401                                sys.stderr.write(u"\n! Error: Your MythTv data base scheme version (%s) does not have the necessary fields at least (%s) is missing\n\n" % (db_version, field))
    5402                                 sys.exit(False)
     5402                                sys.exit(1)
    54035403
    54045404                # Check if this is a Scheduled and Recorded graphics download request
    54055405                if self.config['mythtv_watched']:
    54065406                        self._downloadScheduledRecordedGraphics()
    5407                         sys.exit(True)
     5407                        sys.exit(0)
    54085408
    54095409                # Check if this is just a Janitor (clean up unused graphics files) request
    54105410                if self.config['mythtvjanitor']:
    54115411                        self._graphicsCleanup()
    5412                         sys.exit(True)
     5412                        sys.exit(0)
    54135413
    54145414                directories=self.config['mythvideo']
    54155415
    54165416                if not len(directories):
    54175417                        sys.stderr.write(u"\n! Error: There must be a video directory specified in MythTv\n")
    5418                         sys.exit(False)
     5418                        sys.exit(1)
    54195419
    54205420                # Set statistics
    54215421                num_processed=0
     
    54405440
    54415441                if len(validFiles) == 0:
    54425442                        sys.stderr.write(u"\n! Error: No valid video files found\n")
    5443                         sys.exit(False)
     5443                        sys.exit(1)
    54445444
    54455445                tv_series_season_format=u"%s/%s Season %d.%s"
    54465446                tv_series_format=u"%s/%s.%s"
     
    62726272
    62736273        if opts.usage:                                  # Display usage information
    62746274                sys.stdout.write(usage_txt+'\n')
    6275                 sys.exit(True)
     6275                sys.exit(0)
    62766276
    62776277        if opts.examples:                                       # Display example information
    62786278                sys.stdout.write(examples_txt+'\n')
    6279                 sys.exit(True)
     6279                sys.exit(0)
    62806280
    62816281        if opts.version == True:                # Display program information
    62826282                sys.stdout.write(u"\nTitle: (%s); Version: (%s); Author: (%s)\n%s\n" % (
    62836283                __title__, __version__, __author__, __purpose__ ))
    6284                 sys.exit(True)
     6284                sys.exit(0)
    62856285
    62866286        # Apply any command line switches
    62876287        configuration.changeVariable('local_language', opts.language)
     
    63196319                else:
    63206320                        configuration.validate_setVariables(['FAKE SERIES NAME','FAKE EPISODE NAME'])
    63216321                configuration.displayOptions()
    6322                 sys.exit(True)
     6322                sys.exit(0)
    63236323
    63246324        # Validate specific variables
    63256325        configuration.validate_setVariables(series_season_ep)