def test_logging_OptParse_002_01(self): """Test if 'OptParse' works with MythLog.""" # set default values acc. source code m_dblog = False m_loglevel = LOGLEVEL.INFO m_verbose = LOGMASK.GENERAL m_logfile = stdout with add_log_flags(): m = MythLog('simple_test') #print ("m._LEVEL = %d" %m._LEVEL) #print ("m._MASK = %d" %m._MASK) #print ("m._DBLOG = %s" %m._DBLOG) #print (sys.argv) parser = OptionParser(prog="simple_test") # silence warnings in unittest about missing '-v' option: parser.add_option('-v', action='store_true', dest='uv', default=False, help='Use to set verbosity in unittest') # load MYthTV's extension m.loadOptParse(parser) opts, args = parser.parse_args() # check the options provided by 'additional_args': m_dblog = opts.nodblog # the option is named '--nodblog', stored in 'nodblog' m_loglevel = m._LEVEL m_verbose = m._MASK m_logfile = m._LOGFILE self.assertEqual(m_dblog, True) self.assertEqual(m_loglevel, LOGLEVEL.DEBUG) self.assertEqual( m_verbose, LOGMASK.ALL) ### XXX RER '-v' from unittest collides with this self.assertTrue(os.path.exists("/tmp/my_logfile"))
def main(): parser = OptionParser(usage="usage: %prog [options] [jobid]") formatgroup = OptionGroup(parser, "Formatting Options", "These options are used to display and manipulate the output file formats.") formatgroup.add_option("-f", "--helpformat", action="store_true", default=False, dest="fmthelp", help="Print explination of file format string.") formatgroup.add_option("-p", "--printformat", action="store_true", default=False, dest="fmtprint", help="Print current file format string.") formatgroup.add_option("--tformat", action="store", type="string", dest="tformat", help="Use TV format for current task. If no task, store in database.") formatgroup.add_option("--mformat", action="store", type="string", dest="mformat", help="Use Movie format for current task. If no task, store in database.") formatgroup.add_option("--gformat", action="store", type="string", dest="gformat", help="Use Generic format for current task. If no task, store in database.") formatgroup.add_option("--listingonly", action="store_true", default=False, dest="listingonly", help="Use data from listing provider, rather than grabber") parser.add_option_group(formatgroup) sourcegroup = OptionGroup(parser, "Source Definition", "These options can be used to manually specify a recording to operate on "+\ "in place of the job id.") sourcegroup.add_option("--chanid", action="store", type="int", dest="chanid", help="Use chanid for manual operation") sourcegroup.add_option("--starttime", action="store", type="int", dest="starttime", help="Use starttime for manual operation") parser.add_option_group(sourcegroup) actiongroup = OptionGroup(parser, "Additional Actions", "These options perform additional actions after the recording has been exported.") actiongroup.add_option('--safe', action='store_true', default=False, dest='safe', help='Perform quick sanity check of exported file using file size.') actiongroup.add_option('--really-safe', action='store_true', default=False, dest='reallysafe', help='Perform slow sanity check of exported file using SHA1 hash.') actiongroup.add_option("--delete", action="store_true", default=False, help="Delete source recording after successful export. Enforces use of --safe.") parser.add_option_group(actiongroup) othergroup = OptionGroup(parser, "Other Data", "These options copy additional information from the source recording.") othergroup.add_option("--seekdata", action="store_true", default=False, dest="seekdata", help="Copy seekdata from source recording.") othergroup.add_option("--skiplist", action="store_true", default=False, dest="skiplist", help="Copy commercial detection from source recording.") othergroup.add_option("--cutlist", action="store_true", default=False, dest="cutlist", help="Copy manual commercial cuts from source recording.") parser.add_option_group(othergroup) MythLog.loadOptParse(parser) opts, args = parser.parse_args() if opts.verbose: if opts.verbose == 'help': print MythLog.helptext sys.exit(0) MythLog._setlevel(opts.verbose) if opts.fmthelp: usage_format() sys.exit(0) if opts.fmtprint: print_format() sys.exit(0) if opts.delete: opts.safe = True if opts.chanid and opts.starttime: export = VIDEO(opts) elif len(args) == 1: try: export = VIDEO(opts,int(args[0])) except Exception, e: Job(int(args[0])).update({'status':Job.ERRORED, 'comment':'ERROR: '+e.args[0]}) MythLog(module='mythvidexport.py').logTB(MythLog.GENERAL) sys.exit(1)
def main(): parser = OptionParser(usage="usage: %prog [options] [jobid]") formatgroup = OptionGroup( parser, "Formatting Options", "These options are used to display and manipulate the output file formats." ) formatgroup.add_option("-f", "--helpformat", action="store_true", default=False, dest="fmthelp", help="Print explination of file format string.") formatgroup.add_option("-p", "--printformat", action="store_true", default=False, dest="fmtprint", help="Print current file format string.") formatgroup.add_option( "--tformat", action="store", type="string", dest="tformat", help="Use TV format for current task. If no task, store in database.") formatgroup.add_option( "--mformat", action="store", type="string", dest="mformat", help="Use Movie format for current task. If no task, store in database." ) formatgroup.add_option( "--gformat", action="store", type="string", dest="gformat", help= "Use Generic format for current task. If no task, store in database.") formatgroup.add_option( "--listingonly", action="store_true", default=False, dest="listingonly", help="Use data from listing provider, rather than grabber") parser.add_option_group(formatgroup) sourcegroup = OptionGroup(parser, "Source Definition", "These options can be used to manually specify a recording to operate on "+\ "in place of the job id.") sourcegroup.add_option("--chanid", action="store", type="int", dest="chanid", help="Use chanid for manual operation") sourcegroup.add_option("--starttime", action="store", type="string", dest="starttime", help="Use starttime for manual operation") parser.add_option_group(sourcegroup) actiongroup = OptionGroup( parser, "Additional Actions", "These options perform additional actions after the recording has been exported." ) actiongroup.add_option( '--safe', action='store_true', default=False, dest='safe', help='Perform quick sanity check of exported file using file size.') actiongroup.add_option( '--really-safe', action='store_true', default=False, dest='reallysafe', help='Perform slow sanity check of exported file using SHA1 hash.') actiongroup.add_option( "--delete", action="store_true", default=False, help= "Delete source recording after successful export. Enforces use of --safe." ) parser.add_option_group(actiongroup) othergroup = OptionGroup( parser, "Other Data", "These options copy additional information from the source recording.") othergroup.add_option("--seekdata", action="store_true", default=False, dest="seekdata", help="Copy seekdata from source recording.") othergroup.add_option( "--skiplist", action="store_true", default=False, dest="skiplist", help="Copy commercial detection from source recording.") othergroup.add_option( "--cutlist", action="store_true", default=False, dest="cutlist", help="Copy manual commercial cuts from source recording.") parser.add_option_group(othergroup) MythLog.loadOptParse(parser) opts, args = parser.parse_args() if opts.verbose: if opts.verbose == 'help': print MythLog.helptext sys.exit(0) MythLog._setlevel(opts.verbose) if opts.fmthelp: usage_format() sys.exit(0) if opts.fmtprint: print_format() sys.exit(0) if opts.delete: opts.safe = True if opts.chanid and opts.starttime: export = VIDEO(opts) elif len(args) == 1: try: export = VIDEO(opts, int(args[0])) except Exception, e: Job(int(args[0])).update({ 'status': Job.ERRORED, 'comment': 'ERROR: ' + e.args[0] }) MythLog(module='mythvidexport.py').logTB(MythLog.GENERAL) sys.exit(1)
def main(): parser = OptionParser(usage="usage: %prog [options] [jobid]") sourcegroup = OptionGroup(parser, "Source Definition", "These options can be used to manually specify a recording to operate on "+\ "in place of the job id.") sourcegroup.add_option( "--chanid", action="store", type="int", dest="chanid", help="Use chanid for manual operation, format interger") sourcegroup.add_option( "--startdate", action="store", type="string", dest="startdate", help="Use startdate for manual operation, format is year-mm-dd") sourcegroup.add_option( "--starttime", action="store", type="string", dest="starttime", help="Use starttime for manual operation, format is hh:mm:ss in UTC") sourcegroup.add_option( "--offset", action="store", type="string", dest="offset", help= "Use offset(timezone) for manual operation, format is [+/-]hh:mm. Do not adjust for DST" ) parser.add_option_group(sourcegroup) actiongroup = OptionGroup(parser, "Additional Actions", "These options perform additional actions after the recording has been migrated. "+\ "A safe copy is always performed in that the file is checked to match the "+\ "MythBE hash. The safe copy option will abort the entire process if selected "+\ "along with Other Data and an exception occurs in the process") actiongroup.add_option( '--safe', action='store_true', default=False, dest='safe', help= 'If other data is copied and a failure occurs this will abort the whole process.' ) actiongroup.add_option( "--delete", action="store_true", default=False, help= "Delete source recording after successful export. Enforces use of --safe." ) parser.add_option_group(actiongroup) othergroup = OptionGroup( parser, "Other Data", "These options copy additional information from the source recording.") othergroup.add_option("--seekdata", action="store_true", default=False, dest="seekdata", help="Copy seekdata from source recording.") othergroup.add_option( "--skiplist", action="store_true", default=False, dest="skiplist", help="Copy commercial detection from source recording.") othergroup.add_option( "--cutlist", action="store_true", default=False, dest="cutlist", help="Copy manual commercial cuts from source recording.") parser.add_option_group(othergroup) MythLog.loadOptParse(parser) opts, args = parser.parse_args() def error_out(): export.delete_vid() if export.thisJob: export.set_job_status(Job.ERRORED) sys.exit(1) if opts.verbose: if opts.verbose == 'help': print MythLog.helptext sys.exit(0) MythLog._setlevel(opts.verbose) if opts.delete: opts.safe = True # if a manual channel and time entry then setup the export with opts if opts.chanid and opts.startdate and opts.starttime and opts.offset: try: export = VIDEO(opts) except Exception, e: sys.exit(1)
def main(): parser = OptionParser(usage="usage: %prog [options] [jobid]") sourcegroup = OptionGroup(parser, "Source Definition", "These options can be used to manually specify a recording to operate on "+\ "in place of the job id.") sourcegroup.add_option("--chanid", action="store", type="int", dest="chanid", help="Use chanid for manual operation, format interger") sourcegroup.add_option("--startdate", action="store", type="string", dest="startdate", help="Use startdate for manual operation, format is year-mm-dd") sourcegroup.add_option("--starttime", action="store", type="string", dest="starttime", help="Use starttime for manual operation, format is hh:mm:ss in UTC") sourcegroup.add_option("--offset", action="store", type="string", dest="offset", help="Use offset(timezone) for manual operation, format is [+/-]hh:mm. Do not adjust for DST") parser.add_option_group(sourcegroup) actiongroup = OptionGroup(parser, "Additional Actions", "These options perform additional actions after the recording has been migrated. "+\ "A safe copy is always performed in that the file is checked to match the "+\ "MythBE hash. The safe copy option will abort the entire process if selected "+\ "along with Other Data and an exception occurs in the process") actiongroup.add_option('--safe', action='store_true', default=False, dest='safe', help='If other data is copied and a failure occurs this will abort the whole process.') actiongroup.add_option("--delete", action="store_true", default=False, help="Delete source recording after successful export. Enforces use of --safe.") parser.add_option_group(actiongroup) othergroup = OptionGroup(parser, "Other Data", "These options copy additional information from the source recording.") othergroup.add_option("--seekdata", action="store_true", default=False, dest="seekdata", help="Copy seekdata from source recording.") othergroup.add_option("--skiplist", action="store_true", default=False, dest="skiplist", help="Copy commercial detection from source recording.") othergroup.add_option("--cutlist", action="store_true", default=False, dest="cutlist", help="Copy manual commercial cuts from source recording.") parser.add_option_group(othergroup) MythLog.loadOptParse(parser) opts, args = parser.parse_args() def error_out(): export.delete_vid() if export.thisJob: export.set_job_status(Job.ERRORED) sys.exit(1) if opts.verbose: if opts.verbose == 'help': print MythLog.helptext sys.exit(0) MythLog._setlevel(opts.verbose) if opts.delete: opts.safe = True # if a manual channel and time entry then setup the export with opts if opts.chanid and opts.startdate and opts.starttime and opts.offset: try: export = VIDEO(opts) except Exception, e: sys.exit(1)