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


Python ImportPlugin.set_source方法代码示例

本文整理汇总了Python中plugins.imp.ImportPlugin.set_source方法的典型用法代码示例。如果您正苦于以下问题:Python ImportPlugin.set_source方法的具体用法?Python ImportPlugin.set_source怎么用?Python ImportPlugin.set_source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plugins.imp.ImportPlugin的用法示例。


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

示例1: set_source

# 需要导入模块: from plugins.imp import ImportPlugin [as 别名]
# 或者: from plugins.imp.ImportPlugin import set_source [as 别名]
 def set_source(self, name):
     IP.set_source(self, name)
     self.filename = name
     self.fileversion = self.read_fileversion()
     if self.fileversion == None:
         gutils.error(_('The format of the file is not supported.'))
         return False
     return True
开发者ID:BackupTheBerlios,项目名称:griffith-svn,代码行数:10,代码来源:AllMyMovies.py

示例2: set_source

# 需要导入模块: from plugins.imp import ImportPlugin [as 别名]
# 或者: from plugins.imp.ImportPlugin import set_source [as 别名]
 def set_source(self, name):
     IP.set_source(self, name)
     self.filename = name
     self.fileversion = self.read_fileversion()
     if self.fileversion == None:
         gutils.error(_('The format of the file is not supported.'))
         return False
     if self.filename:
         self.imdbfilename = os.path.join(os.path.dirname(self.filename), 'IMDb.dat')
     else:
         self.imdbfilename = None
     return True
开发者ID:BackupTheBerlios,项目名称:griffith-svn,代码行数:14,代码来源:MovieTrack.py

示例3: set_source

# 需要导入模块: from plugins.imp import ImportPlugin [as 别名]
# 或者: from plugins.imp.ImportPlugin import set_source [as 别名]
    def set_source(self, name):
        # source _dependent_ initialization goes here
        if name is None or not os.path.isfile(name):
            return False
        IP.set_source(self, name)
        self.__source_name = name
        # auto-detect file-encoding (optional)
        try:
            from chardet.universaldetector import UniversalDetector

            detector = UniversalDetector()
            detector.reset()
            lines = 0
            for line in file(self.__source_name, "rb"):
                detector.feed(line)
                lines += 1
                if detector.done or lines == 50:
                    break
            detector.close()
            encoding = string.lower(detector.result["encoding"])
        except:
            log.exception("")
            encoding = "utf_8"
        encoding = self._encoding_cleanup.sub("", encoding)
        model = self.gtk.get_widget("e_encoding").get_model()
        itempos = 0
        for item in model:
            pos1 = string.find(self._encoding_cleanup.sub("", string.lower(str(item[0]))), encoding)
            if pos1 == 0:
                break
            itempos += 1
        self.gtk.get_widget("e_encoding").set_active(itempos)
        # auto-detect CSV import settings (optional)
        try:
            import csv

            sniffer = csv.Sniffer()
            csvfilesize = os.path.getsize(self.__source_name)
            if csvfilesize > 65535:
                csvfilesize = 65535
            csvfile = file(self.__source_name, "rb")
            try:
                # quote char, line terminator and field delimiter
                proposed_dialect = sniffer.sniff(csvfile.read(csvfilesize))
                self.gtk.get_widget("e_delimiter").set_text(proposed_dialect.delimiter)
                self.gtk.get_widget("e_quotechar").set_text(proposed_dialect.quotechar)
                if proposed_dialect.lineterminator == "\r\n":
                    self.gtk.get_widget("e_lineterminator").set_active(1)
                # first row with column headers
                csvfile.seek(0)
                if sniffer.has_header(csvfile.read(csvfilesize)):
                    self.gtk.get_widget("e_startrow").set_text("1")
                else:
                    self.gtk.get_widget("e_startrow").set_text("0")
            finally:
                csvfile.close()
        except:
            log.exception("")
        # run dialog
        response = self.gtk.get_widget("d_import").run()
        if response == gtk.RESPONSE_OK:
            return True
        else:
            return False
开发者ID:BackupTheBerlios,项目名称:griffith-svn,代码行数:66,代码来源:CSV.py


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