当前位置: 首页>>代码示例>>Python>>正文


Python script.ScriptParser类代码示例

本文整理汇总了Python中picard.script.ScriptParser的典型用法代码示例。如果您正苦于以下问题:Python ScriptParser类的具体用法?Python ScriptParser怎么用?Python ScriptParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ScriptParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _example_to_filename

 def _example_to_filename(self, file):
     settings = {
         'windows_compatibility': self.ui.windows_compatibility.isChecked(),
         'ascii_filenames': self.ui.ascii_filenames.isChecked(),
         'rename_files': self.ui.rename_files.isChecked(),
         'move_files': self.ui.move_files.isChecked(),
         'use_va_format': False,  # TODO remove
         'file_naming_format': unicode(self.ui.file_naming_format.toPlainText()),
         'move_files_to': os.path.normpath(unicode(self.ui.move_files_to.text()))
     }
     try:
         if config.setting["enable_tagger_script"]:
             script = config.setting["tagger_script"]
             parser = ScriptParser()
             parser.eval(script, file.metadata)
         filename = file._make_filename(file.filename, file.metadata, settings)
         if not settings["move_files"]:
             return os.path.basename(filename)
         return filename
     except SyntaxError:
         return ""
     except ScriptError:
         return ""
     except TypeError:
         return ""
     except UnknownFunction:
         return ""
开发者ID:KLuken,项目名称:picard,代码行数:27,代码来源:renaming.py

示例2: _example_to_filename

 def _example_to_filename(self, file):
     settings = {
         'windows_compatibility': self.ui.windows_compatibility.isChecked(),
         'ascii_filenames': self.ui.ascii_filenames.isChecked(),
         'rename_files': self.ui.rename_files.isChecked(),
         'move_files': self.ui.move_files.isChecked(),
         'use_va_format': False,  # TODO remove
         'file_naming_format': self.ui.file_naming_format.toPlainText(),
         'move_files_to': os.path.normpath(self.ui.move_files_to.text())
     }
     try:
         if config.setting["enable_tagger_scripts"]:
             for s_pos, s_name, s_enabled, s_text in config.setting["list_of_scripts"]:
                 if s_enabled and s_text:
                     parser = ScriptParser()
                     parser.eval(s_text, file.metadata)
         filename = file._make_filename(file.filename, file.metadata, settings)
         if not settings["move_files"]:
             return os.path.basename(filename)
         return filename
     except SyntaxError:
         return ""
     except ScriptError:
         return ""
     except TypeError:
         return ""
开发者ID:JDLH,项目名称:picard,代码行数:26,代码来源:renaming.py

示例3: _script_to_filename

 def _script_to_filename(self, format, file_metadata, settings=None):
     if settings is None:
         settings = config.setting
     metadata = Metadata()
     if config.setting["clear_existing_tags"]:
         metadata.copy(file_metadata)
     else:
         metadata.copy(self.orig_metadata)
         metadata.update(file_metadata)
     # make sure every metadata can safely be used in a path name
     for name in metadata.keys():
         if isinstance(metadata[name], basestring):
             metadata[name] = sanitize_filename(metadata[name])
     format = format.replace("\t", "").replace("\n", "")
     filename = ScriptParser().eval(format, metadata, self)
     if settings["ascii_filenames"]:
         if isinstance(filename, unicode):
             filename = unaccent(filename)
         filename = replace_non_ascii(filename)
     # replace incompatible characters
     if settings["windows_compatibility"] or sys.platform == "win32":
         filename = replace_win32_incompat(filename)
     # remove null characters
     filename = filename.replace("\x00", "")
     return filename
开发者ID:Freso,项目名称:picard,代码行数:25,代码来源:file.py

示例4: _finalize_loading

    def _finalize_loading(self, error):
        if error:
            self.metadata.clear()
            self.metadata['album'] = _("[could not load album %s]") % self.id
            del self._new_metadata
            del self._new_tracks
            self.update()
            return

        # Run metadata plugins
        while self._metadata_plugins:
            try:
                self._metadata_plugins.popleft()()
            except:
                self.log.error(traceback.format_exc())

        if not self._requests:
            # Prepare parser for user's script
            script = None
            if self.config.setting["enable_tagger_script"]:
                script = self.config.setting["tagger_script"]
                parser = ScriptParser()

            for track in self._new_tracks:
                # Update the track with new album metadata, in case it
                # was modified by plugins.
                for key, values in self._new_metadata.rawitems():
                    track.metadata[key] = values[:]
                # Run tagger script for each track
                if script:
                    try:
                        parser.eval(script, track.metadata)
                    except:
                        self.log.error(traceback.format_exc())
                    # Strip leading/trailing whitespace
                    track.metadata.strip_whitespace()

            # Run tagger script for the album itself
            if script:
                try:
                    parser.eval(script, self._new_metadata)
                except:
                    self.log.error(traceback.format_exc())
                self._new_metadata.strip_whitespace()

            for track in self.tracks:
                for file in list(track.linked_files):
                    file.move(self.unmatched_files)
            self.metadata = self._new_metadata
            self.tracks = self._new_tracks
            del self._new_metadata
            del self._new_tracks
            self.loaded = True
            self.match_files(self.unmatched_files.files)
            self.update()
            self.tagger.window.set_statusbar_message('Album %s loaded', self.id, timeout=3000)
            while self._after_load_callbacks.qsize() > 0:
                func = self._after_load_callbacks.get()
                func()
开发者ID:lalinsky,项目名称:picard-debian,代码行数:59,代码来源:album.py

示例5: check_format

 def check_format(self):
     parser = ScriptParser()
     try:
         parser.eval(unicode(self.ui.file_naming_format.toPlainText()))
     except Exception as e:
         raise OptionsCheckError("", str(e))
     if self.ui.rename_files.isChecked():
         if not unicode(self.ui.file_naming_format.toPlainText()).strip():
             raise OptionsCheckError("", _("The file naming format must not be empty."))
开发者ID:KLuken,项目名称:picard,代码行数:9,代码来源:renaming.py

示例6: process

    def process(self, script):
        files = self.files

        for file in files:
            m = file.metadata
            parser = ScriptParser()
            try:
                parser.eval(script, m)
            except:
                log.error(traceback.format_exc())
            m.strip_whitespace()
开发者ID:rupa108,项目名称:picard_plugins,代码行数:11,代码来源:__init__.py

示例7: _make_image_filename

 def _make_image_filename(self, filename, dirname, metadata):
     filename = ScriptParser().eval(filename, metadata)
     if config.setting["ascii_filenames"]:
         if isinstance(filename, unicode):
             filename = unaccent(filename)
         filename = replace_non_ascii(filename)
     if not filename:
         filename = "cover"
     if not os.path.isabs(filename):
         filename = os.path.join(dirname, filename)
     # replace incompatible characters
     if config.setting["windows_compatibility"] or sys.platform == "win32":
         filename = replace_win32_incompat(filename)
     # remove null characters
     filename = filename.replace("\x00", "")
     return encode_filename(filename)
开发者ID:hackur,项目名称:picard,代码行数:16,代码来源:image.py

示例8: script_to_filename

def script_to_filename(naming_format, metadata, file=None, settings=None):
    if settings is None:
        settings = config.setting
    # make sure every metadata can safely be used in a path name
    for name in metadata:
        values = [sanitize_filename(str(v)) for v in metadata.getall(name)]
        metadata.set(name, values)
    naming_format = naming_format.replace("\t", "").replace("\n", "")
    filename = ScriptParser().eval(naming_format, metadata, file)
    if settings["ascii_filenames"]:
        filename = replace_non_ascii(filename, pathsave=True)
    # replace incompatible characters
    if settings["windows_compatibility"] or sys.platform == "win32":
        filename = replace_win32_incompat(filename)
    # remove null characters
    filename = filename.replace("\x00", "")
    return filename
开发者ID:mineo,项目名称:picard,代码行数:17,代码来源:scripttofilename.py

示例9: _run_script

    def _run_script(self, script):
        s_name = script[1]
        s_text = script[3]
        parser = ScriptParser()

        for obj in self._get_unique_metadata_objects():
            try:
                parser.eval(s_text, obj.metadata)
                obj.update()
            except ScriptError as e:
                log.exception('Error running tagger script "%s" on object %r', s_name, obj)
                msg = N_('Script error in "%(script)s": %(message)s')
                mparms = {
                    'script': s_name,
                    'message': str(e),
                }
                self.tagger.window.set_statusbar_message(msg, mparms)
开发者ID:Jormangeud,项目名称:picard,代码行数:17,代码来源:scriptsmenu.py

示例10: setUp

 def setUp(self):
     config.setting = {
         'enabled_plugins': '',
     }
     self.parser = ScriptParser()
     def func_noargstest(parser):
         return ""
     register_script_function(func_noargstest, "noargstest")
开发者ID:Freso,项目名称:picard,代码行数:8,代码来源:test_script.py

示例11: _parse_recording

 def _parse_recording(self, recording):
     recording_to_metadata(recording, self, self.config)
     self._customize_metadata()
     m = self.metadata
     run_track_metadata_processors(self.album, m, None, recording)
     if self.config.setting["enable_tagger_script"]:
         script = self.config.setting["tagger_script"]
         if script:
             parser = ScriptParser()
             try:
                 parser.eval(script, m)
             except:
                 self.log.error(traceback.format_exc())
             m.strip_whitespace()
     self.loaded = True
     if self.callback:
         self.callback()
     self.tagger.nats.update(True)
开发者ID:betoth2001,项目名称:picard,代码行数:18,代码来源:track.py

示例12: _parse_recording

    def _parse_recording(self, recording):
        m = self.metadata
        recording_to_metadata(recording, m, self)
        self.orig_metadata.copy(m)
        self._customize_metadata()
        run_track_metadata_processors(self.album, m, None, recording)
        for s_name, s_text in enabled_tagger_scripts_texts():
            parser = ScriptParser()
            try:
                parser.eval(s_text, m)
            except ScriptError:
                log.exception("Failed to run tagger script %s on track", s_name)
            m.strip_whitespace()

        self.loaded = True
        self.status = None
        if self.callback:
            self.callback()
            self.callback = None
        self.album.update(True)
开发者ID:Jormangeud,项目名称:picard,代码行数:20,代码来源:track.py

示例13: _parse_recording

    def _parse_recording(self, recording):
        m = self.metadata
        recording_to_metadata(recording, m, self)
        self._customize_metadata()
        run_track_metadata_processors(self.album, m, None, recording)
        if config.setting["enable_tagger_scripts"]:
            for s_pos, s_name, s_enabled, s_text in config.setting["list_of_scripts"]:
                if s_enabled and s_text:
                    parser = ScriptParser()
                    try:
                        parser.eval(s_text, m)
                    except:
                        log.error(traceback.format_exc())
                    m.strip_whitespace()

        self.loaded = True
        if self.callback:
            self.callback()
            self.callback = None
        self.tagger.nats.update(True)
开发者ID:Sophist-UK,项目名称:Sophist_picard,代码行数:20,代码来源:track.py

示例14: _example_to_filename

 def _example_to_filename(self, file):
     settings = {
         'windows_compatible_filenames': self.ui.windows_compatible_filenames.isChecked(),
         'ascii_filenames': self.ui.ascii_filenames.isChecked(),
         'rename_files': self.ui.rename_files.isChecked(),
         'move_files': self.config.setting["move_files"],
         'use_va_format': self.ui.use_va_format.isChecked(),
         'file_naming_format': unicode(self.ui.file_naming_format.toPlainText()),
         'va_file_naming_format': unicode(self.ui.va_file_naming_format.toPlainText()),
         'move_files_to': os.path.normpath(unicode(self.config.setting["move_files_to"])),
     }
     try:
         if self.config.setting["enable_tagger_script"]:
             script = self.config.setting["tagger_script"]
             parser = ScriptParser()
             parser.eval(script, file.metadata)
         filename = file._make_filename(file.filename, file.metadata, settings)
         return filename
     except SyntaxError, e: return ""
     except TypeError, e: return ""
     except UnknownFunction, e: return ""
开发者ID:lalinsky,项目名称:picard-debian,代码行数:21,代码来源:renaming.py

示例15: eval

 def eval(self, script, context=None, file=None):
     result = ScriptParser.eval(self, script, context, file)
     return result.split(STOP_MARKER)[0]
开发者ID:mineo,项目名称:mbstuff,代码行数:3,代码来源:stop.py


注:本文中的picard.script.ScriptParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。