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


Python Configuration.get_filename方法代码示例

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


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

示例1: config

# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_filename [as 别名]
def config() :
    configuration = Configuration()
    for key in configuration :
        if configuration.need_configure(key) :
            doc = configuration.get_doc(key)
            strvalue = configuration.get_strvalue(key)
            print "%s ?[%s]" % (doc,strvalue)
            line = sys.stdin.readline().replace('\r','').replace('\n','')
            if line != '' :
                configuration.set_strvalue(key,line)
    configuration.save()
    print "The file %s has been updated. Press RETURN to continue." % (configuration.get_filename(),)
    sys.stdin.readline()
开发者ID:BackupTheBerlios,项目名称:pydirstat-svn,代码行数:15,代码来源:__init__.py

示例2: FileDumper

# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_filename [as 别名]
class FileDumper( object ) :
    """This is the mother class of all dumpers. A dumper is a plugin that receive informations about a file and how to draw it. It usually dump a file, but you can do whatever you want with it."""
    EXT=".dump"
    NEEDHANDLE=True
    def __init__(self, rootpath=None, outputfile=None) :
        self._configuration = Configuration()

        if self._configuration.get_value('path') != '' :
            rootpath = self._configuration.get_value('path')

        # Gruik Gruik : C:" -> C:\ Thanks Windows !
        if rootpath and (len(rootpath)==3) and (rootpath[2]) == '"' :
            rootpath = rootpath[0:2] + '\\'

        if rootpath == None :
            rootpath = '.'

        if os.path.supports_unicode_filenames :
            rootpath = unicode(rootpath)
        else :
            rootpath = str(rootpath)

        tree = FileTree(rootpath)
        tree.scan()

        self._rootpath = rootpath
        self._tree = tree
        filename = outputfile

        if filename == None :
            filename = self._configuration.get_value('outputfile')

        if filename == '' :
            if os.path.isdir(rootpath) :
                filename = os.path.join(rootpath,self._configuration.get_value('basename')+self.EXT)
            else :
                name = os.path.split(rootpath)[1]
                filename = name + '.' + self._configuration.get_value('basename') + self.EXT
        self._filename = filename
        self._size = None

    def dump(self,gsize=None) :
        """This method really start the dump. You should not override it. Override _start_dump, _end_dump or add_rect instead."""
        if gsize != None :
            self._size = gsize
        if self._size == None :
            self._size = Size(self._configuration.get_value('width'),self._configuration.get_value('height'))
        self._treemapview = TreemapView( self._tree, self._size )
        size = self._treemapview.visibleSize()

        if self.NEEDHANDLE :
            self._file = file(self._filename,'wt')

        self._start_dump()
        self._treemapview.draw(self)
        self._end_dump()

        if self.NEEDHANDLE :
            self._file.close()

    def get_metadata(self) :
        '''This method may be called by plugin to print metadata'''
        return [
            ('Generator', 'pydirstat'),
            ('Version', __version__),
            ('Directory', os.path.abspath(self._rootpath)),
            ('Total Size',fmtsize(self._treemapview.rootTile().fileinfo().totalSize())),
            ('Date', time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())),
            ('Configuration File',self._configuration.get_filename()),
            ('Python version',sys.version),
            ]

    def get_colors(self) :
        '''This method may be called by plugin to print legend'''
        method_by_type = {}
        types = []
        colors = {}
        for section_name in self._configuration.get_sections() :
            if section_name.startswith('type:') :
                section_content = self._configuration.get_section(section_name)
                for key in section_content :
                    value = section_content[key]
                    if value not in method_by_type :
                        method_by_type[value] = {}
                    if section_name not in method_by_type[value] :
                        method_by_type[value][section_name] = []
                    method_by_type[value][section_name].append(key)
                    if value not in types :
                        types.append(value)
            elif section_name == 'color' :
                colors_conf = self._configuration.get_section('color')
                for color in colors_conf :
                    colors[color] = Color(colors_conf[color])

        types.sort()
        if 'file' not in types :
            types.append('file')
        if 'dir' not in types :
            types.append('dir')
        if '_' not in types :
#.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:pydirstat-svn,代码行数:103,代码来源:Dumper.py

示例3: FileDumper

# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_filename [as 别名]
class FileDumper(object):
    EXT = ".dump"
    NEEDHANDLE = True

    def __init__(self, rootpath=None, outputfile=None, size=None, tree=None, configuration=None):
        self._configuration = configuration
        if self._configuration == None:
            self._configuration = Configuration()

        if rootpath == None and self._configuration.get_value("path") != "":
            rootpath = self._configuration.get_value("path")

        # Gruik Gruik : C:" -> C:\ Thanks Windows !
        if rootpath and (len(rootpath) == 3) and (rootpath[2]) == '"':
            rootpath = rootpath[0:2] + "\\"
        if (rootpath == None) and (tree == None):
            rootpath = "."
        if rootpath != None:
            if os.path.supports_unicode_filenames:
                rootpath = unicode(rootpath)
            else:
                rootpath = str(rootpath)
            tree = FileTree(rootpath)
            tree.scan()

        self._rootpath = rootpath
        self._tree = tree
        filename = outputfile
        if filename == None:
            filename = self._configuration.get_value("outputfile")
        if filename == "":
            if os.path.isdir(rootpath):
                filename = os.path.join(rootpath, self._configuration.get_value("basename") + self.EXT)
            else:
                name = os.path.split(rootpath)[1]
                filename = name + "." + self._configuration.get_value("basename") + self.EXT
        self._filename = filename
        self._size = size

    def dump(self, gsize=None):
        if gsize != None:
            self._size = gsize
        if self._size == None:
            self._size = Size(self._configuration.get_value("width"), self._configuration.get_value("height"))
        self._tmv = TreemapView(self._tree, self._size, self._configuration)
        size = self._tmv.visibleSize()

        if self.NEEDHANDLE:
            self._file = file(self._filename, "wt")

        self._start_dump()
        self._tmv.draw(self)
        self._end_dump()

        if self.NEEDHANDLE:
            self._file.close()

    def get_metadata(self):
        """This method may be called by plugin to print metadata"""
        return [
            ("Generator", "pydirstat"),
            ("Version", __version__),
            ("Directory", os.path.abspath(self._rootpath)),
            ("Date", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())),
            ("Configuration File", self._configuration.get_filename()),
            ("Total Size", fmtsize(self._tmv.rootTile().orig().totalSize())),
            ("Python version", sys.version),
        ]

    def get_colors(self):
        method_by_type = {}
        types = []
        colors = {}
        for section_name in self._configuration.get_sections():
            if section_name.startswith("type:"):
                section_content = self._configuration.get_section(section_name)
                for key in section_content:
                    value = section_content[key]
                    if value not in method_by_type:
                        method_by_type[value] = {}
                    if section_name not in method_by_type[value]:
                        method_by_type[value][section_name] = []
                    method_by_type[value][section_name].append(key)
                    if value not in types:
                        types.append(value)
            elif section_name == "color":
                colors_conf = self._configuration.get_section("color")
                for color in colors_conf:
                    colors[color] = Color(colors_conf[color])

        types.sort()
        if "file" not in types:
            types.append("file")
        if "dir" not in types:
            types.append("dir")
        if "_" not in types:
            types.append("_")

        for typename in types:
            if typename not in colors:
#.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:pydirstat-svn,代码行数:103,代码来源:Dumper.py


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