Example #1
0
    def test_Logging_Basic_002_01(self):
        """Test if options can be modified from MythTV.MythLog."""

        m = MythLog('simple_test')

        m._setmask("most")
        # check the modified mask:
        self.assertEqual(m._MASK, LOGMASK.MOST)
        # check the default level:
        self.assertEqual(m._LEVEL, LOGLEVEL.INFO)
        # check the default file:
        self.assertTrue('stdout' in repr(m._LOGFILE))

        m._setlevel("notice")
        # check the modified mask:
        self.assertEqual(m._MASK, LOGMASK.MOST)
        # check the modified level:
        self.assertEqual(m._LEVEL, LOGLEVEL.NOTICE)
        # check the default file:
        self.assertTrue('stdout' in repr(m._LOGFILE))

        m._setfile("/tmp/my_logfile")
        # check the modified mask:
        self.assertEqual(m._MASK, LOGMASK.MOST)
        # check the modified level:
        self.assertEqual(m._LEVEL, LOGLEVEL.NOTICE)
        # check the modified file:
        self.assertTrue(os.path.exists("/tmp/my_logfile"))
    def __init__(self, host=None):
        self.db = MythDB()
        self.db.searchRecorded.handler = Recorded
        self.be = MythBE(db=self.db)
        self.log = MythLog(db=self.db)

        self.set_host(host)
        self.load_backends()
        self.load_storagegroups()
Example #3
0
    def __init__(self, opts, jobid=None):
        if jobid:
            self.job = Job(jobid)
            self.chanid = self.job.chanid
            self.starttime = self.job.starttime
            self.job.update(status=Job.STARTING)
        else:
            self.job = None
            self.chanid = opts.chanid
            self.starttime = opts.starttime

        self.opts = opts
        self.db = MythDB()
        self.log = MythLog(module='mythvidexport.py', db=self.db)

        # load setting strings
        self.get_format()

        # prep objects
        self.rec = Recorded((self.chanid, self.starttime), db=self.db)
        self.log(
            MythLog.GENERAL, MythLog.INFO, 'Using recording',
            '%s - %s' % (self.rec.title.encode('utf-8'),
                         self.rec.subtitle.encode('utf-8')))
        self.vid = Video(db=self.db).create({
            'title': '',
            'filename': '',
            'host': gethostname()
        })

        # process data
        self.get_meta()
        self.get_dest()
        # bug fix to work around limitation in the bindings where DBDataRef classes
        # are mapped to the filename at time of Video element creation. since the
        # filename is specified as blank when the video is created, the markup
        # handler is not properly initialized
        self.vid.markup._refdat = (self.vid.filename, )

        # save file
        self.copy()
        if opts.seekdata:
            self.copy_seek()
        if opts.skiplist:
            self.copy_markup(static.MARKUP.MARK_COMM_START,
                             static.MARKUP.MARK_COMM_END)
        if opts.cutlist:
            self.copy_markup(static.MARKUP.MARK_CUT_START,
                             static.MARKUP.MARK_CUT_END)
        self.vid.update()

        # delete old file
        if opts.delete:
            self.rec.delete()
Example #4
0
    def test_Logging_Basic_001_01(self):
        """Test if default options works with MythLog."""

        m = MythLog('simple_test')

        # check the default mask:
        self.assertEqual(m._MASK, LOGMASK.GENERAL)
        # check the default level:
        self.assertEqual(m._LEVEL, LOGLEVEL.INFO)
        # check the default file:
        self.assertTrue('stdout' in repr(m._LOGFILE))

        # test '__repr__' and '__str__'
        print()
        print(repr(m))
        print(str(m))
Example #5
0
    def __init__(self, opts, jobid=None):
        if jobid:
            self.job = Job(jobid)
            self.chanid = self.job.chanid
            self.starttime = self.job.starttime
            self.job.update(status=3)
        else:
            self.job = None
            self.chanid = opts.chanid
            self.starttime = opts.starttime

        self.opts = opts
        self.db = MythDB()
        self.log = MythLog(module='mythvidexport.py', db=self.db)

        # load setting strings
        self.get_format()

        # prep objects
        self.rec = Recorded((self.chanid, self.starttime), db=self.db)
        self.log(MythLog.IMPORTANT, 'Using recording',
                 '%s - %s' % (self.rec.title, self.rec.subtitle))
        self.vid = Video(db=self.db).create({
            'title': '',
            'filename': '',
            'host': gethostname()
        })

        # process data
        self.get_meta()
        self.get_dest()

        # save file
        self.copy()
        if opts.seekdata:
            self.copy_seek()
        if opts.skiplist:
            self.copy_markup(static.MARKUP.MARK_COMM_START,
                             static.MARKUP.MARK_COMM_END)
        if opts.cutlist:
            self.copy_markup(static.MARKUP.MARK_CUT_START,
                             static.MARKUP.MARK_CUT_END)
        self.vid.update()
    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 test_Logging_argparse_001_01(self):
        """Test if 'argparse' works with MythLog."""

        m = MythLog('simple_test')

        parser = argparse.ArgumentParser(prog="simple_test")

        # Add arbitrary option:
        parser.add_argument('--chanid',
                            action='store',
                            dest='chanid',
                            default=0,
                            help='Use chanid for manual operation')

        # load MYthTV's extension
        m.loadArgParse(parser)

        # unittest : first arguements are the test class or the verbosity flag
        test_args = []
        args_found = False
        for a in argv:
            if not args_found:
                args_found = a.startswith('test')
            else:
                test_args.append(a)

        args = parser.parse_args(test_args)

        # check the default mask:
        self.assertEqual(m._MASK, LOGMASK.GENERAL)

        # check if helptext contains 'siparser'
        h = m.helptext
        found = False
        for line in h.split("\n"):
            match = re.findall(r'siparser', line)
            if match:
                found = True
        self.assertEqual(found, True)
    def test_Logging_argparse_002_01(self):
        """Test if 'argparse' works with MythLog."""

        # set default values acc. source code
        m_dblog = True
        m_loglevel = LOGLEVEL.INFO
        m_verbose = LOGMASK.GENERAL
        m_logfile = stdout

        with add_log_flags():
            m = MythLog('simple_test')
            parser = argparse.ArgumentParser(prog="simple_test")

            # load MYthTV's extension
            m.loadArgParse(parser)

            # unittest : first arguements are the test class or the verbosity flag
            # filter out arguements for unittesting:
            test_args = add_log_flags.additional_args

            # according 'add_log_flags', test_args should be:
            #  ['--nodblog', '--loglevel', 'debug', '--verbose', 'all', '--logfile', '/tmp/my_logfile']

            args = parser.parse_args(test_args)
            #print(test_args)
            #print(args)

            # check the options provided by 'additional_args':
            m_dblog = m._DBLOG
            m_loglevel = m._LEVEL
            m_verbose = m._MASK
            m_logfile = m._LOGFILE

        self.assertEqual(m_dblog, False)
        self.assertEqual(m_loglevel, LOGLEVEL.DEBUG)
        self.assertEqual(m_verbose, LOGMASK.ALL)
        self.assertTrue(os.path.exists("/tmp/my_logfile"))
Example #9
0
    def __init__(self, opts, jobid=None):

        # Setup for the job to run
        if jobid:
            self.thisJob = Job(jobid)
            self.chanID = self.thisJob.chanid
            self.startTime = self.thisJob.starttime
            self.thisJob.update(status=Job.STARTING)

        # If no job ID given, must be a command line run
        else:
            self.thisJob = jobid
            self.chanID = opts.chanid
            self.startTime = opts.startdate + " " + opts.starttime + opts.offset
        self.opts = opts
        self.type = "none"
        self.db = MythDB()
        self.log = MythLog(module='Myth-Rec-to-Vid.py', db=self.db)

        # Capture the backend host name
        self.host = self.db.gethostname()

        # prep objects
        self.rec = Recorded((self.chanID, self.startTime), db=self.db)
        self.log(
            MythLog.GENERAL, MythLog.INFO, 'Using recording',
            '%s - %s' % (self.rec.title.encode('utf-8'),
                         self.rec.subtitle.encode('utf-8')))

        self.vid = Video(db=self.db).create({
            'title': '',
            'filename': '',
            'host': self.host
        })

        self.bend = MythBE(db=self.db)
Example #10
0
def LOG(msg):
    logger = MythLog(module='mythadder.py')
    logger(MythLog.GENERAL, MythLog.INFO, msg)
Example #11
0
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)
Example #12
0
def main():
    parser = OptionParser(usage="usage: %prog [options] [jobid]")

    parser.add_option("-f",
                      "--helpformat",
                      action="store_true",
                      default=False,
                      dest="fmthelp",
                      help="Print explination of file format string.")
    parser.add_option("-p",
                      "--printformat",
                      action="store_true",
                      default=False,
                      dest="fmtprint",
                      help="Print current file format string.")
    parser.add_option(
        "--tformat",
        action="store",
        type="string",
        dest="tformat",
        help="Use TV format for current task. If no task, store in database.")
    parser.add_option(
        "--mformat",
        action="store",
        type="string",
        dest="mformat",
        help="Use Movie format for current task. If no task, store in database."
    )
    parser.add_option(
        "--gformat",
        action="store",
        type="string",
        dest="gformat",
        help=
        "Use Generic format for current task. If no task, store in database.")
    parser.add_option("--chanid",
                      action="store",
                      type="int",
                      dest="chanid",
                      help="Use chanid for manual operation")
    parser.add_option("--starttime",
                      action="store",
                      type="int",
                      dest="starttime",
                      help="Use starttime for manual operation")
    parser.add_option(
        "--listingonly",
        action="store_true",
        default=False,
        dest="listingonly",
        help="Use data from listing provider, rather than grabber")
    parser.add_option("--seekdata",
                      action="store_true",
                      default=False,
                      dest="seekdata",
                      help="Copy seekdata from source recording.")
    parser.add_option("--skiplist",
                      action="store_true",
                      default=False,
                      dest="skiplist",
                      help="Copy commercial detection from source recording.")
    parser.add_option(
        "--cutlist",
        action="store_true",
        default=False,
        dest="cutlist",
        help="Copy manual commercial cuts from source recording.")
    parser.add_option('-v',
                      '--verbose',
                      action='store',
                      type='string',
                      dest='verbose',
                      help='Verbosity level')

    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.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': 304,
                'comment': 'ERROR: ' + e.args[0]
            })
            MythLog(module='mythvidexport.py').logTB(MythLog.IMPORTANT)
            sys.exit(1)
Example #13
0
            export = VIDEO(opts)

        except Exception, e:
            sys.exit(1)

    # If an auto or manual job entry then setup the export with the jobID
    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='Myth-Rec-to-Vid.py').logTB(MythLog.GENERAL)
            sys.exit(1)

    # else bomb the job and return an error code
    else:
        parser.print_help()
        sys.exit(2)

    # Export object created so process the job
    try:
        export.get_type()
        export.get_meta()
        export.get_dest()

    except Exception, e:
        export.log(MythLog.GENERAL | MythLog.FILE, MythLog.INFO,
Example #14
0
#!/usr/bin/env python

import os
import sys
try:
    from MythTV import MythVideo, VideoGrabber, MythLog
except:
    print 'ERROR: The python bindings are not installed'
    sys.exit(-1)

LOG = MythLog('MythVideo Scanner', lstr='general')
mvid = MythVideo()


def format_name(vid):
    # returns a string in the format 'TITLE[ - SEASONxEPISODE][ - SUBTITLE]'
    s = vid.title
    if vid.season:
        s += ' - %dx%02d' % (vid.season, vid.episode)
    if vid.subtitle:
        s += ' - ' + vid.subtitle
    return s.encode('utf-8', 'replace')


# Load TV Grabber
try:
    TVgrab = VideoGrabber('TV', db=mvid)
except:
    print 'ERROR: Cannot find MythVideo TV grabber'
    sys.exit(-1)
Example #15
0
from fuse import Fuse

try:
    import MythTV
except:
    print 'Warning! MythTV Python bindings could not be found'
    sys.exit(1)
if MythTV.__version__ < (0, 24, 0, 0):
    print 'Warning! Installed MythTV Python bindings are tool old. Please update'
    print '    to 0.23.0.18 or later.'
    sys.exit(1)
from MythTV import MythDB, MythVideo, ftopen, MythBE,\
                   Video, Recorded, MythLog, static

fuse.fuse_python_api = (0, 2)
LOG = MythLog(lstr='none')
MythLog._setfile('/dev/null')
BACKEND = None


def doNothing(*args, **kwargs):
    pass


def increment():
    res = 1
    while True:
        yield res
        res += 1