Exemple #1
0
def main():
    print()
    if args.image:
        print('1. Read image sheet')
        print('Path : ' + args.image)
    elif args.text:
        print('1. Read text sheet')
        print('Path : ' + args.text)
        sheet_parser = Parser(args.text)
    else:
        print('Needs input')
        exit(1)
    print()

    print('2. Parse sheet')
    try:
        sheet = sheet_parser.parse()
    except SheetParserError as err:
        expression, message = err.args
        print()
        print('!! Sheet Parser Error !!')
        print(expression)
        print(message)
        print()
        exit(1)
    else:
        print('parse success')
        print('Print sheet...')
        print(sheet)
    print()

    print('3. Load videos')
    print()

    print('4. Generate music video.')
    music = Maker(sheet, args.output)
    music.make()
    print()
class ObjectCollection(object):

    ###########################################################################
    def __init__(self, collection, clazz=None, type_bindings=None):
        self.collection = collection
        self.maker =  Maker(type_bindings=type_bindings,
            default_type=clazz,
            object_descriptor_resolver=self)
        self.database = collection.database
        self.name = collection.name

    ###########################################################################
    # Object descriptor Resolver implementations
    ###########################################################################


    ###########################################################################
    def is_datum_descriptor(self, value):
        return type(value) is DBRef

    ###########################################################################
    def resolve_datum_descriptor(self, desc):
        db_ref = desc
        ref_collection_name = db_ref.collection
        ref_collection = self.database[ref_collection_name]
        return ref_collection.find_one({"_id": db_ref.id})

    ###########################################################################
    # queries
    ###########################################################################
    @robustify(max_attempts=5, retry_interval=2,
               do_on_exception=_raise_if_not_autoreconnect,
               do_on_failure=_raise_on_failure)
    def find(self, query=None, sort=None, limit=None):
        if query is None or (query.__class__ == dict):
            result = self.find_iter( query, sort, limit )
            # TODO: this is bad for large result sets potentially
            return [ d for d in result ]
        else:
            return self.find_one({ "_id" : query }, sort=sort)

    ###########################################################################
    def find_iter(self, query=None, sort=None, limit=None):
        if query is None or (query.__class__ == dict):
            if limit is None:
                documents = self.collection.find(query, sort=sort)
            else:
                documents = self.collection.find(query, sort=sort, limit=limit)

            for doc in documents:
                yield self.make_obj( doc )
        else:
            # assume query is _id and do _id lookup
            yield self.find_one({ "_id" : query }, sort=sort)

    ###########################################################################
    @robustify(max_attempts=5, retry_interval=2,
               do_on_exception=_raise_if_not_autoreconnect,
               do_on_failure=_raise_on_failure)
    def find_one(self, query=None, sort=None):
        result = self.collection.find_one(query, sort=sort)
        return self.make_obj( result )

    ###########################################################################
    @robustify(max_attempts=5, retry_interval=2,
               do_on_exception=_raise_if_not_autoreconnect,
               do_on_failure=_raise_on_failure)
    def find_and_modify(self, query=None, update=None, sort=None, **kwargs):
        result = self.collection.find_and_modify(query=query, update=update,
                                                 sort=sort, **kwargs)
        return self.make_obj(result)

    ###########################################################################
    @robustify(max_attempts=5, retry_interval=2,
               do_on_exception=_raise_if_not_autoreconnect,
               do_on_failure=_raise_on_failure)
    def update(self, spec, document, upsert=False, manipulate=False,
                     safe=None, multi=False, check_keys=True, **kwargs):
        self.collection.update(spec=spec, document=document, upsert=upsert,
                               manipulate=manipulate, safe=safe, multi=multi,
                               check_keys=check_keys, **kwargs)

    ###########################################################################
    @robustify(max_attempts=5, retry_interval=2,
               do_on_exception=_raise_if_not_autoreconnect,
               do_on_failure=_raise_on_failure)
    def save_document(self, document):
        self.collection.save(document)

    ###########################################################################
    def make_obj( self, doc ):
        return self.maker.make(doc)

    ###########################################################################
    def insert(self, object):
        pass

    ###########################################################################
    def save(self, object):
        pass

    ###########################################################################
    def remove(self, object):
        pass

    ###########################################################################
    @robustify(max_attempts=5, retry_interval=2,
               do_on_exception=_raise_if_not_autoreconnect,
               do_on_failure=_raise_on_failure)
    def remove_by_id(self, id):
        self.collection.remove({"_id": id})
Exemple #3
0
class LatexBuilder:
    """
    Main (g)rubber wrapper hiding all the internals and compiling the
    required tex file.
    """
    def __init__(self):
        # The actual workers
        self.maker = Maker()
        self.tex = Latex(self.maker)
        self.maker.dep_append(self.tex)

        # What to do
        self.backend = "pdftex"
        self.format = "pdf"
        self.index_style = ""
        self.batch = 1
        self.encoding = "latin-1"
        self.texpost = ""

    def set_format(self, format):
        # Just record it
        self.format = format

    def set_backend(self, backend):
        self.backend = backend

    def set_index_style(self, index_style):
        self.index_style = index_style

    def compile(self, source):
        self.tex.batch = self.batch
        self.tex.encoding = self.encoding
        self.tex.set_source(source)

        # Load the modules needed to produce the expected output format
        if (self.format == "pdf"):
            if (self.backend == "pdftex"):
                self.tex.modules.register("pdftex")
            elif (self.backend == "xetex"):
                self.tex.modules.register("xetex")
            else:
                self.tex.modules.register("dvips")
                self.tex.modules.register("ps2pdf")
        elif (self.format == "ps"):
            self.tex.modules.register("dvips")

        # Now load other the modules required to compile this file
        self.tex.prepare()

        # Set the index style
        if self.index_style and self.tex.modules.has_key("makeidx"):
            idx = self.tex.modules["makeidx"]
            idx.style = self.index_style

        # Let's go...
        rc = self.maker.make()
        if rc != 0:
            raise OSError("%s compilation failed" % self.tex.program)

        # Post process script to call?
        if not(self.texpost):
            return

        os.environ["LATEX"] = self.tex.program
        rc = subprocess.call([self.texpost, source], stdout=msg.stdout)
        if rc == 1:
            return
        if rc != 0:
            raise OSError("%s texpost failed" % self.texpost)

        rc = self.maker.make(force=1)
        if rc != 0:
            raise OSError("%s post compilation failed" % self.tex.program)

    def clean(self):
        self.tex.clean()
        self.reinit()

    def reinit(self):
        self.tex.reinit()
        self.maker.reinit()
        self.maker.dep_append(self.tex)

    def print_errors(self):
        msg.display_all(self.tex.get_errors(), writer=msg.write_stderr)
Exemple #4
0
class LatexBuilder:
    """
    Main (g)rubber wrapper hiding all the internals and compiling the
    required tex file.
    """
    def __init__(self):
        # The actual workers
        self.maker = Maker()
        self.tex = Latex(self.maker)
        self.maker.dep_append(self.tex)

        # What to do
        self.backend = "pdftex"
        self.format = "pdf"
        self.index_style = ""
        self.batch = 1
        self.encoding = "latin-1"
        self.texpost = ""
        self.options = ""

    def set_format(self, format):
        # Just record it
        self.format = format

    def set_backend(self, backend):
        self.backend = backend

    def set_index_style(self, index_style):
        self.index_style = index_style

    def compile(self, source):
        self.tex.batch = self.batch
        self.tex.encoding = self.encoding
        self.tex.set_source(source)
        if self.options:
            self.tex.opts += shlex.split(self.options)

        # Load the modules needed to produce the expected output format
        if (self.format == "pdf"):
            if (self.backend == "pdftex"):
                self.tex.modules.register("pdftex")
            elif (self.backend == "xetex"):
                self.tex.modules.register("xetex")
            else:
                self.tex.modules.register("dvips")
                self.tex.modules.register("ps2pdf")
        elif (self.format == "ps"):
            self.tex.modules.register("dvips")

        # Now load other the modules required to compile this file
        self.tex.prepare()

        # Set the index style
        if self.index_style and self.tex.modules.has_key("makeidx"):
            idx = self.tex.modules["makeidx"]
            idx.style = self.index_style

        # Let's go...
        rc = self.maker.make()
        if rc != 0:
            raise OSError("%s compilation failed" % self.tex.program)

        # Post process script to call?
        if not (self.texpost):
            return

        os.environ["LATEX"] = self.tex.program
        rc = subprocess.call([self.texpost, source], stdout=msg.stdout)
        if rc == 1:
            return
        if rc != 0:
            raise OSError("%s texpost failed" % self.texpost)

        rc = self.maker.make(force=1)
        if rc != 0:
            raise OSError("%s post compilation failed" % self.tex.program)

    def clean(self):
        self.tex.clean()
        self.reinit()

    def reinit(self):
        self.tex.reinit()
        self.maker.reinit()
        self.maker.dep_append(self.tex)

    def print_errors(self):
        msg.display_all(self.tex.get_errors(), writer=msg.write_stderr)

    def print_misschars(self):
        # Show the characters not handled by fonts
        self.tex.print_misschars()
class HTML5kKaraokeMaker(object):

    "CLI interface of HTML5kKaraokeMaker"

    def readCli(self):
        '''CLI:Argument parser'''

        parser = argparse.ArgumentParser()
        parser.add_argument(
            '-p',
            '--webpath',
            help=_("use a local web path file"),
            default=D_WEB_DIR
        )
        parser.add_argument(
            '-d',
            '--datapath',
            help=_("use a local data path file"),
            default=D_DATA_DIR
        )
        parser.add_argument(
            '-o',
            '--output',
            help=_("choose a specific output directory"),
            default=D_WEB_DIR
        )
        self.args = parser.parse_args()
        return True

    def __init__(self, logLevel=LOGLEVEL):
        ''' Launch CLI'''

        self.logger = logging.getLogger("HTML5kKaraokeMaker")
        self.logger.setLevel(logLevel)

        if self.readCli():
            self.maker = Maker(self.args.webpath,self.args.datapath)
            self.maker.make()
            self.saveFile()
        else:
            print(_("Interface error"))

    def __str__(self):
        '''Print text'''

        if self.maker:
            return str(self.maker)
        else:
            return _("No file")

    def saveFile(self):

        #copy needed data
        audioPath=self.args.output+'/audio'
        dependPath=self.args.output+'/depend'
        if os.path.exists(audioPath):
            shutil.rmtree(audioPath)
        if os.path.exists(dependPath):
            shutil.rmtree(dependPath)
        shutil.copytree('data/audio','web/audio')
        shutil.copytree('data/depend','web/depend')

        with open(self.args.output+"/index.html", "w+") as doc:
            doc.write(self.__str__())